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.
pull/543/head
Mugurell 2 years ago committed by mergify[bot]
parent 8ba7b8bddc
commit 8d9ccd76e9

@ -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),

@ -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,

Loading…
Cancel
Save