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.customization.picker.settings.ui.binder 18 19 import android.view.View 20 import android.widget.ImageView 21 import android.widget.TextView 22 import androidx.core.view.isVisible 23 import androidx.lifecycle.Lifecycle 24 import androidx.lifecycle.LifecycleOwner 25 import androidx.lifecycle.flowWithLifecycle 26 import androidx.lifecycle.lifecycleScope 27 import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSectionViewModel 28 import com.android.themepicker.R 29 import com.android.wallpaper.picker.common.icon.ui.viewbinder.IconViewBinder 30 import com.android.wallpaper.picker.common.text.ui.viewbinder.TextViewBinder 31 import kotlinx.coroutines.flow.collectLatest 32 import kotlinx.coroutines.launch 33 34 object ColorContrastSectionViewBinder { 35 fun bind( 36 view: View, 37 viewModel: ColorContrastSectionViewModel, 38 lifecycleOwner: LifecycleOwner, 39 onClicked: () -> Unit, 40 ) { 41 view.setOnClickListener { onClicked() } 42 43 val descriptionView: TextView = 44 view.requireViewById(R.id.color_contrast_section_description) 45 val icon: ImageView = view.requireViewById(R.id.icon_1) 46 47 lifecycleOwner.lifecycleScope.launch { 48 viewModel.summary 49 .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED) 50 .collectLatest { summary -> 51 TextViewBinder.bind( 52 view = descriptionView, 53 viewModel = summary.description, 54 ) 55 if (summary.icon != null) { 56 IconViewBinder.bind( 57 view = icon, 58 viewModel = summary.icon, 59 ) 60 } 61 icon.isVisible = summary.icon != null 62 } 63 } 64 } 65 } 66