1 /*
2  * 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 package com.android.wallpaper.picker.preview.domain.interactor
18 
19 import android.app.WallpaperColors
20 import android.graphics.Bitmap
21 import android.graphics.Point
22 import android.graphics.Rect
23 import com.android.wallpaper.asset.Asset
24 import com.android.wallpaper.module.logging.UserEventLogger
25 import com.android.wallpaper.picker.customization.data.repository.WallpaperRepository
26 import com.android.wallpaper.picker.customization.shared.model.WallpaperDestination
27 import com.android.wallpaper.picker.data.WallpaperModel
28 import com.android.wallpaper.picker.data.WallpaperModel.StaticWallpaperModel
29 import com.android.wallpaper.picker.preview.data.repository.WallpaperPreviewRepository
30 import com.android.wallpaper.picker.preview.shared.model.FullPreviewCropModel
31 import dagger.hilt.android.scopes.ActivityRetainedScoped
32 import javax.inject.Inject
33 import kotlinx.coroutines.flow.StateFlow
34 
35 @ActivityRetainedScoped
36 class WallpaperPreviewInteractor
37 @Inject
38 constructor(
39     private val wallpaperPreviewRepository: WallpaperPreviewRepository,
40     private val wallpaperRepository: WallpaperRepository,
41 ) {
42     val wallpaperModel: StateFlow<WallpaperModel?> = wallpaperPreviewRepository.wallpaperModel
43 
44     val hasSmallPreviewTooltipBeenShown: StateFlow<Boolean> =
45         wallpaperPreviewRepository.hasSmallPreviewTooltipBeenShown
hideSmallPreviewTooltipnull46     fun hideSmallPreviewTooltip() = wallpaperPreviewRepository.hideSmallPreviewTooltip()
47 
48     val hasFullPreviewTooltipBeenShown: StateFlow<Boolean> =
49         wallpaperPreviewRepository.hasFullPreviewTooltipBeenShown
50     fun hideFullPreviewTooltip() = wallpaperPreviewRepository.hideFullPreviewTooltip()
51 
52     suspend fun setStaticWallpaper(
53         @UserEventLogger.SetWallpaperEntryPoint setWallpaperEntryPoint: Int,
54         destination: WallpaperDestination,
55         wallpaperModel: StaticWallpaperModel,
56         bitmap: Bitmap,
57         wallpaperSize: Point,
58         asset: Asset,
59         fullPreviewCropModels: Map<Point, FullPreviewCropModel>? = null,
60     ) {
61         wallpaperRepository.setStaticWallpaper(
62             setWallpaperEntryPoint,
63             destination,
64             wallpaperModel,
65             bitmap,
66             wallpaperSize,
67             asset,
68             fullPreviewCropModels,
69         )
70     }
71 
setLiveWallpapernull72     suspend fun setLiveWallpaper(
73         @UserEventLogger.SetWallpaperEntryPoint setWallpaperEntryPoint: Int,
74         destination: WallpaperDestination,
75         wallpaperModel: WallpaperModel.LiveWallpaperModel,
76     ) {
77         wallpaperRepository.setLiveWallpaper(
78             setWallpaperEntryPoint,
79             destination,
80             wallpaperModel,
81         )
82     }
83 
getWallpaperColorsnull84     suspend fun getWallpaperColors(bitmap: Bitmap, cropHints: Map<Point, Rect>?): WallpaperColors? =
85         wallpaperRepository.getWallpaperColors(bitmap, cropHints)
86 }
87