1 /*
2  * Copyright (C) 2021 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 package com.android.wallpaper.picker.customization.data.repository
17 
18 import android.app.WallpaperColors
19 import com.android.wallpaper.picker.customization.shared.model.WallpaperColorsModel
20 import kotlinx.coroutines.flow.MutableStateFlow
21 import kotlinx.coroutines.flow.StateFlow
22 import kotlinx.coroutines.flow.asStateFlow
23 
24 /** ViewModel class to keep track of WallpaperColors for the current wallpaper */
25 class WallpaperColorsRepository {
26 
27     private val _homeWallpaperColors =
28         MutableStateFlow<WallpaperColorsModel>(WallpaperColorsModel.Loading)
29     /** WallpaperColors for the currently set home wallpaper */
30     val homeWallpaperColors: StateFlow<WallpaperColorsModel> = _homeWallpaperColors.asStateFlow()
31 
32     private val _lockWallpaperColors =
33         MutableStateFlow<WallpaperColorsModel>(WallpaperColorsModel.Loading)
34     /** WallpaperColors for the currently set lock wallpaper */
35     val lockWallpaperColors: StateFlow<WallpaperColorsModel> = _lockWallpaperColors.asStateFlow()
36 
setHomeWallpaperColorsnull37     fun setHomeWallpaperColors(colors: WallpaperColors?) {
38         _homeWallpaperColors.value = WallpaperColorsModel.Loaded(colors)
39     }
40 
setLockWallpaperColorsnull41     fun setLockWallpaperColors(colors: WallpaperColors?) {
42         _lockWallpaperColors.value = WallpaperColorsModel.Loaded(colors)
43     }
44 }
45