diff options
author | Sherry Zhou <yuandizhou@google.com> | 2023-11-06 22:46:57 +0000 |
---|---|---|
committer | Sherry Zhou <yuandizhou@google.com> | 2023-11-13 17:55:13 +0000 |
commit | e314c9cd6b80c8e3ea6116ae2d64efaec384a4b2 (patch) | |
tree | cbf48fb2af7e5e60d1935bfad03448c493446aa0 | |
parent | 5d680a8d240a55c6430240bd1438cb09f625238d (diff) | |
download | systemui-e314c9cd6b80c8e3ea6116ae2d64efaec384a4b2.tar.gz |
Make saveWallpaper only being called when setWallpaper is clicked
This version can save and load wallpaper with fixed names
Flag: None
Bug: 308445764
Test: Will develop in b/309848157
Change-Id: I5e322ada59baedb3830f3414797ebcd12a9b1951
3 files changed, 41 insertions, 21 deletions
diff --git a/weathereffects/debug/src/com/google/android/wallpaper/weathereffects/WallpaperEffectsDebugActivity.kt b/weathereffects/debug/src/com/google/android/wallpaper/weathereffects/WallpaperEffectsDebugActivity.kt index a54b885..afbd4e3 100644 --- a/weathereffects/debug/src/com/google/android/wallpaper/weathereffects/WallpaperEffectsDebugActivity.kt +++ b/weathereffects/debug/src/com/google/android/wallpaper/weathereffects/WallpaperEffectsDebugActivity.kt @@ -34,6 +34,7 @@ import androidx.constraintlayout.widget.ConstraintLayout import com.google.android.torus.core.activity.TorusViewerActivity import com.google.android.torus.core.engine.TorusEngine import com.google.android.torus.utils.extensions.setImmersiveFullScreen +import com.google.android.wallpaper.weathereffects.dagger.BackgroundScope import com.google.android.wallpaper.weathereffects.dagger.MainScope import com.google.android.wallpaper.weathereffects.provider.WallpaperInfoContract import com.google.android.wallpaper.weathereffects.shared.model.WallpaperFileModel @@ -50,6 +51,9 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() { @MainScope lateinit var mainScope: CoroutineScope @Inject + @BackgroundScope + lateinit var bgScope: CoroutineScope + @Inject lateinit var context: Context @Inject lateinit var interactor: WeatherEffectsInteractor @@ -116,6 +120,7 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() { ComponentName(this, WeatherWallpaperService::class.java) ) this.startActivityForResult(i, SET_WALLPAPER_REQUEST_CODE) + saveWallpaper() } rootView.requireViewById<FrameLayout>(R.id.wallpaper_layout) @@ -187,6 +192,12 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() { } } + private fun saveWallpaper() { + bgScope.launch { + interactor.saveWallpaper() + } + } + private fun setDebugText(text: String? = null) { val output = rootView.requireViewById<TextView>(R.id.output) output.text = text diff --git a/weathereffects/src/com/google/android/wallpaper/weathereffects/data/repository/WeatherEffectsRepository.kt b/weathereffects/src/com/google/android/wallpaper/weathereffects/data/repository/WeatherEffectsRepository.kt index a2ed15a..8b2fc6f 100644 --- a/weathereffects/src/com/google/android/wallpaper/weathereffects/data/repository/WeatherEffectsRepository.kt +++ b/weathereffects/src/com/google/android/wallpaper/weathereffects/data/repository/WeatherEffectsRepository.kt @@ -61,23 +61,6 @@ class WeatherEffectsRepository @Inject constructor( val foreground = fgBitmap!! val background = bgBitmap!! - - var success = true - // TODO: Only persist assets when the wallpaper is applied. - success = success and WallpaperFileUtils.export( - context, - WallpaperFileUtils.FG_FILE_NAME, - foreground, - ) - success = success and WallpaperFileUtils.export( - context, - WallpaperFileUtils.BG_FILE_NAME, - background, - ) - if (!success) { - Log.e(TAG, "Failed to export assets during wallpaper generation") - return - } _wallpaperImage.value = WallpaperImageModel( foreground, background, @@ -85,10 +68,8 @@ class WeatherEffectsRepository @Inject constructor( ) } catch (e: RuntimeException) { Log.e(TAG, "Unable to load wallpaper: ", e) - null } catch (e: OutOfMemoryError) { Log.e(TAG, "Unable to load wallpaper: ", e) - null } } @@ -115,10 +96,34 @@ class WeatherEffectsRepository @Inject constructor( ) } catch (e: RuntimeException) { Log.e(TAG, "Unable to load wallpaper: ", e) - null } catch (e: OutOfMemoryError) { Log.e(TAG, "Unable to load wallpaper: ", e) - null + } + } + + suspend fun saveWallpaper() { + val foreground = _wallpaperImage.value?.foreground + val background = _wallpaperImage.value?.background + + var success = true + success = success and (foreground?.let { + WallpaperFileUtils.export( + context, + WallpaperFileUtils.FG_FILE_NAME, + it, + ) + } == true) + success = success and (background?.let { + WallpaperFileUtils.export( + context, + WallpaperFileUtils.BG_FILE_NAME, + it, + ) + } == true) + if (success) { + Log.d(TAG, "Successfully save wallpaper") + } else { + Log.e(TAG, "Failed to save wallpaper") } } diff --git a/weathereffects/src/com/google/android/wallpaper/weathereffects/domain/WeatherEffectsInteractor.kt b/weathereffects/src/com/google/android/wallpaper/weathereffects/domain/WeatherEffectsInteractor.kt index ca8b961..22e4b44 100644 --- a/weathereffects/src/com/google/android/wallpaper/weathereffects/domain/WeatherEffectsInteractor.kt +++ b/weathereffects/src/com/google/android/wallpaper/weathereffects/domain/WeatherEffectsInteractor.kt @@ -34,4 +34,8 @@ class WeatherEffectsInteractor @Inject constructor( suspend fun loadWallpaper() { repository.loadWallpaperFromLocalStorage() } + + suspend fun saveWallpaper() { + repository.saveWallpaper() + } } |