1 /* 2 * Copyright (C) 2022 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.wallpaper.picker.customization.ui.viewmodel 19 20 import android.app.WallpaperColors 21 import android.os.Bundle 22 import com.android.wallpaper.model.WallpaperInfo 23 import com.android.wallpaper.module.CustomizationSections 24 import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor 25 import com.android.wallpaper.picker.customization.shared.model.WallpaperModel 26 import com.android.wallpaper.util.PreviewUtils 27 import kotlinx.coroutines.flow.Flow 28 29 /** Models the UI state for a preview of the home screen or lock screen. */ 30 class ScreenPreviewViewModel( 31 val previewUtils: PreviewUtils, <lambda>null32 private val initialExtrasProvider: () -> Bundle? = { null }, 33 private val wallpaperInfoProvider: suspend () -> WallpaperInfo?, <lambda>null34 private val onWallpaperColorChanged: (WallpaperColors?) -> Unit = {}, 35 // TODO (b/270193793): add below field to all usages, remove default value & make non-nullable 36 private val wallpaperInteractor: WallpaperInteractor? = null, 37 ) { 38 /** Returns whether wallpaper picker should handle reload */ shouldHandleReloadnull39 fun shouldHandleReload(): Boolean { 40 return wallpaperInteractor?.let { it.shouldHandleReload() } ?: true 41 } 42 43 /** Returns a flow that is updated whenever the wallpaper has been updated */ wallpaperUpdateEventsnull44 fun wallpaperUpdateEvents(screen: CustomizationSections.Screen): Flow<WallpaperModel>? { 45 return wallpaperInteractor?.wallpaperUpdateEvents(screen) 46 } 47 getInitialExtrasnull48 fun getInitialExtras(): Bundle? { 49 return initialExtrasProvider.invoke() 50 } 51 getWallpaperInfonull52 suspend fun getWallpaperInfo(): WallpaperInfo? { 53 return wallpaperInfoProvider.invoke() 54 } 55 onWallpaperColorsChangednull56 fun onWallpaperColorsChanged(colors: WallpaperColors?) { 57 onWallpaperColorChanged.invoke(colors) 58 } 59 } 60