Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e314c9cd authored by Sherry Zhou's avatar Sherry Zhou
Browse files

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
parent 5d680a8d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
+26 −21
Original line number Diff line number Diff line
@@ -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")
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -34,4 +34,8 @@ class WeatherEffectsInteractor @Inject constructor(
    suspend fun loadWallpaper() {
        repository.loadWallpaperFromLocalStorage()
    }

    suspend fun saveWallpaper() {
        repository.saveWallpaper()
    }
}