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.util 18 19 import android.view.LayoutInflater 20 import android.view.View 21 import android.widget.FrameLayout 22 import android.widget.LinearLayout 23 import com.android.themepicker.R 24 import com.android.wallpaper.model.Screen 25 import com.android.wallpaper.model.Screen.HOME_SCREEN 26 import com.android.wallpaper.model.Screen.LOCK_SCREEN 27 import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil 28 import com.android.wallpaper.picker.customization.ui.util.DefaultCustomizationOptionUtil 29 import dagger.hilt.android.scopes.ActivityScoped 30 import javax.inject.Inject 31 32 @ActivityScoped 33 class ThemePickerCustomizationOptionUtil 34 @Inject 35 constructor(private val defaultCustomizationOptionUtil: DefaultCustomizationOptionUtil) : 36 CustomizationOptionUtil { 37 38 enum class ThemePickerLockCustomizationOption : CustomizationOptionUtil.CustomizationOption { 39 CLOCK, 40 SHORTCUTS, 41 SHOW_NOTIFICATIONS, 42 MORE_LOCK_SCREEN_SETTINGS, 43 } 44 45 enum class ThemePickerHomeCustomizationOption : CustomizationOptionUtil.CustomizationOption { 46 COLORS, 47 APP_GRID, 48 APP_SHAPE, 49 THEMED_ICONS, 50 } 51 52 private var viewMap: Map<CustomizationOptionUtil.CustomizationOption, View>? = null 53 getOptionEntriesnull54 override fun getOptionEntries( 55 screen: Screen, 56 optionContainer: LinearLayout, 57 layoutInflater: LayoutInflater, 58 ): List<Pair<CustomizationOptionUtil.CustomizationOption, View>> { 59 val defaultOptionEntries = 60 defaultCustomizationOptionUtil.getOptionEntries( 61 screen, 62 optionContainer, 63 layoutInflater, 64 ) 65 return when (screen) { 66 LOCK_SCREEN -> 67 buildList { 68 addAll(defaultOptionEntries) 69 add( 70 ThemePickerLockCustomizationOption.CLOCK to 71 layoutInflater.inflate( 72 R.layout.customization_option_entry_clock, 73 optionContainer, 74 false, 75 ) 76 ) 77 add( 78 ThemePickerLockCustomizationOption.SHORTCUTS to 79 layoutInflater.inflate( 80 R.layout.customization_option_entry_keyguard_quick_affordance, 81 optionContainer, 82 false 83 ) 84 ) 85 add( 86 ThemePickerLockCustomizationOption.SHOW_NOTIFICATIONS to 87 layoutInflater.inflate( 88 R.layout.customization_option_entry_show_notifications, 89 optionContainer, 90 false, 91 ) 92 ) 93 add( 94 ThemePickerLockCustomizationOption.MORE_LOCK_SCREEN_SETTINGS to 95 layoutInflater.inflate( 96 R.layout.customization_option_entry_more_lock_settings, 97 optionContainer, 98 false, 99 ) 100 ) 101 } 102 HOME_SCREEN -> 103 buildList { 104 addAll(defaultOptionEntries) 105 add( 106 ThemePickerHomeCustomizationOption.COLORS to 107 layoutInflater.inflate( 108 R.layout.customization_option_entry_colors, 109 optionContainer, 110 false, 111 ) 112 ) 113 add( 114 ThemePickerHomeCustomizationOption.APP_GRID to 115 layoutInflater.inflate( 116 R.layout.customization_option_entry_app_grid, 117 optionContainer, 118 false, 119 ) 120 ) 121 add( 122 ThemePickerHomeCustomizationOption.APP_SHAPE to 123 layoutInflater.inflate( 124 R.layout.customization_option_entry_app_shape, 125 optionContainer, 126 false, 127 ) 128 ) 129 add( 130 ThemePickerHomeCustomizationOption.THEMED_ICONS to 131 layoutInflater.inflate( 132 R.layout.customization_option_entry_themed_icons, 133 optionContainer, 134 false, 135 ) 136 ) 137 } 138 } 139 } 140 initBottomSheetContentnull141 override fun initBottomSheetContent( 142 bottomSheetContainer: FrameLayout, 143 layoutInflater: LayoutInflater 144 ) { 145 defaultCustomizationOptionUtil.initBottomSheetContent(bottomSheetContainer, layoutInflater) 146 viewMap = buildMap { 147 put( 148 ThemePickerLockCustomizationOption.CLOCK, 149 createCustomizationPickerBottomSheetView( 150 ThemePickerLockCustomizationOption.CLOCK, 151 bottomSheetContainer, 152 layoutInflater, 153 ) 154 .also { bottomSheetContainer.addView(it) } 155 ) 156 put( 157 ThemePickerLockCustomizationOption.SHORTCUTS, 158 createCustomizationPickerBottomSheetView( 159 ThemePickerLockCustomizationOption.SHORTCUTS, 160 bottomSheetContainer, 161 layoutInflater, 162 ) 163 .also { bottomSheetContainer.addView(it) } 164 ) 165 } 166 } 167 getBottomSheetContentnull168 override fun getBottomSheetContent(option: CustomizationOptionUtil.CustomizationOption): View? { 169 return defaultCustomizationOptionUtil.getBottomSheetContent(option) ?: viewMap?.get(option) 170 } 171 onDestroynull172 override fun onDestroy() { 173 viewMap = null 174 } 175 createCustomizationPickerBottomSheetViewnull176 private fun createCustomizationPickerBottomSheetView( 177 option: ThemePickerLockCustomizationOption, 178 bottomSheetContainer: FrameLayout, 179 layoutInflater: LayoutInflater, 180 ): View = 181 when (option) { 182 ThemePickerLockCustomizationOption.CLOCK -> R.layout.bottom_sheet_clock 183 ThemePickerLockCustomizationOption.SHORTCUTS -> R.layout.bottom_sheet_shortcut 184 else -> 185 throw IllegalStateException( 186 "Customization option $option does not have a bottom sheet view" 187 ) 188 }.let { layoutInflater.inflate(it, bottomSheetContainer, false) } 189 } 190