From 2bba66fb58552e27d6747c1c032b5771bb492952 Mon Sep 17 00:00:00 2001 From: Arturo Mejia Date: Thu, 13 Jan 2022 09:36:44 -0500 Subject: [PATCH] For #23144 Address regression in COLD start --- .../java/org/mozilla/fenix/home/HomeFragment.kt | 15 ++++++++++----- .../mozilla/fenix/wallpapers/WallpaperManager.kt | 8 +++++++- 2 files changed, 17 insertions(+), 6 deletions(-) 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 7e9195e2ae..4cb647cb82 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -126,6 +126,7 @@ import org.mozilla.fenix.settings.deletebrowsingdata.deleteAndQuit import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.ToolbarPopupWindow import org.mozilla.fenix.utils.allowUndo +import org.mozilla.fenix.wallpapers.Wallpaper import org.mozilla.fenix.whatsnew.WhatsNew import java.lang.ref.WeakReference import kotlin.math.min @@ -390,16 +391,20 @@ class HomeFragment : Fragment() { requireContext().components.analytics.experiments.recordExposureEvent(FeatureId.HOME_PAGE) + if (shouldEnableWallpaper()) { + val wallpaperManger = requireComponents.wallpaperManager + // We only want to update the wallpaper when it's different from the default one + // as the default is applied already on xml by default. + if (wallpaperManger.currentWallpaper != Wallpaper.NONE) { + wallpaperManger.updateWallpaper(binding.homeLayout, wallpaperManger.currentWallpaper) + } + } + // DO NOT MOVE ANYTHING BELOW THIS addMarker CALL! requireComponents.core.engine.profiler?.addMarker( MarkersFragmentLifecycleCallbacks.MARKER_NAME, profilerStartTime, "HomeFragment.onCreateView", ) - if (shouldEnableWallpaper()) { - val wallpaperManger = requireComponents.wallpaperManager - wallpaperManger.updateWallpaper(binding.homeLayout, wallpaperManger.currentWallpaper) - } - return binding.root } diff --git a/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt b/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt index a8db0c5919..1192cbe595 100644 --- a/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt +++ b/app/src/main/java/org/mozilla/fenix/wallpapers/WallpaperManager.kt @@ -7,6 +7,7 @@ package org.mozilla.fenix.wallpapers import android.content.Context import android.view.View import androidx.appcompat.app.AppCompatDelegate +import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.ext.asActivity import org.mozilla.fenix.utils.Settings @@ -15,7 +16,7 @@ import org.mozilla.fenix.utils.Settings * Provides access to available wallpapers and manages their states. */ class WallpaperManager(private val settings: Settings) { - + val logger = Logger("WallpaperManager") var currentWallpaper: Wallpaper = getCurrentWallpaperFromSettings() set(value) { settings.currentWallpaper = value.name @@ -29,7 +30,9 @@ class WallpaperManager(private val settings: Settings) { if (newWallpaper == Wallpaper.NONE) { val context = wallpaperContainer.context wallpaperContainer.setBackgroundColor(context.getColorFromAttr(newWallpaper.drawable)) + logger.info("Wallpaper update to default background") } else { + logger.info("Wallpaper update to ${newWallpaper.name}") wallpaperContainer.setBackgroundResource(newWallpaper.drawable) } currentWallpaper = newWallpaper @@ -41,8 +44,10 @@ class WallpaperManager(private val settings: Settings) { val mode = if (currentWallpaper != Wallpaper.NONE) { if (currentWallpaper.isDark) { updateThemePreference(useDarkTheme = true) + logger.info("theme changed to useDarkTheme") AppCompatDelegate.MODE_NIGHT_YES } else { + logger.info("theme changed to useLightTheme") updateThemePreference(useLightTheme = true) AppCompatDelegate.MODE_NIGHT_NO } @@ -55,6 +60,7 @@ class WallpaperManager(private val settings: Settings) { if (AppCompatDelegate.getDefaultNightMode() != mode) { AppCompatDelegate.setDefaultNightMode(mode) + logger.info("theme updated activity recreated") context.asActivity()?.recreate() } }