feat: Listen for prefs2 icon shapes in theme manager
Signed-off-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
@@ -39,6 +39,7 @@ Compatibility list:
|
||||
* [Launcher] Crash with `NameNotFoundException` when app is archived in Android 15/16.0
|
||||
* [Launcher] Null crash when trying to drop an icon on the home screen for some devices (fix: LawnchairLauncher/Lawnchair#6237)
|
||||
* [Launcher] Crash due to incorrect thread looper for accessing cache
|
||||
* [Launcher] Make icon shapes change instantaneous
|
||||
|
||||
### 🥞 Development 4 Release 1 (Snapshot 10)
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ import android.util.Log
|
||||
import app.lawnchair.icons.shape.IconShape
|
||||
import app.lawnchair.icons.shape.PathShapeDelegate
|
||||
import app.lawnchair.preferences2.PreferenceManager2
|
||||
import com.android.launcher3.EncryptionType
|
||||
import com.android.launcher3.LauncherPrefChangeListener
|
||||
import com.android.launcher3.LauncherPrefs
|
||||
import com.android.launcher3.LauncherPrefs.Companion.backedUpItem
|
||||
import com.android.launcher3.concurrent.annotations.Ui
|
||||
import com.android.launcher3.dagger.ApplicationContext
|
||||
import com.android.launcher3.dagger.LauncherAppSingleton
|
||||
@@ -14,6 +17,11 @@ import com.android.launcher3.util.DaggerSingletonTracker
|
||||
import com.android.launcher3.util.LooperExecutor
|
||||
import com.patrykmichalik.opto.core.firstBlocking
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
@LauncherAppSingleton
|
||||
class LawnchairThemeManager
|
||||
@@ -34,6 +42,31 @@ constructor(
|
||||
) {
|
||||
override var iconState = parseIconStateV2(null)
|
||||
|
||||
init {
|
||||
val scope = MainScope()
|
||||
merge(
|
||||
prefs2.iconShape.get(),
|
||||
prefs2.customIconShape.get()
|
||||
).onEach { verifyIconState() }
|
||||
.launchIn(scope)
|
||||
|
||||
// Listen for specific Lawnchair SharedPreferences it's easier than trying to make prefs1 work with listener
|
||||
val drawerThemedIcons = backedUpItem("drawer_themed_icons", false, EncryptionType.DEVICE_PROTECTED)
|
||||
val keys = listOf(drawerThemedIcons)
|
||||
val keysArray = keys.toTypedArray()
|
||||
val prefKeySet = keys.map { it.sharedPrefKey }
|
||||
|
||||
val prefListener = LauncherPrefChangeListener { key ->
|
||||
if (prefKeySet.contains(key)) verifyIconState()
|
||||
}
|
||||
prefs.addListener(prefListener, *keysArray)
|
||||
|
||||
lifecycle.addCloseable {
|
||||
prefs.removeListener(prefListener, *keysArray)
|
||||
scope.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
override fun verifyIconState() {
|
||||
val newState = parseIconStateV2(iconState)
|
||||
if (newState == iconState) return
|
||||
|
||||
Reference in New Issue
Block a user