1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wallpaper.customization.ui.view
18 
19 import android.widget.SeekBar
20 import android.widget.TextView
21 import androidx.core.view.isInvisible
22 import com.android.systemui.plugins.clocks.ClockFontAxis
23 
24 class ClockFontSliderViewHolder(val name: TextView, val slider: SeekBar) {
25 
setIsVisiblenull26     fun setIsVisible(isVisible: Boolean) {
27         name.isInvisible = !isVisible
28         slider.isInvisible = !isVisible
29     }
30 
initViewnull31     fun initView(clockFontAxis: ClockFontAxis, onFontAxisValueUpdated: (value: Float) -> Unit) {
32         name.text = clockFontAxis.name
33         slider.apply {
34             max = clockFontAxis.maxValue.toInt()
35             min = clockFontAxis.minValue.toInt()
36             progress = clockFontAxis.currentValue.toInt()
37             setOnSeekBarChangeListener(
38                 object : SeekBar.OnSeekBarChangeListener {
39                     override fun onProgressChanged(
40                         seekBar: SeekBar?,
41                         progress: Int,
42                         fromUser: Boolean,
43                     ) {
44                         if (fromUser) {
45                             onFontAxisValueUpdated.invoke(progress.toFloat())
46                         }
47                     }
48 
49                     override fun onStartTrackingTouch(seekBar: SeekBar?) {}
50 
51                     override fun onStopTrackingTouch(seekBar: SeekBar?) {}
52                 }
53             )
54         }
55     }
56 
setValuenull57     fun setValue(value: Float) {
58         slider.progress = value.toInt()
59     }
60 }
61