1 /* <lambda>null2 * 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.Switch 20 import android.widget.TextView 21 import androidx.core.view.isVisible 22 import com.android.systemui.plugins.clocks.ClockFontAxis 23 import kotlin.math.abs 24 25 class ClockFontSwitchViewHolder(val name: TextView, val switch: Switch) { 26 27 private var switchMaxValue: Float? = null 28 29 fun setIsVisible(isVisible: Boolean) { 30 name.isVisible = isVisible 31 switch.isVisible = isVisible 32 } 33 34 fun initView(clockFontAxis: ClockFontAxis, onFontAxisValueUpdated: (value: Float) -> Unit) { 35 switchMaxValue = clockFontAxis.maxValue 36 name.text = clockFontAxis.name 37 switch.apply { 38 isChecked = abs(clockFontAxis.currentValue - clockFontAxis.maxValue) < 0.01f 39 setOnCheckedChangeListener { v, _ -> 40 val value = if (v.isChecked) clockFontAxis.maxValue else clockFontAxis.minValue 41 onFontAxisValueUpdated.invoke(value) 42 } 43 } 44 } 45 46 fun setValue(value: Float) { 47 switchMaxValue?.let { switch.isChecked = abs(value - it) < 0.01f } 48 } 49 } 50