2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/23144 Address regression in COLD start

This commit is contained in:
Arturo Mejia 2022-01-13 09:36:44 -05:00 committed by mergify[bot]
parent 50c17d7bea
commit dc560358e8
2 changed files with 17 additions and 6 deletions

View File

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

View File

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