Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
closes #23514: add firefox wallpapers
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewTighe authored and mergify[bot] committed Feb 2, 2022
1 parent 4780eba commit 0837197
Show file tree
Hide file tree
Showing 27 changed files with 23 additions and 131 deletions.
Binary file removed app/src/main/assets/wallpapers/wallpaper_1.png
Binary file not shown.
Binary file removed app/src/main/assets/wallpapers/wallpaper_2.png
Binary file not shown.
14 changes: 0 additions & 14 deletions app/src/main/assets/wallpapers/wallpapers.json

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main/java/org/mozilla/fenix/components/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import org.mozilla.fenix.utils.ClipboardHandler
import org.mozilla.fenix.utils.Settings
import org.mozilla.fenix.wallpapers.WallpaperDownloader
import org.mozilla.fenix.wallpapers.WallpaperManager
import org.mozilla.fenix.wallpapers.WallpapersAssetsStorage
import org.mozilla.fenix.wifi.WifiConnectionMonitor
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -148,7 +147,6 @@ class Components(private val context: Context) {
val wallpaperManager by lazyMonitored {
WallpaperManager(
settings,
WallpapersAssetsStorage(context),
WallpaperDownloader(context, core.client, analytics.crashReporter),
analytics.crashReporter,
)
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/org/mozilla/fenix/wallpapers/Wallpaper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.mozilla.fenix.wallpapers

import android.content.Context
import android.content.res.Configuration
import org.mozilla.fenix.R

/**
* A class that represents an available wallpaper and its state.
Expand All @@ -17,9 +18,6 @@ import android.content.res.Configuration
*/
data class Wallpaper(
val name: String,
val portraitPath: String,
val landscapePath: String,
val isDark: Boolean,
val themeCollection: WallpaperThemeCollection,
)

Expand Down Expand Up @@ -51,6 +49,13 @@ enum class WallpaperOrigin {
REMOTE,
}

val Wallpaper.drawableId: Int get() = when (name) {
"amethyst" -> R.drawable.amethyst
"cerulean" -> R.drawable.cerulean
"sunrise" -> R.drawable.sunrise
else -> -1
}

/**
* Get the expected local path on disk for a wallpaper. This will differ depending
* on orientation and app theme.
Expand Down
47 changes: 14 additions & 33 deletions app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.mozilla.fenix.wallpapers
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable
Expand All @@ -30,21 +29,17 @@ import java.io.File
@Suppress("TooManyFunctions")
class WallpaperManager(
private val settings: Settings,
private val wallpaperStorage: WallpaperStorage,
private val downloader: WallpaperDownloader,
private val crashReporter: CrashReporter,
) {
val logger = Logger("WallpaperManager")
private val remoteWallpapers = listOf(
Wallpaper(
"focus",
portraitPath = "",
landscapePath = "",
isDark = false,
themeCollection = WallpaperThemeCollection.FOCUS
),
)
var availableWallpapers: List<Wallpaper> = loadWallpapers() + remoteWallpapers
var availableWallpapers: List<Wallpaper> = localWallpapers + remoteWallpapers
private set

var currentWallpaper: Wallpaper = getCurrentWallpaperFromSettings()
Expand Down Expand Up @@ -114,22 +109,18 @@ class WallpaperManager(
*/
fun loadSavedWallpaper(context: Context, wallpaper: Wallpaper): Bitmap? =
if (wallpaper.themeCollection.origin == WallpaperOrigin.LOCAL) {
loadWallpaperFromAssets(context, wallpaper)
loadWallpaperFromDrawables(context, wallpaper)
} else {
loadWallpaperFromDisk(context, wallpaper)
}

private fun loadWallpaperFromAssets(context: Context, wallpaper: Wallpaper): Bitmap? = Result.runCatching {
val path = if (isLandscape(context)) {
wallpaper.landscapePath
} else {
wallpaper.portraitPath
}
context.assets.open(path).use {
BitmapFactory.decodeStream(it)
}
private fun loadWallpaperFromDrawables(context: Context, wallpaper: Wallpaper): Bitmap? = Result.runCatching {
BitmapFactory.decodeResource(context.resources, wallpaper.drawableId)
}.getOrNull()

/**
* Load a wallpaper from app-specific storage.
*/
private fun loadWallpaperFromDisk(context: Context, wallpaper: Wallpaper): Bitmap? = Result.runCatching {
val path = wallpaper.getLocalPathFromContext(context)
runBlockingIncrement {
Expand All @@ -140,19 +131,6 @@ class WallpaperManager(
}
}.getOrNull()

private fun isLandscape(context: Context): Boolean {
return context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}

private fun loadWallpapers(): List<Wallpaper> {
val wallpapersFromStorage = wallpaperStorage.loadAll()
return if (wallpapersFromStorage.isNotEmpty()) {
listOf(defaultWallpaper) + wallpapersFromStorage
} else {
listOf(defaultWallpaper)
}
}

/**
* Animates the Firefox logo, if it hasn't been animated before, otherwise nothing will happen.
* After animating the first time, the [Settings.shouldAnimateFirefoxLogo] setting
Expand Down Expand Up @@ -189,12 +167,15 @@ class WallpaperManager(
companion object {
const val DEFAULT_RESOURCE = R.attr.homeBackground
val defaultWallpaper = Wallpaper(
name = "default_wallpaper",
portraitPath = "",
landscapePath = "",
isDark = false,
name = "default",
themeCollection = WallpaperThemeCollection.NONE
)
val localWallpapers = listOf(
defaultWallpaper,
Wallpaper("amethyst", themeCollection = WallpaperThemeCollection.FIREFOX),
Wallpaper("cerulean", themeCollection = WallpaperThemeCollection.FIREFOX),
Wallpaper("sunrise", themeCollection = WallpaperThemeCollection.FIREFOX),
)
private const val ANIMATION_DELAY_MS = 1500L
}
}
14 changes: 0 additions & 14 deletions app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperStorage.kt

This file was deleted.

This file was deleted.

Binary file added app/src/main/res/drawable-hdpi/amethyst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/cerulean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/sunrise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-land-hdpi/amethyst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-land-hdpi/cerulean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-land-hdpi/sunrise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-land-xhdpi/sunrise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-port-xhdpi/sunrise.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import org.mozilla.fenix.utils.Settings
class WallpaperManagerTest {

private val mockSettings: Settings = mockk()
private val mockStorage: WallpaperStorage = mockk {
every { loadAll() } returns listOf()
}
private val mockMetrics: MetricController = mockk()

@Test
Expand All @@ -27,7 +24,7 @@ class WallpaperManagerTest {
every { mockSettings.currentWallpaper = capture(currentCaptureSlot) } just runs

val updatedWallpaper = WallpaperManager.defaultWallpaper
val wallpaperManager = WallpaperManager(mockSettings, mockStorage, mockk(), mockk())
val wallpaperManager = WallpaperManager(mockSettings, mockk(), mockk())
wallpaperManager.currentWallpaper = updatedWallpaper

assertEquals(updatedWallpaper.name, currentCaptureSlot.captured)
Expand Down

0 comments on commit 0837197

Please sign in to comment.