diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
index 427f5de93d..7f02df8673 100644
--- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
+++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt
@@ -105,5 +105,5 @@ object FeatureFlags {
/**
* Enables showing the wallpaper functionality.
*/
- const val showWallpapers = false
+ val showWallpapers = Config.channel.isNightlyOrDebug
}
diff --git a/app/src/main/java/org/mozilla/fenix/components/Components.kt b/app/src/main/java/org/mozilla/fenix/components/Components.kt
index 51327822e5..5a48230e10 100644
--- a/app/src/main/java/org/mozilla/fenix/components/Components.kt
+++ b/app/src/main/java/org/mozilla/fenix/components/Components.kt
@@ -36,6 +36,7 @@ import org.mozilla.fenix.perf.StrictModeManager
import org.mozilla.fenix.perf.lazyMonitored
import org.mozilla.fenix.utils.ClipboardHandler
import org.mozilla.fenix.utils.Settings
+import org.mozilla.fenix.wallpapers.WallpaperManager
import org.mozilla.fenix.wifi.WifiConnectionMonitor
import java.util.concurrent.TimeUnit
@@ -142,6 +143,10 @@ class Components(private val context: Context) {
AddonManager(core.store, core.engine, addonCollectionProvider, addonUpdater)
}
+ val wallpaperManager by lazyMonitored {
+ WallpaperManager(settings)
+ }
+
val analytics by lazyMonitored { Analytics(context) }
val publicSuffixList by lazyMonitored { PublicSuffixList(context) }
val clipboardHandler by lazyMonitored { ClipboardHandler(context) }
diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
index f7b202dd40..4d2226d78c 100644
--- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
+++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
@@ -394,6 +394,12 @@ class HomeFragment : Fragment() {
requireComponents.core.engine.profiler?.addMarker(
MarkersFragmentLifecycleCallbacks.MARKER_NAME, profilerStartTime, "HomeFragment.onCreateView",
)
+
+ if (FeatureFlags.showWallpapers) {
+ val wallpaperManger = requireComponents.wallpaperManager
+ wallpaperManger.updateWallpaper(binding.homeLayout, wallpaperManger.currentWallpaper)
+ }
+
return binding.root
}
@@ -751,6 +757,16 @@ class HomeFragment : Fragment() {
lifecycleScope.launch(IO) {
requireComponents.reviewPromptController.promptReview(requireActivity())
}
+
+ if (FeatureFlags.showWallpapers) {
+ binding.wordmark.setOnClickListener {
+ val manager = requireComponents.wallpaperManager
+ manager.updateWallpaper(
+ wallpaperContainer = binding.homeLayout,
+ newWallpaper = manager.switchToNextWallpaper()
+ )
+ }
+ }
}
private fun navToSavedLogins() {
diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
index bb25ef6415..a2cb60fb7e 100644
--- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
+++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt
@@ -40,6 +40,7 @@ import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.withExperiment
import org.mozilla.fenix.settings.PhoneFeature
+import org.mozilla.fenix.wallpapers.Wallpaper
import org.mozilla.fenix.settings.deletebrowsingdata.DeleteBrowsingDataOnQuitType
import org.mozilla.fenix.settings.logins.SavedLoginsSortingStrategyMenu
import org.mozilla.fenix.settings.logins.SortingStrategy
@@ -158,6 +159,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = ""
)
+ var currentWallpaper by stringPreference(
+ appContext.getPreferenceKey(R.string.pref_key_current_wallpaper),
+ default = Wallpaper.NONE.name
+ )
+
var openLinksInAPrivateTab by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab),
default = false
diff --git a/app/src/main/java/org/mozilla/fenix/wallpapers/Wallpaper.kt b/app/src/main/java/org/mozilla/fenix/wallpapers/Wallpaper.kt
new file mode 100644
index 0000000000..08a131aaee
--- /dev/null
+++ b/app/src/main/java/org/mozilla/fenix/wallpapers/Wallpaper.kt
@@ -0,0 +1,16 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.fenix.wallpapers
+
+import org.mozilla.fenix.R
+
+/**
+ * A enum that represents the available wallpapers and their states.
+ */
+enum class Wallpaper(val drawable: Int) {
+ FIRST(R.drawable.wallpaper_1),
+ SECOND(R.drawable.wallpaper_2),
+ NONE(R.attr.homeBackground);
+}
diff --git a/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt b/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt
new file mode 100644
index 0000000000..d4c124cc75
--- /dev/null
+++ b/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.fenix.wallpapers
+
+import android.view.View
+import mozilla.components.support.ktx.android.content.getColorFromAttr
+import org.mozilla.fenix.utils.Settings
+
+/**
+ * Provides access to available wallpapers and manages their states.
+ */
+class WallpaperManager(private val settings: Settings) {
+
+ var currentWallpaper: Wallpaper = getCurrentWallpaperFromSettings()
+ set(value) {
+ settings.currentWallpaper = value.name
+ field = value
+ }
+
+ /**
+ * Apply the [newWallpaper] into the [wallpaperContainer] and update the [currentWallpaper].
+ */
+ fun updateWallpaper(wallpaperContainer: View, newWallpaper: Wallpaper) {
+ if (newWallpaper == Wallpaper.NONE) {
+ val context = wallpaperContainer.context
+ wallpaperContainer.setBackgroundColor(context.getColorFromAttr(newWallpaper.drawable))
+ } else {
+ wallpaperContainer.setBackgroundResource(newWallpaper.drawable)
+ }
+ currentWallpaper = newWallpaper
+ }
+
+ /**
+ * Returns the next available [Wallpaper], the [currentWallpaper] is the last one then
+ * the first available [Wallpaper] will be returned.
+ */
+ fun switchToNextWallpaper(): Wallpaper {
+ val values = Wallpaper.values()
+ val index = values.indexOf(currentWallpaper) + 1
+
+ return if (index >= values.size) {
+ values.first()
+ } else {
+ values[index]
+ }
+ }
+
+ private fun getCurrentWallpaperFromSettings(): Wallpaper {
+ val currentWallpaper = settings.currentWallpaper
+ return if (currentWallpaper.isEmpty()) {
+ Wallpaper.NONE
+ } else {
+ Wallpaper.valueOf(currentWallpaper)
+ }
+ }
+}
diff --git a/app/src/main/res/drawable/wallpaper_1.png b/app/src/main/res/drawable/wallpaper_1.png
new file mode 100644
index 0000000000..e62b6ca4db
Binary files /dev/null and b/app/src/main/res/drawable/wallpaper_1.png differ
diff --git a/app/src/main/res/drawable/wallpaper_2.png b/app/src/main/res/drawable/wallpaper_2.png
new file mode 100644
index 0000000000..7141777bd1
Binary files /dev/null and b/app/src/main/res/drawable/wallpaper_2.png differ
diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml
index 76a5432180..9a30b4731f 100644
--- a/app/src/main/res/values/preference_keys.xml
+++ b/app/src/main/res/values/preference_keys.xml
@@ -186,6 +186,9 @@
pref_key_adjust_adgroup
pref_key_adjust_creative
+
+ pref_key_current_wallpaper
+
pref_key_encryption_key_generated