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 androidx.lifecycle.viewModelScope
21 import com.android.wallpaper.model.Screen
22 import com.android.wallpaper.model.Screen.LOCK_SCREEN
23 import com.android.wallpaper.picker.common.preview.ui.viewmodel.BasePreviewViewModel
24 import dagger.hilt.android.lifecycle.HiltViewModel
25 import javax.inject.Inject
26 import kotlinx.coroutines.flow.Flow
27 import kotlinx.coroutines.flow.MutableStateFlow
28 import kotlinx.coroutines.flow.asStateFlow
29 import kotlinx.coroutines.flow.map
30 
31 @HiltViewModel
32 class CustomizationPickerViewModel2
33 @Inject
34 constructor(
35     customizationOptionsViewModelFactory: CustomizationOptionsViewModelFactory,
36     basePreviewViewModelFactory: BasePreviewViewModel.Factory,
37 ) : ViewModel() {
38 
39     val customizationOptionsViewModel =
40         customizationOptionsViewModelFactory.create(viewModelScope = viewModelScope)
41     val basePreviewViewModel = basePreviewViewModelFactory.create(viewModelScope)
42 
43     enum class PickerScreen {
44         MAIN,
45         CUSTOMIZATION_OPTION,
46     }
47 
48     private val _selectedPreviewScreen = MutableStateFlow(LOCK_SCREEN)
49     val selectedPreviewScreen = _selectedPreviewScreen.asStateFlow()
50 
selectPreviewScreennull51     fun selectPreviewScreen(screen: Screen) {
52         _selectedPreviewScreen.value = screen
53     }
54 
55     val screen =
<lambda>null56         customizationOptionsViewModel.selectedOption.map {
57             if (it != null) {
58                 Pair(PickerScreen.CUSTOMIZATION_OPTION, it)
59             } else {
60                 Pair(PickerScreen.MAIN, null)
61             }
62         }
63 
<lambda>null64     val isPreviewClickable: Flow<Boolean> = basePreviewViewModel.wallpapers.map { it != null }
65 
66     val isPagerInteractable: Flow<Boolean> =
<lambda>null67         customizationOptionsViewModel.selectedOption.map { it == null }
68 }
69