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.picker.customization.ui.binder 18 19 import android.content.Context 20 import android.content.res.ColorStateList 21 import android.view.View 22 import android.widget.TextView 23 import androidx.core.widget.TextViewCompat 24 import androidx.lifecycle.LifecycleOwner 25 import com.android.customization.picker.clock.ui.view.ClockViewFactory 26 import com.android.wallpaper.R 27 import com.android.wallpaper.model.Screen 28 import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil.CustomizationOption 29 import com.android.wallpaper.picker.customization.ui.util.DefaultCustomizationOptionUtil 30 import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel 31 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2 32 import javax.inject.Inject 33 import javax.inject.Singleton 34 35 @Singleton 36 class DefaultCustomizationOptionsBinder @Inject constructor() : CustomizationOptionsBinder { 37 38 override fun bind( 39 view: View, 40 lockScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 41 homeScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 42 customizationOptionFloatingSheetViewMap: Map<CustomizationOption, View>?, 43 viewModel: CustomizationPickerViewModel2, 44 colorUpdateViewModel: ColorUpdateViewModel, 45 lifecycleOwner: LifecycleOwner, 46 navigateToWallpaperCategoriesScreen: (screen: Screen) -> Unit, 47 ) { 48 val moreWallpapersLock = 49 lockScreenCustomizationOptionEntries 50 .find { 51 it.first == 52 DefaultCustomizationOptionUtil.DefaultLockCustomizationOption.WALLPAPER 53 } 54 ?.second 55 ?.findViewById<TextView>(R.id.more_wallpapers) 56 val moreWallpapersHome = 57 homeScreenCustomizationOptionEntries 58 .find { 59 it.first == 60 DefaultCustomizationOptionUtil.DefaultHomeCustomizationOption.WALLPAPER 61 } 62 ?.second 63 ?.findViewById<TextView>(R.id.more_wallpapers) 64 65 moreWallpapersLock?.setOnClickListener { 66 navigateToWallpaperCategoriesScreen.invoke(Screen.LOCK_SCREEN) 67 } 68 69 moreWallpapersHome?.setOnClickListener { 70 navigateToWallpaperCategoriesScreen.invoke(Screen.HOME_SCREEN) 71 } 72 73 ColorUpdateBinder.bind( 74 setColor = { color -> 75 moreWallpapersLock?.apply { 76 setTextColor(color) 77 TextViewCompat.setCompoundDrawableTintList(this, ColorStateList.valueOf(color)) 78 } 79 }, 80 color = colorUpdateViewModel.colorPrimary, 81 shouldAnimate = { 82 viewModel.selectedPreviewScreen.value == Screen.LOCK_SCREEN && 83 viewModel.customizationOptionsViewModel.selectedOption.value == null 84 }, 85 lifecycleOwner = lifecycleOwner, 86 ) 87 88 ColorUpdateBinder.bind( 89 setColor = { color -> 90 moreWallpapersHome?.apply { 91 setTextColor(color) 92 TextViewCompat.setCompoundDrawableTintList(this, ColorStateList.valueOf(color)) 93 } 94 }, 95 color = colorUpdateViewModel.colorPrimary, 96 shouldAnimate = { 97 viewModel.selectedPreviewScreen.value == Screen.HOME_SCREEN && 98 viewModel.customizationOptionsViewModel.selectedOption.value == null 99 }, 100 lifecycleOwner = lifecycleOwner, 101 ) 102 } 103 104 override fun bindClockPreview( 105 context: Context, 106 clockHostView: View, 107 viewModel: CustomizationPickerViewModel2, 108 colorUpdateViewModel: ColorUpdateViewModel, 109 lifecycleOwner: LifecycleOwner, 110 clockViewFactory: ClockViewFactory, 111 ) { 112 // Do nothing intended 113 } 114 } 115