For #22851 toggle wallpapers when tap on the Firefox logo

upstream-sync
Arturo Mejia 2 years ago committed by mergify[bot]
parent 073fd89390
commit 7a44412619

@ -105,5 +105,5 @@ object FeatureFlags {
/**
* Enables showing the wallpaper functionality.
*/
const val showWallpapers = false
val showWallpapers = Config.channel.isNightlyOrDebug
}

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

@ -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() {

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

@ -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);
}

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

@ -186,6 +186,9 @@
<string name="pref_key_adjust_adgroup" translatable="false">pref_key_adjust_adgroup</string>
<string name="pref_key_adjust_creative" translatable="false">pref_key_adjust_creative</string>
<!-- Wallpaper Settings -->
<string name="pref_key_current_wallpaper" translatable="false">pref_key_current_wallpaper</string>
<string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string>
<!-- Top Sites -->

Loading…
Cancel
Save