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.binder 18 19 import android.view.View 20 import androidx.lifecycle.Lifecycle 21 import androidx.lifecycle.LifecycleOwner 22 import androidx.lifecycle.lifecycleScope 23 import androidx.lifecycle.repeatOnLifecycle 24 import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption 25 import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel 26 import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder 27 import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder 28 import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil.CustomizationOption 29 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel 30 import javax.inject.Inject 31 import javax.inject.Singleton 32 import kotlinx.coroutines.launch 33 34 @Singleton 35 class ThemePickerCustomizationOptionsBinder 36 @Inject 37 constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationOptionsBinder) : 38 CustomizationOptionsBinder { 39 40 override fun bind( 41 view: View, 42 lockScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 43 homeScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 44 viewModel: CustomizationOptionsViewModel, 45 lifecycleOwner: LifecycleOwner 46 ) { 47 defaultCustomizationOptionsBinder.bind( 48 view, 49 lockScreenCustomizationOptionEntries, 50 homeScreenCustomizationOptionEntries, 51 viewModel, 52 lifecycleOwner 53 ) 54 55 val optionClock = 56 lockScreenCustomizationOptionEntries 57 .find { it.first == ThemePickerLockCustomizationOption.CLOCK } 58 ?.second 59 val optionShortcut = 60 lockScreenCustomizationOptionEntries 61 .find { it.first == ThemePickerLockCustomizationOption.SHORTCUTS } 62 ?.second 63 viewModel as ThemePickerCustomizationOptionsViewModel 64 65 lifecycleOwner.lifecycleScope.launch { 66 lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { 67 launch { 68 viewModel.onCustomizeClockClicked.collect { 69 optionClock?.setOnClickListener { _ -> it?.invoke() } 70 } 71 } 72 73 launch { 74 viewModel.onCustomizeShortcutClicked.collect { 75 optionShortcut?.setOnClickListener { _ -> it?.invoke() } 76 } 77 } 78 } 79 } 80 } 81 } 82