1 /*
<lambda>null2  * Copyright (C) 2023 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 
18 package com.android.customization.picker.preview.ui.viewmodel
19 
20 import android.app.WallpaperColors
21 import android.os.Bundle
22 import com.android.customization.model.themedicon.domain.interactor.ThemedIconInteractor
23 import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor
24 import com.android.customization.picker.grid.domain.interactor.GridInteractor
25 import com.android.wallpaper.model.Screen
26 import com.android.wallpaper.model.WallpaperInfo
27 import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
28 import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel
29 import com.android.wallpaper.util.PreviewUtils
30 import kotlinx.coroutines.flow.Flow
31 import kotlinx.coroutines.flow.combine
32 import kotlinx.coroutines.flow.map
33 import kotlinx.coroutines.flow.merge
34 
35 /** A ThemePicker version of the [ScreenPreviewViewModel] */
36 class PreviewWithThemeViewModel(
37     previewUtils: PreviewUtils,
38     initialExtrasProvider: () -> Bundle? = { null },
39     wallpaperInfoProvider: suspend (forceReload: Boolean) -> WallpaperInfo?,
<lambda>null40     onWallpaperColorChanged: (WallpaperColors?) -> Unit = {},
41     wallpaperInteractor: WallpaperInteractor,
42     private val themedIconInteractor: ThemedIconInteractor,
43     private val gridInteractor: GridInteractor,
44     colorPickerInteractor: ColorPickerInteractor? = null,
45     screen: Screen,
46 ) :
47     ScreenPreviewViewModel(
48         previewUtils,
49         initialExtrasProvider,
50         wallpaperInfoProvider,
51         onWallpaperColorChanged,
52         wallpaperInteractor,
53         screen,
54     ) {
workspaceUpdateEventsnull55     override fun workspaceUpdateEvents(): Flow<Unit> =
56         merge(
57             themedIconInteractor.isActivated.map {},
<lambda>null58             gridInteractor.getSelectOptionStateFlow().map {}
59         )
60 
61     private val wallpaperIsLoading = super.isLoading
62 
63     override val isLoading: Flow<Boolean> =
<lambda>null64         colorPickerInteractor?.let {
65             combine(wallpaperIsLoading, colorPickerInteractor.isApplyingSystemColor) {
66                 wallpaperIsLoading,
67                 colorIsLoading ->
68                 wallpaperIsLoading || colorIsLoading
69             }
70         } ?: wallpaperIsLoading
71 }
72