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.picker.customization.ui.viewmodel 18 19 import androidx.lifecycle.ViewModel 20 import com.android.wallpaper.model.Screen 21 import com.android.wallpaper.model.Screen.LOCK_SCREEN 22 import dagger.hilt.android.lifecycle.HiltViewModel 23 import javax.inject.Inject 24 import kotlinx.coroutines.flow.MutableStateFlow 25 import kotlinx.coroutines.flow.asStateFlow 26 import kotlinx.coroutines.flow.map 27 28 @HiltViewModel 29 class CustomizationPickerViewModel2 30 @Inject 31 constructor( 32 val customizationOptionsViewModel: CustomizationOptionsViewModel, 33 ) : ViewModel() { 34 35 enum class PickerScreen { 36 MAIN, 37 CUSTOMIZATION_OPTION, 38 } 39 40 private val _selectedPreviewScreen = MutableStateFlow(LOCK_SCREEN) 41 val selectedPreviewScreen = _selectedPreviewScreen.asStateFlow() 42 selectPreviewScreennull43 fun selectPreviewScreen(screen: Screen) { 44 _selectedPreviewScreen.value = screen 45 } 46 47 val screen = <lambda>null48 customizationOptionsViewModel.selectedOption.map { 49 if (it != null) { 50 Pair(PickerScreen.CUSTOMIZATION_OPTION, it) 51 } else { 52 Pair(PickerScreen.MAIN, null) 53 } 54 } 55 onBackPressednull56 fun onBackPressed(): Boolean = customizationOptionsViewModel.deselectOption() 57 } 58