2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-07 15:20:38 +00:00

For #25538 - Add a simple way to check if the default wallpaper is to be shown

A previous check for whether the persisted name of the current wallpaper is
empty made checking whether the default wallpaper is to be shown brittle.
Instead of duplicating such a check in multiple places it is now extracted in
one method that can be used in multiple places including the new telemetry.
This commit is contained in:
Mugurell 2022-06-06 12:39:16 +03:00 committed by mergify[bot]
parent 8ba7b8bddc
commit 8d9ccd76e9
2 changed files with 36 additions and 2 deletions

View File

@ -115,10 +115,10 @@ class WallpaperManager(
}
private fun getCurrentWallpaperFromSettings(): Wallpaper {
val currentWallpaper = settings.currentWallpaper
return if (currentWallpaper.isEmpty()) {
return if (isDefaultTheCurrentWallpaper(settings)) {
defaultWallpaper
} else {
val currentWallpaper = settings.currentWallpaper
wallpapers.find { it.name == currentWallpaper }
?: fileManager.lookupExpiredWallpaper(currentWallpaper)
?: defaultWallpaper
@ -240,6 +240,13 @@ class WallpaperManager(
}
companion object {
/**
* Get whether the default wallpaper should be used.
*/
fun isDefaultTheCurrentWallpaper(settings: Settings): Boolean = with(settings.currentWallpaper) {
return isEmpty() || equals(defaultWallpaper.name)
}
val defaultWallpaper = Wallpaper.Default
private val localWallpapers: List<Wallpaper.Local> = listOf(
Wallpaper.Local.Firefox("amethyst", R.drawable.amethyst),

View File

@ -166,6 +166,33 @@ class WallpaperManagerTest {
assertEquals(expected, wallpaperManager.currentWallpaper)
}
@Test
fun `GIVEN no custom wallpaper set WHEN checking whether the current wallpaper should be default THEN return true`() {
every { mockSettings.currentWallpaper } returns ""
val result = WallpaperManager.isDefaultTheCurrentWallpaper(mockSettings)
assertTrue(result)
}
@Test
fun `GIVEN the default wallpaper is set to be shown WHEN checking whether the current wallpaper should be default THEN return true`() {
every { mockSettings.currentWallpaper } returns WallpaperManager.defaultWallpaper.name
val result = WallpaperManager.isDefaultTheCurrentWallpaper(mockSettings)
assertTrue(result)
}
@Test
fun `GIVEN a custom wallpaper is set to be shown WHEN checking whether the current wallpaper should be default THEN return false`() {
every { mockSettings.currentWallpaper } returns "test"
val result = WallpaperManager.isDefaultTheCurrentWallpaper(mockSettings)
assertFalse(result)
}
private enum class TimeRelation {
BEFORE,
NOW,