fix: Synchronise theme map + icon state update (#7330)
This commit is contained in:
1 parent
ae92541803
commit
fa6bc6796f
2 files changed
+31
-25
No files matched your search
@@ -69,25 +69,25 @@ class LawnchairIconProvider @Inject constructor(
|
||||
private val themedIconSource
|
||||
get() = iconPackProvider.getIconPack(themedIconSourcePref.get())?.apply { loadBlocking() }
|
||||
|
||||
private val themeMapLock = Any()
|
||||
private var themeMapName: String = ""
|
||||
private var themeMapEnabled: Boolean? = null
|
||||
private var _themeMap: Map<String, ThemeData>? = null
|
||||
|
||||
val themeMap: Map<String, ThemeData>
|
||||
get() {
|
||||
if (!themedIconsEnabled) {
|
||||
_themeMap = DISABLED_MAP
|
||||
get() = synchronized(themeMapLock) {
|
||||
val sourceName = themedIconSource?.packPackageName.orEmpty()
|
||||
val enabled = themedIconsEnabled
|
||||
if (
|
||||
_themeMap == null ||
|
||||
themeMapName != sourceName ||
|
||||
themeMapEnabled != enabled
|
||||
) {
|
||||
themeMapName = sourceName
|
||||
themeMapEnabled = enabled
|
||||
_themeMap = if (enabled) getThemedIconMap() else DISABLED_MAP
|
||||
}
|
||||
if (_themeMap == null) {
|
||||
_themeMap = getThemedIconMap()
|
||||
}
|
||||
if (themedIconSource != null && themeMapName == "") {
|
||||
_themeMap = super.getThemedIconMap()
|
||||
}
|
||||
if (themedIconSource != null && themeMapName != themedIconSource!!.packPackageName) {
|
||||
themeMapName = themedIconSource!!.packPackageName
|
||||
_themeMap = getThemedIconMap()
|
||||
}
|
||||
return _themeMap!!
|
||||
_themeMap!!
|
||||
}
|
||||
|
||||
val systemIconState = themeManager.iconState
|
||||
@@ -315,19 +315,18 @@ class LawnchairIconProvider @Inject constructor(
|
||||
private val themedIconPackPref = PreferenceManager.getInstance(context).themedIconPackPackage
|
||||
|
||||
private val subscription = iconPackPref.subscribeChanges {
|
||||
val newState = themeManager.iconState
|
||||
if (iconState != newState) {
|
||||
iconState = newState
|
||||
updateSystemState()
|
||||
recreateCalendarAndClockChangeReceiver()
|
||||
}
|
||||
updateIconStateIfNeeded()
|
||||
recreateCalendarAndClockChangeReceiver()
|
||||
}
|
||||
private val themedIconSubscription = themedIconPackPref.subscribeChanges {
|
||||
updateIconStateIfNeeded()
|
||||
}
|
||||
|
||||
private fun updateIconStateIfNeeded() {
|
||||
val newState = themeManager.iconState
|
||||
if (iconState != newState) {
|
||||
iconState = newState
|
||||
updateSystemState()
|
||||
recreateCalendarAndClockChangeReceiver()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,11 +405,14 @@ class LawnchairIconProvider @Inject constructor(
|
||||
filter.addAction(ACTION_PACKAGE_CHANGED)
|
||||
filter.addAction(ACTION_PACKAGE_REMOVED)
|
||||
filter.addDataScheme("package")
|
||||
filter.addDataSchemeSpecificPart(themeMapName, 0)
|
||||
context.registerReceiver(this, filter, null, handler)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.data?.schemeSpecificPart != themedIconSourcePref.get()) return
|
||||
synchronized(themeMapLock) {
|
||||
_themeMap = null
|
||||
}
|
||||
updateSystemState()
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.dagger.LauncherAppComponent
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
import com.android.launcher3.graphics.ThemeManager
|
||||
import com.android.launcher3.icons.LauncherIcons
|
||||
import com.android.launcher3.model.DeviceGridState
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
import com.android.launcher3.util.DaggerSingletonObject
|
||||
@@ -50,11 +50,15 @@ class PreferenceManager @Inject constructor(
|
||||
private val idp get() = InvariantDeviceProfile.INSTANCE.get(context)
|
||||
private val dc get() = DisplayController.INSTANCE.get(context)
|
||||
private val mRecentsModel get() = RecentsModel.INSTANCE.get(context)
|
||||
private val las get() = LauncherAppState.INSTANCE.get(context)
|
||||
private val reloadIcons: () -> Unit = {
|
||||
mRecentsModel.onThemeChanged()
|
||||
Executors.MODEL_EXECUTOR.execute {
|
||||
LauncherAppState.INSTANCE.get(context).iconCache.clearMemoryCache()
|
||||
LauncherAppState.INSTANCE.get(context).model.reloadIfActive()
|
||||
// All of this is like refreshAndReloadLauncher in ModelInitializer
|
||||
LauncherIcons.clearPool(context)
|
||||
las.iconCache.clearMemoryCache()
|
||||
las.iconCache.updateIconParams(idp.fillResIconDpi, idp.iconBitmapSize)
|
||||
las.model.forceReload()
|
||||
}
|
||||
}
|
||||
private val reloadGrid: () -> Unit = { idp.onPreferencesChanged(context) }
|
||||
|
||||
Reference in new issue
Block a user