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.wallpaper.model.WallpaperInfo 25 import com.android.wallpaper.module.CustomizationSections 26 import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor 27 import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel 28 import com.android.wallpaper.util.PreviewUtils 29 import kotlinx.coroutines.flow.Flow 30 import kotlinx.coroutines.flow.combine 31 32 /** A ThemePicker version of the [ScreenPreviewViewModel] */ 33 class PreviewWithThemeViewModel( 34 previewUtils: PreviewUtils, 35 initialExtrasProvider: () -> Bundle? = { null }, 36 wallpaperInfoProvider: suspend (forceReload: Boolean) -> WallpaperInfo?, <lambda>null37 onWallpaperColorChanged: (WallpaperColors?) -> Unit = {}, 38 wallpaperInteractor: WallpaperInteractor, 39 private val themedIconInteractor: ThemedIconInteractor? = null, 40 colorPickerInteractor: ColorPickerInteractor? = null, 41 screen: CustomizationSections.Screen, 42 ) : 43 ScreenPreviewViewModel( 44 previewUtils, 45 initialExtrasProvider, 46 wallpaperInfoProvider, 47 onWallpaperColorChanged, 48 wallpaperInteractor, 49 screen, 50 ) { workspaceUpdateEventsnull51 override fun workspaceUpdateEvents(): Flow<Boolean>? = themedIconInteractor?.isActivated 52 53 private val wallpaperIsLoading = super.isLoading 54 55 override val isLoading: Flow<Boolean> = 56 colorPickerInteractor?.let { 57 combine(wallpaperIsLoading, colorPickerInteractor.isApplyingSystemColor) { 58 wallpaperIsLoading, 59 colorIsLoading -> 60 wallpaperIsLoading || colorIsLoading 61 } 62 } 63 ?: wallpaperIsLoading 64 } 65