2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/27095 - Download light/dark wallpaper card colors

This commit is contained in:
Noah Bond 2022-10-07 10:22:10 -07:00 committed by mergify[bot]
parent b4f1feb745
commit f53d77e071
14 changed files with 81 additions and 54 deletions

View File

@ -200,14 +200,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = 0, default = 0,
) )
/**
* A cache of the background color to use on cards overlaying the current wallpaper.
*/
var currentWallpaperCardColor by longPreference(
appContext.getPreferenceKey(R.string.pref_key_current_wallpaper_card_color),
default = 0,
)
/** /**
* Indicates if the current legacy wallpaper should be migrated. * Indicates if the current legacy wallpaper should be migrated.
*/ */

View File

@ -37,7 +37,8 @@ class LegacyWallpaperFileManager(
name = name, name = name,
collection = Wallpaper.DefaultCollection, collection = Wallpaper.DefaultCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
) )

View File

@ -14,13 +14,17 @@ import java.util.Date
* @property collection The name of the collection the wallpaper belongs to. * @property collection The name of the collection the wallpaper belongs to.
* is not restricted. * is not restricted.
* @property textColor The 8 digit hex code color that should be used for text overlaying the wallpaper. * @property textColor The 8 digit hex code color that should be used for text overlaying the wallpaper.
* @property cardColor The 8 digit hex code color that should be used for cards overlaying the wallpaper. * @property cardColorLight The 8 digit hex code color that should be used for cards overlaying the wallpaper
* when the user's theme is set to Light.
* @property cardColorDark The 8 digit hex code color that should be used for cards overlaying the wallpaper
* when the user's theme is set to Dark.
*/ */
data class Wallpaper( data class Wallpaper(
val name: String, val name: String,
val collection: Collection, val collection: Collection,
val textColor: Long?, val textColor: Long?,
val cardColor: Long?, val cardColorLight: Long?,
val cardColorDark: Long?,
val thumbnailFileState: ImageFileState, val thumbnailFileState: ImageFileState,
val assetsFileState: ImageFileState, val assetsFileState: ImageFileState,
) { ) {
@ -84,7 +88,8 @@ data class Wallpaper(
name = defaultName, name = defaultName,
collection = DefaultCollection, collection = DefaultCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = ImageFileState.Downloaded, thumbnailFileState = ImageFileState.Downloaded,
assetsFileState = ImageFileState.Downloaded, assetsFileState = ImageFileState.Downloaded,
) )
@ -115,12 +120,12 @@ data class Wallpaper(
fun getCurrentWallpaperFromSettings(settings: Settings): Wallpaper? { fun getCurrentWallpaperFromSettings(settings: Settings): Wallpaper? {
val name = settings.currentWallpaperName val name = settings.currentWallpaperName
val textColor = settings.currentWallpaperTextColor val textColor = settings.currentWallpaperTextColor
val cardColor = settings.currentWallpaperCardColor return if (name.isNotEmpty() && textColor != 0L) {
return if (name.isNotEmpty() && textColor != 0L && cardColor != 0L) {
Wallpaper( Wallpaper(
name = name, name = name,
textColor = textColor, textColor = textColor,
cardColor = cardColor, cardColorLight = null,
cardColorDark = null,
collection = DefaultCollection, collection = DefaultCollection,
thumbnailFileState = ImageFileState.Downloaded, thumbnailFileState = ImageFileState.Downloaded,
assetsFileState = ImageFileState.Downloaded, assetsFileState = ImageFileState.Downloaded,

View File

@ -36,7 +36,8 @@ class WallpaperFileManager(
name = name, name = name,
collection = Wallpaper.DefaultCollection, collection = Wallpaper.DefaultCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Downloaded, thumbnailFileState = Wallpaper.ImageFileState.Downloaded,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
) )

View File

@ -81,7 +81,8 @@ class WallpaperMetadataFetcher(
Wallpaper( Wallpaper(
name = getString("id"), name = getString("id"),
textColor = getArgbValueAsLong("text-color"), textColor = getArgbValueAsLong("text-color"),
cardColor = getArgbValueAsLong("card-color"), cardColorLight = getArgbValueAsLong("card-color-light"),
cardColorDark = getArgbValueAsLong("card-color-dark"),
collection = collection, collection = collection,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Unavailable, assetsFileState = Wallpaper.ImageFileState.Unavailable,

View File

@ -185,7 +185,8 @@ class WallpapersUseCases(
name = Wallpaper.amethystName, name = Wallpaper.amethystName,
collection = firefoxClassicCollection, collection = firefoxClassicCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
), ),
@ -193,7 +194,8 @@ class WallpapersUseCases(
name = Wallpaper.ceruleanName, name = Wallpaper.ceruleanName,
collection = firefoxClassicCollection, collection = firefoxClassicCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
), ),
@ -201,7 +203,8 @@ class WallpapersUseCases(
name = Wallpaper.sunriseName, name = Wallpaper.sunriseName,
collection = firefoxClassicCollection, collection = firefoxClassicCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
), ),
@ -211,7 +214,8 @@ class WallpapersUseCases(
name = Wallpaper.twilightHillsName, name = Wallpaper.twilightHillsName,
collection = firefoxClassicCollection, collection = firefoxClassicCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
), ),
@ -219,7 +223,8 @@ class WallpapersUseCases(
name = Wallpaper.beachVibeName, name = Wallpaper.beachVibeName,
collection = firefoxClassicCollection, collection = firefoxClassicCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
), ),
@ -454,7 +459,6 @@ class WallpapersUseCases(
override suspend fun invoke(wallpaper: Wallpaper): Wallpaper.ImageFileState { override suspend fun invoke(wallpaper: Wallpaper): Wallpaper.ImageFileState {
settings.currentWallpaperName = wallpaper.name settings.currentWallpaperName = wallpaper.name
settings.currentWallpaperTextColor = wallpaper.textColor ?: 0 settings.currentWallpaperTextColor = wallpaper.textColor ?: 0
settings.currentWallpaperCardColor = wallpaper.cardColor ?: 0
store.dispatch(AppAction.WallpaperAction.UpdateCurrentWallpaper(wallpaper)) store.dispatch(AppAction.WallpaperAction.UpdateCurrentWallpaper(wallpaper))
return Wallpaper.ImageFileState.Downloaded return Wallpaper.ImageFileState.Downloaded
} }

View File

@ -205,7 +205,6 @@
<string name="pref_key_wallpapers" translatable="false">pref_key_wallpapers</string> <string name="pref_key_wallpapers" translatable="false">pref_key_wallpapers</string>
<string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string> <string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string>
<string name="pref_key_current_wallpaper_text_color" translatable="false">pref_key_current_wallpaper_text_color</string> <string name="pref_key_current_wallpaper_text_color" translatable="false">pref_key_current_wallpaper_text_color</string>
<string name="pref_key_current_wallpaper_card_color" translatable="false">pref_key_current_wallpaper_card_color</string>
<string name="pref_key_wallpapers_onboarding" translatable="false">pref_key_wallpapers_onboarding</string> <string name="pref_key_wallpapers_onboarding" translatable="false">pref_key_wallpapers_onboarding</string>
<string name="pref_key_should_migrate_wallpaper" translatable="false">pref_key_should_migrate_wallpaper</string> <string name="pref_key_should_migrate_wallpaper" translatable="false">pref_key_should_migrate_wallpaper</string>

View File

@ -1357,7 +1357,8 @@ class DefaultSessionControlControllerTest {
learnMoreUrl = null, learnMoreUrl = null,
), ),
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = thumbnailFileState, thumbnailFileState = thumbnailFileState,
assetsFileState = Wallpaper.ImageFileState.Unavailable, assetsFileState = Wallpaper.ImageFileState.Unavailable,
) )

View File

@ -172,7 +172,8 @@ class ExtensionsTest {
private fun generateClassicFirefoxWallpaper(name: String) = Wallpaper( private fun generateClassicFirefoxWallpaper(name: String) = Wallpaper(
name = name, name = name,
textColor = 0L, textColor = 0L,
cardColor = 0L, cardColorLight = 0L,
cardColorDark = 0L,
thumbnailFileState = Wallpaper.ImageFileState.Downloaded, thumbnailFileState = Wallpaper.ImageFileState.Downloaded,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
collection = classicCollection, collection = classicCollection,
@ -195,7 +196,8 @@ class ExtensionsTest {
) = Wallpaper( ) = Wallpaper(
name = wallpaperName, name = wallpaperName,
textColor = 0L, textColor = 0L,
cardColor = 0L, cardColorLight = 0L,
cardColorDark = 0L,
thumbnailFileState = thumbnailState, thumbnailFileState = thumbnailState,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
collection = getSeasonalCollection(collectionName), collection = getSeasonalCollection(collectionName),

View File

@ -97,7 +97,8 @@ class LegacyWallpaperFileManagerTest {
private fun generateWallpaper(name: String) = Wallpaper( private fun generateWallpaper(name: String) = Wallpaper(
name = name, name = name,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
collection = Wallpaper.Collection( collection = Wallpaper.Collection(

View File

@ -128,7 +128,8 @@ class WallpaperDownloaderTest {
name = name, name = name,
collection = wallpaperCollection, collection = wallpaperCollection,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Unavailable, assetsFileState = Wallpaper.ImageFileState.Unavailable,
) )

View File

@ -154,7 +154,8 @@ class WallpaperFileManagerTest {
private fun generateWallpaper(name: String) = Wallpaper( private fun generateWallpaper(name: String) = Wallpaper(
name = name, name = name,
textColor = null, textColor = null,
cardColor = null, cardColorLight = null,
cardColorDark = null,
thumbnailFileState = Wallpaper.ImageFileState.Downloaded, thumbnailFileState = Wallpaper.ImageFileState.Downloaded,
assetsFileState = Wallpaper.ImageFileState.Downloaded, assetsFileState = Wallpaper.ImageFileState.Downloaded,
collection = Wallpaper.DefaultCollection, collection = Wallpaper.DefaultCollection,

View File

@ -52,12 +52,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -70,11 +72,13 @@ class WallpaperMetadataFetcherTest {
with(wallpapers[0]) { with(wallpapers[0]) {
assertEquals(0xFFFBFBFE, textColor) assertEquals(0xFFFBFBFE, textColor)
assertEquals(0xFF15141A, cardColor) assertEquals(0xFFFFFFFF, cardColorLight)
assertEquals(0xFF000000, cardColorDark)
} }
with(wallpapers[1]) { with(wallpapers[1]) {
assertEquals(0xFF15141A, textColor) assertEquals(0xFF15141A, textColor)
assertEquals(0xFFFBFBFE, cardColor) assertEquals(0xFFFFFFFF, cardColorLight)
assertEquals(0xFF000000, cardColorDark)
} }
} }
@ -91,12 +95,14 @@ class WallpaperMetadataFetcherTest {
"wallpapers": [ "wallpapers": [
{ {
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -123,12 +129,14 @@ class WallpaperMetadataFetcherTest {
"wallpapers": [ "wallpapers": [
{ {
"id": "beach-vibes", "id": "beach-vibes",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -160,7 +168,8 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -189,12 +198,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -239,12 +250,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -280,12 +293,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -323,12 +338,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }
@ -364,12 +381,14 @@ class WallpaperMetadataFetcherTest {
{ {
"id": "beach-vibes", "id": "beach-vibes",
"text-color": "FBFBFE", "text-color": "FBFBFE",
"card-color": "15141A" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
}, },
{ {
"id": "sunrise", "id": "sunrise",
"text-color": "15141A", "text-color": "15141A",
"card-color": "FBFBFE" "card-color-light": "FFFFFF",
"card-color-dark": "000000"
} }
] ]
} }

View File

@ -41,8 +41,6 @@ class WallpapersUseCasesTest {
private val mockSettings = mockk<Settings> { private val mockSettings = mockk<Settings> {
every { currentWallpaperTextColor } returns 0L every { currentWallpaperTextColor } returns 0L
every { currentWallpaperTextColor = any() } just Runs every { currentWallpaperTextColor = any() } just Runs
every { currentWallpaperCardColor } returns 0L
every { currentWallpaperCardColor = any() } just Runs
every { shouldMigrateLegacyWallpaper } returns false every { shouldMigrateLegacyWallpaper } returns false
every { shouldMigrateLegacyWallpaper = any() } just Runs every { shouldMigrateLegacyWallpaper = any() } just Runs
} }
@ -525,7 +523,6 @@ class WallpapersUseCasesTest {
verify { mockSettings.currentWallpaperName = selectedWallpaper.name } verify { mockSettings.currentWallpaperName = selectedWallpaper.name }
verify { mockSettings.currentWallpaperTextColor = selectedWallpaper.textColor!! } verify { mockSettings.currentWallpaperTextColor = selectedWallpaper.textColor!! }
verify { mockSettings.currentWallpaperCardColor = selectedWallpaper.cardColor!! }
assertEquals(selectedWallpaper, appStore.state.wallpaperState.currentWallpaper) assertEquals(selectedWallpaper, appStore.state.wallpaperState.currentWallpaper)
assertEquals(wallpaperFileState, Wallpaper.ImageFileState.Downloaded) assertEquals(wallpaperFileState, Wallpaper.ImageFileState.Downloaded)
} }
@ -677,7 +674,8 @@ class WallpapersUseCasesTest {
learnMoreUrl = null, learnMoreUrl = null,
), ),
textColor = Random.nextLong(), textColor = Random.nextLong(),
cardColor = Random.nextLong(), cardColorLight = Random.nextLong(),
cardColorDark = Random.nextLong(),
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Unavailable, assetsFileState = Wallpaper.ImageFileState.Unavailable,
) )
@ -694,7 +692,8 @@ class WallpapersUseCasesTest {
learnMoreUrl = null, learnMoreUrl = null,
), ),
textColor = Random.nextLong(), textColor = Random.nextLong(),
cardColor = Random.nextLong(), cardColorLight = Random.nextLong(),
cardColorDark = Random.nextLong(),
thumbnailFileState = Wallpaper.ImageFileState.Unavailable, thumbnailFileState = Wallpaper.ImageFileState.Unavailable,
assetsFileState = Wallpaper.ImageFileState.Unavailable, assetsFileState = Wallpaper.ImageFileState.Unavailable,
) )