1 /* <lambda>null2 * Copyright 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 com.android.wallpaper.effects.Effect 20 import com.android.wallpaper.effects.EffectsController.EffectEnumInterface 21 import com.android.wallpaper.picker.data.WallpaperModel 22 import com.android.wallpaper.picker.preview.data.repository.CreativeEffectsRepository 23 import com.android.wallpaper.picker.preview.data.repository.DownloadableWallpaperRepository 24 import com.android.wallpaper.picker.preview.data.repository.ImageEffectsRepository 25 import com.android.wallpaper.picker.preview.data.repository.WallpaperPreviewRepository 26 import com.android.wallpaper.picker.preview.shared.model.DownloadableWallpaperModel 27 import com.android.wallpaper.widget.floatingsheetcontent.WallpaperEffectsView2 28 import dagger.hilt.android.scopes.ActivityRetainedScoped 29 import javax.inject.Inject 30 import kotlinx.coroutines.flow.Flow 31 import kotlinx.coroutines.flow.StateFlow 32 33 /** This class handles the business logic for Preview screen's action buttons */ 34 @ActivityRetainedScoped 35 class PreviewActionsInteractor 36 @Inject 37 constructor( 38 private val wallpaperPreviewRepository: WallpaperPreviewRepository, 39 private val imageEffectsRepository: ImageEffectsRepository, 40 private val creativeEffectsRepository: CreativeEffectsRepository, 41 private val downloadableWallpaperRepository: DownloadableWallpaperRepository, 42 ) { 43 val wallpaperModel: StateFlow<WallpaperModel?> = wallpaperPreviewRepository.wallpaperModel 44 45 val downloadableWallpaperModel: Flow<DownloadableWallpaperModel> = 46 downloadableWallpaperRepository.downloadableWallpaperModel 47 48 val imageEffectsModel = imageEffectsRepository.imageEffectsModel 49 val imageEffect = imageEffectsRepository.wallpaperEffect 50 val creativeEffectsModel = creativeEffectsRepository.creativeEffectsModel 51 52 suspend fun turnOnCreativeEffect(actionPosition: Int) { 53 creativeEffectsRepository.turnOnCreativeEffect(actionPosition) 54 } 55 56 fun enableImageEffect(effect: EffectEnumInterface) { 57 imageEffectsRepository.enableImageEffect(effect) 58 } 59 60 fun disableImageEffect() { 61 imageEffectsRepository.disableImageEffect() 62 } 63 64 fun isTargetEffect(effect: EffectEnumInterface): Boolean { 65 return imageEffectsRepository.isTargetEffect(effect) 66 } 67 68 fun getEffectTextRes(): WallpaperEffectsView2.EffectTextRes { 69 return imageEffectsRepository.getEffectTextRes() 70 } 71 72 fun downloadWallpaper() { 73 downloadableWallpaperRepository.downloadWallpaper { viewModel -> 74 // If download success, update wallpaper preview repo's WallpaperModel to render the 75 // live wallpaper. 76 wallpaperPreviewRepository.setWallpaperModel(viewModel) 77 } 78 } 79 80 fun cancelDownloadWallpaper(): Boolean = 81 downloadableWallpaperRepository.cancelDownloadWallpaper() 82 83 fun startEffectsModelDownload(effect: Effect) { 84 imageEffectsRepository.startEffectsModelDownload(effect) 85 } 86 87 fun interruptEffectsModelDownload(effect: Effect) { 88 imageEffectsRepository.interruptEffectsModelDownload(effect) 89 } 90 } 91