diff --git a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt index aff9cc6af5..5b9bd6a753 100644 --- a/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt +++ b/lawnchair/src/app/lawnchair/DeviceProfileOverrides.kt @@ -3,7 +3,7 @@ package app.lawnchair import android.content.Context import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 -import app.lawnchair.preferences2.firstBlocking +import app.lawnchair.preferences2.firstCached import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.InvariantDeviceProfile.INDEX_DEFAULT import com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE @@ -14,7 +14,6 @@ import com.android.launcher3.dagger.LauncherAppComponent import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.DaggerSingletonObject import com.android.launcher3.util.SafeCloseable -import com.patrykmichalik.opto.core.firstBlocking import javax.inject.Inject @LauncherAppSingleton @@ -97,20 +96,20 @@ class DeviceProfileOverrides @Inject constructor( prefs2: PreferenceManager2, defaultGrid: InvariantDeviceProfile.GridOption, ) : this( - numAllAppsColumns = prefs2.drawerColumns.firstBlocking(gridOption = defaultGrid), + numAllAppsColumns = prefs2.drawerColumns.firstCached(gridOption = defaultGrid), numFolderRows = prefs.folderRows.get(defaultGrid), - numFolderColumns = prefs2.folderColumns.firstBlocking(gridOption = defaultGrid), + numFolderColumns = prefs2.folderColumns.firstCached(gridOption = defaultGrid), - iconSizeFactor = prefs2.homeIconSizeFactor.firstBlocking(), - allAppsIconSizeFactor = prefs2.drawerIconSizeFactor.firstBlocking(), + iconSizeFactor = prefs2.homeIconSizeFactor.firstCached(), + allAppsIconSizeFactor = prefs2.drawerIconSizeFactor.firstCached(), allAppsIconTextSizeFactor = - if (prefs2.showIconLabelsInDrawer.firstBlocking()) { - prefs2.drawerIconLabelSizeFactor.firstBlocking() + if (prefs2.showIconLabelsInDrawer.firstCached()) { + prefs2.drawerIconLabelSizeFactor.firstCached() } else { 0f }, - enableTaskbarOnPhone = prefs2.enableTaskbarOnPhone.firstBlocking(), + enableTaskbarOnPhone = prefs2.enableTaskbarOnPhone.firstCached(), ) fun applyUi(idp: InvariantDeviceProfile) { @@ -146,12 +145,12 @@ class DeviceProfileOverrides @Inject constructor( constructor( prefs2: PreferenceManager2, ) : this( - enableIconText = prefs2.showIconLabelsOnHomeScreen.firstBlocking(), - iconTextSizeFactor = prefs2.homeIconLabelSizeFactor.firstBlocking(), - enableIconTextFolder = prefs2.showIconLabelsOnHomeScreenFolder.firstBlocking(), - iconFolderTextSizeFactor = prefs2.homeIconLabelFolderSizeFactor.firstBlocking(), - enableAllAppsIconText = prefs2.showIconLabelsInDrawer.firstBlocking(), - allAppsIconTextSizeFactor = prefs2.drawerIconLabelSizeFactor.firstBlocking(), + enableIconText = prefs2.showIconLabelsOnHomeScreen.firstCached(), + iconTextSizeFactor = prefs2.homeIconLabelSizeFactor.firstCached(), + enableIconTextFolder = prefs2.showIconLabelsOnHomeScreenFolder.firstCached(), + iconFolderTextSizeFactor = prefs2.homeIconLabelFolderSizeFactor.firstCached(), + enableAllAppsIconText = prefs2.showIconLabelsInDrawer.firstCached(), + allAppsIconTextSizeFactor = prefs2.drawerIconLabelSizeFactor.firstCached(), ) constructor( diff --git a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt index f140fbc956..04b398b550 100644 --- a/lawnchair/src/app/lawnchair/LawnchairLauncher.kt +++ b/lawnchair/src/app/lawnchair/LawnchairLauncher.kt @@ -42,6 +42,7 @@ import app.lawnchair.gestures.ui.LawnchairShortcutActivity import app.lawnchair.nexuslauncher.OverlayCallbackImpl import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.root.RootHelperManager import app.lawnchair.root.RootNotAvailableException import app.lawnchair.theme.ThemeProvider @@ -81,7 +82,6 @@ import com.android.launcher3.widget.RoundedCornerEnforcement import com.android.systemui.plugins.shared.LauncherOverlayManager import com.android.systemui.shared.system.QuickStepContract import com.kieronquinn.app.smartspacer.sdk.client.SmartspacerClient -import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.onEach import dev.kdrag0n.monet.theme.ColorScheme import java.util.stream.Stream @@ -324,7 +324,7 @@ class LawnchairLauncher : QuickstepLauncher() { } override fun showDefaultOptions(x: Float, y: Float) { - val showWallpaperCarousel = "+carousel" in preferenceManager2.launcherPopupOrder.firstBlocking() + val showWallpaperCarousel = "+carousel" in preferenceManager2.launcherPopupOrder.firstCached() if (showWallpaperCarousel) { show( @@ -494,7 +494,7 @@ class LawnchairLauncher : QuickstepLauncher() { */ private fun reloadIconsIfNeeded() { if ( - preferenceManager2.alwaysReloadIcons.firstBlocking() + preferenceManager2.alwaysReloadIcons.firstCached() ) { LauncherAppState.getInstance(this).model.reloadIfActive() } diff --git a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt index 31b6395111..200cf34e68 100644 --- a/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt +++ b/lawnchair/src/app/lawnchair/allapps/AllAppsSearchInput.kt @@ -28,6 +28,7 @@ import androidx.lifecycle.lifecycleScope import app.lawnchair.launcher import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.preferences2.subscribeBlocking import app.lawnchair.qsb.AssistantIconView import app.lawnchair.qsb.LawnQsbLayout.Companion.getLensIntent @@ -54,7 +55,6 @@ import com.android.launcher3.allapps.search.AllAppsSearchBarController import com.android.launcher3.search.SearchCallback import com.android.launcher3.util.Themes import com.android.systemui.shared.system.BlurUtils -import com.patrykmichalik.opto.core.firstBlocking import java.util.Locale import kotlin.math.max import kotlinx.coroutines.launch @@ -127,7 +127,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : micIcon = ViewCompat.requireViewById(this, R.id.mic_btn) lensIcon = ViewCompat.requireViewById(this, R.id.lens_btn) - val shouldShowIcons = prefs2.matchHotseatQsbStyle.firstBlocking() + val shouldShowIcons = prefs2.matchHotseatQsbStyle.firstCached() val searchProvider = getSearchProvider(context, prefs2) val isGoogle = searchProvider == Google || searchProvider == GoogleGo || searchProvider == PixelSearch @@ -149,7 +149,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : } } - prefs2.themedHotseatQsb.subscribeBlocking(scope = viewAttachedScope) { themed -> + prefs2.themedHotseatQsb.subscribeBlocking(prefs2 = prefs2, scope = viewAttachedScope) { themed -> with(searchIcon) { isVisible = true @@ -190,7 +190,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : val currentPaddingRight = initialPaddingRight input.onFocusChangeListener = OnFocusChangeListener { _, hasFocus -> if (hasFocus) { - if (prefs2.searchAlgorithm.firstBlocking() != LawnchairSearchAlgorithm.APP_SEARCH) { + if (prefs2.searchAlgorithm.firstCached() != LawnchairSearchAlgorithm.APP_SEARCH) { input.setHint(R.string.all_apps_device_search_hint) } else { input.setHint(R.string.all_apps_search_bar_hint) @@ -246,7 +246,7 @@ class AllAppsSearchInput(context: Context, attrs: AttributeSet?) : }, ) - val hide = prefs2.hideAppDrawerSearchBar.firstBlocking() + val hide = prefs2.hideAppDrawerSearchBar.firstCached() if (hide) { isInvisible = true layoutParams.height = 0 diff --git a/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt b/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt index af2c2580e2..df4852cdab 100644 --- a/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt +++ b/lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt @@ -7,7 +7,6 @@ import app.lawnchair.gestures.config.GestureHandlerConfig import app.lawnchair.gestures.type.GestureType import app.lawnchair.launcher import app.lawnchair.preferences2.PreferenceManager2 -import app.lawnchair.util.firstBlocking import com.android.launcher3.util.ComponentKey import com.android.launcher3.util.VibratorWrapper import kotlinx.coroutines.launch @@ -61,7 +60,7 @@ class IconGestureListener( * @param gestureType The type of gesture to resolve for the current component */ private fun resolveGesture(gestureType: GestureType): GestureHandlerConfig? { val currentComponentKey = componentKey ?: return null - val gesture = prefs.getGestureForApp(currentComponentKey, gestureType).firstBlocking() + val gesture = prefs.getGestureForAppCached(currentComponentKey, gestureType) return gesture.takeUnless { it is GestureHandlerConfig.NoOp } } } diff --git a/lawnchair/src/app/lawnchair/gestures/ui/CreateActionsScreen.kt b/lawnchair/src/app/lawnchair/gestures/ui/CreateActionsScreen.kt index 8f9956ef0e..9f854a3dc7 100644 --- a/lawnchair/src/app/lawnchair/gestures/ui/CreateActionsScreen.kt +++ b/lawnchair/src/app/lawnchair/gestures/ui/CreateActionsScreen.kt @@ -16,7 +16,6 @@ import app.lawnchair.ui.preferences.components.controls.ClickablePreference import app.lawnchair.ui.preferences.components.layout.PreferenceLayoutLazyColumn import app.lawnchair.ui.preferences.components.layout.preferenceGroupItems import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.launch @Composable diff --git a/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt b/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt index d3d613c727..e74e1171c6 100644 --- a/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt +++ b/lawnchair/src/app/lawnchair/icons/LawnchairThemeManager.kt @@ -7,6 +7,7 @@ import app.lawnchair.icons.shape.PathShapeDelegate import app.lawnchair.preferences.PreferenceChangeListener import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import com.android.launcher3.LauncherPrefs import com.android.launcher3.concurrent.annotations.Ui import com.android.launcher3.dagger.ApplicationContext @@ -14,7 +15,6 @@ import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.graphics.ThemeManager 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.CoroutineName import kotlinx.coroutines.MainScope @@ -86,14 +86,14 @@ constructor( private fun parseIconStateV2(oldState: IconState?): IconState { val currentAppShape: IconShape = try { - prefs2.iconShape.firstBlocking() + prefs2.iconShape.firstCached() } catch (e: Exception) { Log.d(TAG, "Error getting icon shape", e) IconShape.Circle } val currentFolderShape: IconShape = try { - prefs2.folderShape.firstBlocking() + prefs2.folderShape.firstCached() } catch (e: Exception) { Log.d(TAG, "Error getting folder shape", e) IconShape.Circle diff --git a/lawnchair/src/app/lawnchair/icons/shape/IconShapeManager.kt b/lawnchair/src/app/lawnchair/icons/shape/IconShapeManager.kt index 359bd3e49f..200003e542 100644 --- a/lawnchair/src/app/lawnchair/icons/shape/IconShapeManager.kt +++ b/lawnchair/src/app/lawnchair/icons/shape/IconShapeManager.kt @@ -22,13 +22,13 @@ package app.lawnchair.icons.shape import android.content.Context import android.graphics.drawable.AdaptiveIconDrawable import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import com.android.launcher3.Utilities import com.android.launcher3.dagger.ApplicationContext import com.android.launcher3.dagger.LauncherAppComponent import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.DaggerSingletonObject import com.android.launcher3.util.SafeCloseable -import com.patrykmichalik.opto.core.firstBlocking import javax.inject.Inject @LauncherAppSingleton @@ -56,6 +56,9 @@ class IconShapeManager @Inject constructor( fun getSystemIconShape(context: Context) = INSTANCE.get(context).systemIconShape @JvmStatic - fun getWindowTransitionRadius(context: Context) = PreferenceManager2.getInstance(context).iconShape.firstBlocking().windowTransitionRadius + fun getWindowTransitionRadius(context: Context): Float { + val prefs = PreferenceManager2.getInstance(context) + return prefs.iconShape.firstCached().windowTransitionRadius + } } } diff --git a/lawnchair/src/app/lawnchair/nexuslauncher/OverlayCallbackImpl.kt b/lawnchair/src/app/lawnchair/nexuslauncher/OverlayCallbackImpl.kt index 616eb582c6..e35ce34f24 100644 --- a/lawnchair/src/app/lawnchair/nexuslauncher/OverlayCallbackImpl.kt +++ b/lawnchair/src/app/lawnchair/nexuslauncher/OverlayCallbackImpl.kt @@ -7,6 +7,7 @@ import android.os.Bundle import app.lawnchair.FeedBridge import app.lawnchair.LawnchairLauncher import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import com.android.launcher3.Launcher import com.android.launcher3.LauncherPrefs import com.android.systemui.plugins.shared.LauncherOverlayManager @@ -17,7 +18,6 @@ import com.google.android.libraries.launcherclient.LauncherClient import com.google.android.libraries.launcherclient.LauncherClientCallbacks import com.google.android.libraries.launcherclient.LauncherClientService import com.google.android.libraries.launcherclient.StaticInteger -import com.patrykmichalik.opto.core.firstBlocking /** * Implements [LauncherOverlay] and passes all the corresponding events to [LauncherClient], @@ -37,7 +37,8 @@ class OverlayCallbackImpl(private val mLauncher: LawnchairLauncher) : private var mFlags = 0 init { - val enableFeed = PreferenceManager2.getInstance(mLauncher).enableFeed.firstBlocking() + val prefs = PreferenceManager2.getInstance(mLauncher) + val enableFeed = prefs.enableFeed.firstCached() mClient = LauncherClient( mLauncher, this, diff --git a/lawnchair/src/app/lawnchair/preferences/PreferenceAdapter.kt b/lawnchair/src/app/lawnchair/preferences/PreferenceAdapter.kt index f73146f0fe..f198458b30 100644 --- a/lawnchair/src/app/lawnchair/preferences/PreferenceAdapter.kt +++ b/lawnchair/src/app/lawnchair/preferences/PreferenceAdapter.kt @@ -28,7 +28,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.compose.collectAsStateWithLifecycle import app.lawnchair.preferences2.IdpPreference import app.lawnchair.preferences2.asState -import app.lawnchair.preferences2.firstBlocking +import app.lawnchair.preferences2.firstCached +import app.lawnchair.preferences2.preferenceManager2 import com.android.launcher3.InvariantDeviceProfile import com.patrykmichalik.opto.domain.Preference import kotlin.reflect.KProperty @@ -127,7 +128,8 @@ fun IdpPreference.getAdapter(): PreferenceAdapter { val context = LocalContext.current val idp = remember { InvariantDeviceProfile.INSTANCE.get(context) } val defaultGrid = idp.closestProfile - val state = get(defaultGrid).collectAsStateWithLifecycle(initialValue = firstBlocking(defaultGrid)) + val prefs2 = preferenceManager2() + val state = get(defaultGrid).collectAsStateWithLifecycle(initialValue = firstCached(defaultGrid, prefs2)) return createStateAdapter(state = state, set = { set(it, defaultGrid) }) } diff --git a/lawnchair/src/app/lawnchair/preferences2/IdpPreference.kt b/lawnchair/src/app/lawnchair/preferences2/IdpPreference.kt index dbf1e7d188..9445dc6858 100644 --- a/lawnchair/src/app/lawnchair/preferences2/IdpPreference.kt +++ b/lawnchair/src/app/lawnchair/preferences2/IdpPreference.kt @@ -1,11 +1,14 @@ package app.lawnchair.preferences2 +import androidx.annotation.Discouraged import androidx.compose.runtime.Composable import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.edit import androidx.lifecycle.compose.collectAsStateWithLifecycle +import app.lawnchair.LawnchairApp import com.android.launcher3.InvariantDeviceProfile +import kotlin.jvm.JvmOverloads import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import kotlinx.coroutines.runBlocking @@ -39,8 +42,23 @@ class IdpPreference( } } +@Discouraged("This is a blocking read, use firstCached() for non-blocking reads") fun IdpPreference.firstBlocking(gridOption: InvariantDeviceProfile.GridOption) = runBlocking { get(gridOption = gridOption).first() } +@JvmOverloads +fun IdpPreference.firstCached( + gridOption: InvariantDeviceProfile.GridOption, + prefs2: PreferenceManager2 = PreferenceManager2.getInstance(LawnchairApp.instance), +): Int { + val cached = prefs2.getCachedPreferences() + val value = cached[key] + return if (value == null || value == -1) { + defaultSelector(gridOption) + } else { + value + } +} + @Composable fun IdpPreference.state( gridOption: InvariantDeviceProfile.GridOption, diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceCacheExtensions.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceCacheExtensions.kt new file mode 100644 index 0000000000..5bef362d0c --- /dev/null +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceCacheExtensions.kt @@ -0,0 +1,19 @@ +package app.lawnchair.preferences2 + +import app.lawnchair.LawnchairApp +import com.patrykmichalik.opto.core.PreferenceImpl +import com.patrykmichalik.opto.core.getFromPreferences +import kotlin.jvm.JvmOverloads + +/** + * Returns the current value of this preference from the in-memory cache. + * + * Warning: During initialisation of [PreferenceManager2], pass [this] of [PreferenceManager2] instead + * of leaving it blank or else we would be initialising it too early and cause a [StackOverflowError] + */ +@JvmOverloads +fun PreferenceImpl.firstCached( + prefs2: PreferenceManager2 = PreferenceManager2.getInstance(LawnchairApp.instance), +): C { + return getFromPreferences(prefs2.getCachedPreferences()) +} diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index aabf1b076b..d629493660 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -73,13 +73,18 @@ import com.patrykmichalik.opto.core.PreferenceManager import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.setBlocking import javax.inject.Inject -import kotlinx.coroutines.MainScope +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.drop +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.runBlocking @LauncherAppSingleton class PreferenceManager2 @Inject constructor( @@ -87,7 +92,7 @@ class PreferenceManager2 @Inject constructor( ) : PreferenceManager, SafeCloseable { - private val scope = MainScope() + private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate) private val resourceProvider = DynamicResource.provider(context) private var liveInformationManager: LiveInformationManager = LiveInformationManager.getInstance(context) @@ -104,6 +109,14 @@ class PreferenceManager2 @Inject constructor( ) override val preferencesDataStore = context.preferencesDataStore + + @Volatile + private var cachedPreferences: Preferences = runBlocking { + preferencesDataStore.data.first() + } + + fun getCachedPreferences(): Preferences = cachedPreferences + private val reloadHelper = ReloadHelper(context) val darkStatusBar = preference( @@ -838,7 +851,11 @@ class PreferenceManager2 @Inject constructor( ) init { - initializeIconShape(iconShape.firstBlocking()) + preferencesDataStore.data + .onEach { cachedPreferences = it } + .launchIn(scope) + + initializeIconShape(iconShape.firstCached(this)) iconShape.get() .drop(1) .distinctUntilChanged() @@ -873,6 +890,16 @@ class PreferenceManager2 @Inject constructor( } } + fun getGestureForAppCached(key: ComponentKey, gestureType: GestureType): GestureHandlerConfig { + val cmp = Converters().fromComponentKey(key) + val key = stringPreferencesKey("$cmp:${gestureType.name}") + val prefs = getCachedPreferences() + return prefs[key]?.let { + runCatching { kotlinxJson.decodeFromString(it) } + .getOrDefault(GestureHandlerConfig.NoOp) + } ?: GestureHandlerConfig.NoOp + } + private fun initializeIconShape(shape: IconShape) { CustomAdaptiveIconDrawable.sInitialized = true CustomAdaptiveIconDrawable.sMaskId = shape.getHashString() @@ -880,6 +907,7 @@ class PreferenceManager2 @Inject constructor( } override fun close() { + scope.cancel() } private fun getRemoteDefault(key: String): String? = liveInformationManager.liveInformation diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceUtils.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceUtils.kt index a9388c4406..d4abc6c2a8 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceUtils.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceUtils.kt @@ -3,13 +3,35 @@ package app.lawnchair.preferences2 import androidx.compose.runtime.Composable import androidx.lifecycle.compose.collectAsStateWithLifecycle import app.lawnchair.util.subscribeBlocking +import com.patrykmichalik.opto.core.PreferenceImpl import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.domain.Preference import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.dropWhile +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach @Composable fun Preference.asState() = get().collectAsStateWithLifecycle(initialValue = firstBlocking()) +@Composable +fun PreferenceImpl.asState() = get().collectAsStateWithLifecycle(initialValue = firstCached(preferenceManager2())) + +fun PreferenceImpl.subscribeBlocking( + prefs2: PreferenceManager2, + scope: CoroutineScope, + block: (C) -> Unit, +) { + val initial = firstCached(prefs2) + block(initial) + get() + .distinctUntilChanged() + .dropWhile { it == initial } + .onEach { block(it) } + .launchIn(scope = scope) +} + fun Preference.subscribeBlocking( scope: CoroutineScope, block: (C) -> Unit, diff --git a/lawnchair/src/app/lawnchair/qsb/LawnQsbLayout.kt b/lawnchair/src/app/lawnchair/qsb/LawnQsbLayout.kt index 1cf690d058..f0a0f1cad3 100644 --- a/lawnchair/src/app/lawnchair/qsb/LawnQsbLayout.kt +++ b/lawnchair/src/app/lawnchair/qsb/LawnQsbLayout.kt @@ -23,6 +23,7 @@ import app.lawnchair.launcher import app.lawnchair.launcherNullable import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.preferences2.subscribeBlocking import app.lawnchair.qsb.providers.AppSearch import app.lawnchair.qsb.providers.Google @@ -39,7 +40,6 @@ import com.android.launcher3.R import com.android.launcher3.qsb.QsbContainerView import com.android.launcher3.util.Themes import com.android.launcher3.views.ActivityContext -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flatMapLatest @@ -71,7 +71,7 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex preferenceManager2 = PreferenceManager2.getInstance(context) val attachedScope = viewAttachedScope - preferenceManager2.strokeColorStyle.subscribeBlocking(scope = attachedScope) { + preferenceManager2.strokeColorStyle.subscribeBlocking(prefs2 = preferenceManager2, scope = attachedScope) { strokeColor = it setUpBackground() } @@ -82,7 +82,7 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex val isGoogle = searchProvider == Google || searchProvider == GoogleGo || searchProvider == PixelSearch val supportsLens = searchProvider == Google || searchProvider == PixelSearch - preferenceManager2.themedHotseatQsb.subscribeBlocking(scope = attachedScope) { themed -> + preferenceManager2.themedHotseatQsb.subscribeBlocking(prefs2 = preferenceManager2, scope = attachedScope) { themed -> setUpBackground(themed) val iconRes = if (themed) searchProvider.themedIcon else searchProvider.icon @@ -105,7 +105,7 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex setOnClickListener { val launcher = context.launcher launcher.lifecycleScope.launch { - if (preferenceManager2.matchHotseatQsbStyle.firstBlocking()) { + if (preferenceManager2.matchHotseatQsbStyle.firstCached()) { launcher.appsView.searchUiManager.editText?.showKeyboard() launcher.animateToAllApps() } else { @@ -237,7 +237,7 @@ class LawnQsbLayout(context: Context, attrs: AttributeSet?) : FrameLayout(contex context: Context, preferenceManager: PreferenceManager2, ): QsbSearchProvider { - val provider = preferenceManager.hotseatQsbProvider.firstBlocking() + val provider = preferenceManager.hotseatQsbProvider.firstCached() return if (provider == AppSearch || resolveIntent(context, provider.createSearchIntent()) || diff --git a/lawnchair/src/app/lawnchair/search/algorithms/LawnchairLocalSearchAlgorithm.kt b/lawnchair/src/app/lawnchair/search/algorithms/LawnchairLocalSearchAlgorithm.kt index 0f1cc685f1..e836289b1d 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/LawnchairLocalSearchAlgorithm.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/LawnchairLocalSearchAlgorithm.kt @@ -3,6 +3,7 @@ package app.lawnchair.search.algorithms import android.content.Context import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.adapter.SearchLinksTarget import app.lawnchair.search.adapter.SearchTargetCompat import app.lawnchair.search.adapter.SearchTargetFactory @@ -32,7 +33,6 @@ import com.android.launcher3.LauncherAppState import com.android.launcher3.R import com.android.launcher3.allapps.BaseAllAppsAdapter import com.android.launcher3.search.SearchCallback -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -101,7 +101,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm } else { currentJob = coroutineScope.launch { val prefs2 = PreferenceManager2.getInstance(context) - val maxHistory = prefs2.maxRecentResultCount.firstBlocking() + val maxHistory = prefs2.maxRecentResultCount.firstCached() val historyResults = historySearchProvider.getRecentKeywords(context, maxHistory) @@ -136,7 +136,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm val prefs2 = PreferenceManager2.getInstance(context) if (prefs.searchResultStartPageSuggestion.get()) { - val provider = prefs2.webSuggestionProvider.firstBlocking() + val provider = prefs2.webSuggestionProvider.firstCached() val webProvider = provider.configure(context) val providerName = if (webProvider is CustomWebSearchProvider) { diff --git a/lawnchair/src/app/lawnchair/search/algorithms/LawnchairSearchAlgorithm.kt b/lawnchair/src/app/lawnchair/search/algorithms/LawnchairSearchAlgorithm.kt index 607a8e10a9..1212437cc0 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/LawnchairSearchAlgorithm.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/LawnchairSearchAlgorithm.kt @@ -5,6 +5,7 @@ import app.lawnchair.LawnchairApp import app.lawnchair.allapps.views.SearchItemBackground import app.lawnchair.allapps.views.SearchResultView.Companion.EXTRA_QUICK_LAUNCH import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.LawnchairSearchAdapterProvider import app.lawnchair.search.adapter.START_PAGE import app.lawnchair.search.adapter.SearchAdapterItem @@ -31,7 +32,6 @@ import com.android.launcher3.Utilities import com.android.launcher3.allapps.BaseAllAppsAdapter import com.android.launcher3.search.SearchAlgorithm import com.android.launcher3.search.SearchCallback -import com.patrykmichalik.opto.core.firstBlocking sealed class LawnchairSearchAlgorithm( protected val context: Context, @@ -237,7 +237,7 @@ sealed class LawnchairSearchAlgorithm( fun create(context: Context): LawnchairSearchAlgorithm { val prefs = PreferenceManager2.getInstance(context) - val searchAlgorithm = prefs.searchAlgorithm.firstBlocking() + val searchAlgorithm = prefs.searchAlgorithm.firstCached() return when { searchAlgorithm == ASI_SEARCH && isASISearchEnabled(context) -> LawnchairASISearchAlgorithm( diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/SectionBuilder.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/SectionBuilder.kt index 176d4ade2f..edac9f31b1 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/SectionBuilder.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/SectionBuilder.kt @@ -2,11 +2,11 @@ package app.lawnchair.search.algorithms.engine import android.content.Context import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.adapter.SPACE import app.lawnchair.search.adapter.SearchTargetCompat import app.lawnchair.search.adapter.SearchTargetFactory import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking sealed interface SectionBuilder { /** @@ -131,7 +131,8 @@ data object HistorySectionBuilder : SectionBuilder { factory: SearchTargetFactory, results: List, ): List { - val webSuggestion = PreferenceManager2.getInstance(context).webSuggestionProvider.firstBlocking() + val prefs = PreferenceManager2.getInstance(context) + val webSuggestion = prefs.webSuggestionProvider.firstCached() val history = results.filterIsInstance() if (history.isEmpty()) { diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/ContactsSearchProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/ContactsSearchProvider.kt index bacc7c9885..c620104b73 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/ContactsSearchProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/ContactsSearchProvider.kt @@ -7,11 +7,11 @@ import android.provider.ContactsContract import android.util.Log import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.algorithms.data.ContactInfo import app.lawnchair.search.algorithms.engine.SearchPermission import app.lawnchair.search.algorithms.engine.SearchProvider import app.lawnchair.search.algorithms.engine.SearchResult -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow @@ -37,7 +37,7 @@ object ContactsSearchProvider : SearchProvider, SearchPermission { return@flow } - val maxResults = prefs2.maxPeopleResultCount.firstBlocking() + val maxResults = prefs2.maxPeopleResultCount.firstCached() // Call the newly encapsulated, private function. val contactInfoList = findContactsByName(context, query, maxResults) diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/FileSearchProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/FileSearchProvider.kt index 23cb2c56a6..d7d7aab411 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/FileSearchProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/FileSearchProvider.kt @@ -7,6 +7,7 @@ import android.provider.MediaStore import android.util.Log import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.algorithms.data.FileInfo import app.lawnchair.search.algorithms.data.FolderInfo import app.lawnchair.search.algorithms.data.IFileInfo @@ -22,7 +23,6 @@ import app.lawnchair.util.isHidden import app.lawnchair.util.isRegularFile import app.lawnchair.util.mimeType2Extension import app.lawnchair.util.videoFileTypes -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope @@ -54,7 +54,7 @@ object FileSearchProvider : SearchProvider { } val prefs2 = PreferenceManager2.getInstance(context) - val maxResults = prefs2.maxFileResultCount.firstBlocking() + val maxResults = prefs2.maxFileResultCount.firstCached() // check for permissions: val fileAccessManager = FileAccessManager.getInstance(context) diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/SettingsSearchProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/SettingsSearchProvider.kt index 4191ec7161..183161b0b3 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/SettingsSearchProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/SettingsSearchProvider.kt @@ -5,10 +5,10 @@ import android.provider.Settings import android.util.Log import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.algorithms.data.SettingInfo import app.lawnchair.search.algorithms.engine.SearchProvider import app.lawnchair.search.algorithms.engine.SearchResult -import com.patrykmichalik.opto.core.firstBlocking import java.lang.reflect.Modifier import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.Dispatchers @@ -33,7 +33,7 @@ object SettingsSearchProvider : SearchProvider { return@flow } - val maxResults = prefs2.maxSettingsEntryResultCount.firstBlocking() + val maxResults = prefs2.maxSettingsEntryResultCount.firstCached() val settingsInfoList = findSettingsByNameAndAction(query, maxResults) val searchResults = settingsInfoList.map { settingInfo -> diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/apps/AppSearchProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/apps/AppSearchProvider.kt index d56676d189..c3a5342fa1 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/apps/AppSearchProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/apps/AppSearchProvider.kt @@ -2,22 +2,22 @@ package app.lawnchair.search.algorithms.engine.provider.apps import android.content.Context import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.algorithms.engine.SearchResult import app.lawnchair.search.algorithms.filterHiddenApps import com.android.launcher3.model.AllAppsList import com.android.launcher3.model.data.AppInfo import com.android.launcher3.search.StringMatcherUtility -import com.patrykmichalik.opto.core.firstBlocking import java.util.Locale object AppSearchProvider { fun search(context: Context, query: String, allApps: AllAppsList): List { val prefs = PreferenceManager2.getInstance(context) - val hiddenApps = prefs.hiddenApps.firstBlocking() - val hiddenAppsInSearch = prefs.hiddenAppsInSearch.firstBlocking() - val maxAppResults = prefs.maxAppSearchResultCount.firstBlocking() - val enableFuzzySearch = prefs.enableFuzzySearch.firstBlocking() + val hiddenApps = prefs.hiddenApps.firstCached() + val hiddenAppsInSearch = prefs.hiddenAppsInSearch.firstCached() + val maxAppResults = prefs.maxAppSearchResultCount.firstCached() + val enableFuzzySearch = prefs.enableFuzzySearch.firstCached() val appResults = if (enableFuzzySearch) { fuzzySearch(allApps.data, query, maxAppResults, hiddenApps, hiddenAppsInSearch) diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/CustomWebSearchProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/CustomWebSearchProvider.kt index 9e0e12274f..52dea4e704 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/CustomWebSearchProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/CustomWebSearchProvider.kt @@ -4,8 +4,8 @@ import android.content.Context import android.net.Uri import android.util.Log import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -48,9 +48,9 @@ object CustomWebSearchProvider : WebSearchProvider { override fun configure(context: Context): WebSearchProvider { val prefs = PreferenceManager2.getInstance(context) - searchUrlTemplate = prefs.webSuggestionProviderUrl.firstBlocking() - suggestionsUrlTemplate = prefs.webSuggestionProviderSuggestionsUrl.firstBlocking() - displayName = prefs.webSuggestionProviderName.firstBlocking() + searchUrlTemplate = prefs.webSuggestionProviderUrl.firstCached() + suggestionsUrlTemplate = prefs.webSuggestionProviderSuggestionsUrl.firstCached() + displayName = prefs.webSuggestionProviderName.firstCached() return this } diff --git a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/WebSuggestionProvider.kt b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/WebSuggestionProvider.kt index 94e73f68d7..38fbc3b63a 100644 --- a/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/WebSuggestionProvider.kt +++ b/lawnchair/src/app/lawnchair/search/algorithms/engine/provider/web/WebSuggestionProvider.kt @@ -4,9 +4,9 @@ import android.content.Context import android.util.Log import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.search.algorithms.engine.SearchProvider import app.lawnchair.search.algorithms.engine.SearchResult -import com.patrykmichalik.opto.core.firstBlocking import kotlin.time.Duration.Companion.milliseconds import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.flow.Flow @@ -29,9 +29,9 @@ object WebSuggestionProvider : SearchProvider { return flow { emit(emptyList()) } } - val provider = prefs2.webSuggestionProvider.firstBlocking() - val timeout = prefs2.maxWebSuggestionDelay.firstBlocking() - val maxResults = prefs2.maxWebSuggestionResultCount.firstBlocking() + val provider = prefs2.webSuggestionProvider.firstCached() + val timeout = prefs2.maxWebSuggestionDelay.firstCached() + val maxResults = prefs2.maxWebSuggestionResultCount.firstCached() val webProvider = provider .configure(context) diff --git a/lawnchair/src/app/lawnchair/smartspace/SmartspacerView.kt b/lawnchair/src/app/lawnchair/smartspace/SmartspacerView.kt index 4d06aa8269..8713604c25 100644 --- a/lawnchair/src/app/lawnchair/smartspace/SmartspacerView.kt +++ b/lawnchair/src/app/lawnchair/smartspace/SmartspacerView.kt @@ -33,7 +33,7 @@ class SmartspacerView(context: Context, attrs: AttributeSet?) : BcSmartspaceView private var targetCount = 5 init { - prefs2.smartspacerMaxCount.subscribeBlocking(coroutineScope) { + prefs2.smartspacerMaxCount.subscribeBlocking(prefs2 = prefs2, scope = coroutineScope) { targetCount = it } diff --git a/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt b/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt index b738a859d9..2424ee5f07 100644 --- a/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt +++ b/lawnchair/src/app/lawnchair/theme/ThemeProvider.kt @@ -9,6 +9,7 @@ import android.os.Looper import android.os.PatternMatcher import androidx.core.graphics.ColorUtils import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.theme.color.AndroidColor import app.lawnchair.theme.color.ColorOption import app.lawnchair.theme.color.ColorStyle @@ -23,7 +24,6 @@ import com.android.launcher3.dagger.LauncherAppSingleton import com.android.launcher3.util.DaggerSingletonObject import com.android.launcher3.util.SafeCloseable import com.android.systemui.monet.Style -import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.onEach import dev.kdrag0n.colorkt.Color import dev.kdrag0n.colorkt.conversion.ConversionGraph.convert @@ -41,8 +41,8 @@ class ThemeProvider @Inject constructor( private val wallpaperManager = WallpaperManagerCompat.INSTANCE.get(context) private val coroutineScope = CoroutineScope(Dispatchers.Default) - private var accentColor: ColorOption = preferenceManager2.accentColor.firstBlocking() - private var colorStyle: ColorStyle = preferenceManager2.colorStyle.firstBlocking() + private var accentColor: ColorOption = preferenceManager2.accentColor.firstCached() + private var colorStyle: ColorStyle = preferenceManager2.colorStyle.firstCached() private val colorSchemeMap = HashMap, ColorScheme>() private val listeners = mutableListOf() diff --git a/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt b/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt index 694889694d..133734f376 100644 --- a/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt +++ b/lawnchair/src/app/lawnchair/theme/drawable/DrawableTokens.kt @@ -10,9 +10,9 @@ import android.graphics.drawable.RippleDrawable import android.graphics.drawable.StateListDrawable import androidx.appcompat.content.res.AppCompatResources import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.theme.color.tokens.ColorTokens import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking object DrawableTokens { @@ -159,7 +159,7 @@ object DrawableTokens { // Get custom color from preferences val prefs2 = PreferenceManager2.getInstance(context) - val colorOption = prefs2.workProfileTabBackgroundColor.firstBlocking() + val colorOption = prefs2.workProfileTabBackgroundColor.firstCached() val customColor = colorOption.colorPreferenceEntry.lightColor.invoke(context) val selectedColor = if (customColor != 0) { diff --git a/lawnchair/src/app/lawnchair/ui/popup/LauncherOptionsPopup.kt b/lawnchair/src/app/lawnchair/ui/popup/LauncherOptionsPopup.kt index 80650ab04e..265dbb485a 100644 --- a/lawnchair/src/app/lawnchair/ui/popup/LauncherOptionsPopup.kt +++ b/lawnchair/src/app/lawnchair/ui/popup/LauncherOptionsPopup.kt @@ -5,13 +5,13 @@ import android.widget.Toast import androidx.annotation.DrawableRes import androidx.annotation.StringRes import app.lawnchair.preferences2.PreferenceManager2.Companion.getInstance +import app.lawnchair.preferences2.firstCached import com.android.launcher3.Launcher import com.android.launcher3.R import com.android.launcher3.Utilities import com.android.launcher3.logging.StatsLogManager.LauncherEvent import com.android.launcher3.popup.SystemShortcut import com.android.launcher3.views.OptionsPopupView.OptionItem -import com.patrykmichalik.opto.core.firstBlocking import com.patrykmichalik.opto.core.setBlocking object LauncherOptionsPopup { @@ -32,7 +32,7 @@ object LauncherOptionsPopup { ) { val prefs2 = getInstance(launcher) - val currentOrder = prefs2.launcherPopupOrder.firstBlocking() + val currentOrder = prefs2.launcherPopupOrder.firstCached() val currentOptions = currentOrder.toLauncherOptions() // check for missing items in current options; if so, add them @@ -61,9 +61,9 @@ object LauncherOptionsPopup { onStartHomeSettings: (View) -> Boolean, ): ArrayList { val prefs2 = getInstance(launcher!!) - val lockHomeScreen = prefs2.lockHomeScreen.firstBlocking() + val lockHomeScreen = prefs2.lockHomeScreen.firstCached() val optionOrder = prefs2 - .launcherPopupOrder.firstBlocking().toLauncherOptions() + .launcherPopupOrder.firstCached().toLauncherOptions() val wallpaperResString = if (Utilities.existsStyleWallpapers(launcher)) R.string.styles_wallpaper_button_text else R.string.wallpapers @@ -220,17 +220,17 @@ object LauncherOptionsPopup { ) { val prefs2 = getInstance(launcher) - val lockHomeScreenButtonOnPopUp = prefs2.lockHomeScreenButtonOnPopUp.firstBlocking() - val editHomeScreenButtonOnPopUp = prefs2.editHomeScreenButtonOnPopUp.firstBlocking() - val showSystemSettingsEntryOnPopUp = prefs2.showSystemSettingsEntryOnPopUp.firstBlocking() + val lockHomeScreenButtonOnPopUp = prefs2.lockHomeScreenButtonOnPopUp.firstCached() + val editHomeScreenButtonOnPopUp = prefs2.editHomeScreenButtonOnPopUp.firstCached() + val showSystemSettingsEntryOnPopUp = prefs2.showSystemSettingsEntryOnPopUp.firstCached() val optionOrder = prefs2.launcherPopupOrder - val legacyPopupOptionsMigrated = prefs2.legacyPopupOptionsMigrated.firstBlocking() + val legacyPopupOptionsMigrated = prefs2.legacyPopupOptionsMigrated.firstCached() if (!legacyPopupOptionsMigrated) { prefs2.legacyPopupOptionsMigrated.setBlocking(true) - val options = optionOrder.firstBlocking().toLauncherOptions() + val options = optionOrder.firstCached().toLauncherOptions() options.forEachIndexed { index, item -> if (item.identifier == "lock") { diff --git a/lawnchair/src/app/lawnchair/ui/popup/LawnchairShortcut.kt b/lawnchair/src/app/lawnchair/ui/popup/LawnchairShortcut.kt index 1e96576cea..d0b039676d 100644 --- a/lawnchair/src/app/lawnchair/ui/popup/LawnchairShortcut.kt +++ b/lawnchair/src/app/lawnchair/ui/popup/LawnchairShortcut.kt @@ -20,6 +20,7 @@ import androidx.compose.ui.unit.dp import app.lawnchair.LawnchairLauncher import app.lawnchair.override.CustomizeAppDialog import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.views.ComposeBottomSheet import com.android.launcher3.AbstractFloatingView import com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION @@ -34,7 +35,6 @@ import com.android.launcher3.util.ApplicationInfoWrapper import com.android.launcher3.util.ComponentKey import com.android.launcher3.util.PackageManagerHelper import com.android.launcher3.views.ActivityContext -import com.patrykmichalik.opto.core.firstBlocking import java.net.URISyntaxException class LawnchairShortcut { @@ -43,7 +43,8 @@ class LawnchairShortcut { val CUSTOMIZE = SystemShortcut.Factory { activity: LawnchairLauncher, itemInfo, originalView -> - if (PreferenceManager2.getInstance(activity).lockHomeScreen.firstBlocking()) { + val prefs2 = PreferenceManager2.getInstance(activity) + if (prefs2.lockHomeScreen.firstCached()) { null } else { getAppInfo(activity, itemInfo)?.let { Customize(activity, it, itemInfo, originalView) } @@ -59,7 +60,8 @@ class LawnchairShortcut { val UNINSTALL = SystemShortcut.Factory { activity: ActivityContext, itemInfo: ItemInfo, view: View -> - if (PreferenceManager2.INSTANCE.get(activity.asContext()).lockHomeScreen.firstBlocking()) { + val prefs2 = PreferenceManager2.INSTANCE.get(activity.asContext()) + if (prefs2.lockHomeScreen.firstCached()) { return@Factory null } if (itemInfo.targetComponent == null) { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/about/AboutViewModel.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/AboutViewModel.kt index 9962162741..aa567958f2 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/about/AboutViewModel.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/AboutViewModel.kt @@ -5,9 +5,9 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import com.android.launcher3.BuildConfig import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow @@ -62,7 +62,7 @@ class AboutViewModel( // Check if the build variant is Nightly // AND check if user has enabled auto updater (available to Nightly variant) // OR check if user has overridden it in debug flags (available to All variant) - if (BuildConfig.APPLICATION_ID.contains("nightly") && prefs2.autoUpdaterNightly.firstBlocking()) { + if (BuildConfig.APPLICATION_ID.contains("nightly") && prefs2.autoUpdaterNightly.firstCached()) { nightlyBuildsRepository.checkForUpdate() viewModelScope.launch { nightlyBuildsRepository.updateState.collect { state -> diff --git a/lawnchair/src/app/lawnchair/ui/preferences/components/GestureHandlerPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/GestureHandlerPreference.kt index 7c604f993b..f8398a7672 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/components/GestureHandlerPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/GestureHandlerPreference.kt @@ -39,7 +39,6 @@ import app.lawnchair.ui.preferences.components.layout.PreferenceDivider import app.lawnchair.ui.preferences.components.layout.PreferenceTemplate import app.lawnchair.ui.util.LocalBottomSheetHandler import com.android.launcher3.util.ComponentKey -import com.patrykmichalik.opto.core.firstBlocking import kotlinx.coroutines.launch @OptIn(ExperimentalMaterial3ExpressiveApi::class) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/GeneralPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/GeneralPreferences.kt index 991e96aae1..b61bd271c1 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/GeneralPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/GeneralPreferences.kt @@ -53,7 +53,6 @@ import app.lawnchair.ui.preferences.navigation.GeneralIconShape import com.android.launcher3.BuildConfig import com.android.launcher3.R import com.android.launcher3.Utilities -import com.patrykmichalik.opto.core.firstBlocking @Composable fun GeneralPreferences() { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/PreferencesDashboard.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/PreferencesDashboard.kt index 1ce04ec23c..d8e71540f7 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/PreferencesDashboard.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/PreferencesDashboard.kt @@ -45,6 +45,7 @@ import app.lawnchair.backup.ui.restoreBackupOpener import app.lawnchair.preferences.getAdapter import app.lawnchair.preferences.observeAsState import app.lawnchair.preferences.preferenceManager +import app.lawnchair.preferences2.firstCached import app.lawnchair.preferences2.preferenceManager2 import app.lawnchair.ui.OverflowMenuGrouped import app.lawnchair.ui.preferences.LocalNavController @@ -76,7 +77,6 @@ import app.lawnchair.util.isDefaultLauncher import app.lawnchair.util.restartLauncher import com.android.launcher3.BuildConfig import com.android.launcher3.R -import com.patrykmichalik.opto.core.firstBlocking @Composable fun PreferencesDashboard( @@ -140,7 +140,7 @@ fun PreferencesDashboard( ) } - val isSmartspaceEnabled = prefs2.enableSmartspace.firstBlocking() + val isSmartspaceEnabled = prefs2.enableSmartspace.firstCached() Item { PreferenceCategory( label = stringResource(id = R.string.smartspace_widget), diff --git a/lawnchair/src/app/lawnchair/util/FlowUtils.kt b/lawnchair/src/app/lawnchair/util/FlowUtils.kt index 529efed2b8..e2529e0054 100644 --- a/lawnchair/src/app/lawnchair/util/FlowUtils.kt +++ b/lawnchair/src/app/lawnchair/util/FlowUtils.kt @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import androidx.annotation.Discouraged import androidx.compose.runtime.Composable import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -22,6 +23,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +@Discouraged("This is a blocking read, use firstCached() for non-blocking reads") fun Flow.firstBlocking() = runBlocking { first() } @Composable diff --git a/lawnchair/src/app/lawnchair/util/LawnchairUtils.kt b/lawnchair/src/app/lawnchair/util/LawnchairUtils.kt index 9194698eda..81a77f05f4 100644 --- a/lawnchair/src/app/lawnchair/util/LawnchairUtils.kt +++ b/lawnchair/src/app/lawnchair/util/LawnchairUtils.kt @@ -50,6 +50,7 @@ import androidx.core.graphics.luminance import androidx.core.os.UserManagerCompat import app.lawnchair.preferences.PreferenceManager import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.theme.color.ColorOption import app.lawnchair.theme.color.tokens.ColorTokens import com.android.launcher3.BaseActivity @@ -60,7 +61,6 @@ import com.android.launcher3.util.Executors.MAIN_EXECUTOR import com.android.launcher3.util.Themes import com.android.launcher3.views.ActivityContext import com.android.systemui.shared.system.QuickStepContract -import com.patrykmichalik.opto.core.firstBlocking import java.io.ByteArrayOutputStream import java.io.File import java.util.Locale @@ -178,18 +178,18 @@ val View?.pendingIntent get() = this?.getTag(pendingIntentTagId) as? PendingInte fun getFolderPreviewAlpha(context: Context): Int { val prefs2 = PreferenceManager2.getInstance(context) - return (prefs2.folderPreviewBackgroundOpacity.firstBlocking() * 255).toInt() + return (prefs2.folderPreviewBackgroundOpacity.firstCached() * 255).toInt() } fun getFolderBackgroundAlpha(context: Context): Int { val prefs2 = PreferenceManager2.getInstance(context) - return (prefs2.folderBackgroundOpacity.firstBlocking() * 255).toInt() + return (prefs2.folderBackgroundOpacity.firstCached() * 255).toInt() } /** Apply Lawnchair custom allapps colour to the provided colour */ private fun getAllAppsBaseColor(context: Context, defaultColor: Int): Int { val prefs2 = PreferenceManager2.getInstance(context) - val colorOptions: ColorOption = prefs2.appDrawerBackgroundColor.firstBlocking() + val colorOptions: ColorOption = prefs2.appDrawerBackgroundColor.firstCached() val color = colorOptions.colorPreferenceEntry.lightColor.invoke(context) val baseColor = if (color != 0) color else defaultColor return ColorUtils.setAlphaComponent(baseColor, 255) diff --git a/lawnchair/src/app/lawnchair/views/FullScreenOverlayView.kt b/lawnchair/src/app/lawnchair/views/FullScreenOverlayView.kt index 16584167d0..15a8c37d39 100644 --- a/lawnchair/src/app/lawnchair/views/FullScreenOverlayView.kt +++ b/lawnchair/src/app/lawnchair/views/FullScreenOverlayView.kt @@ -19,9 +19,9 @@ import android.view.animation.DecelerateInterpolator import android.view.animation.PathInterpolator import android.widget.FrameLayout import app.lawnchair.preferences2.PreferenceManager2 +import app.lawnchair.preferences2.firstCached import app.lawnchair.theme.color.tokens.ColorTokens import app.lawnchair.views.overlay.FullScreenOverlayMode -import com.patrykmichalik.opto.core.firstBlocking class FullScreenOverlayView @JvmOverloads constructor( context: Context, @@ -196,7 +196,7 @@ fun Activity.showFullScreenOverlay( onOverlayReady: () -> Unit, ) { val pref2 = PreferenceManager2.getInstance(this) - val animationMode = pref2.closingAppOverlay.firstBlocking() + val animationMode = pref2.closingAppOverlay.firstCached() val overlayView = FullScreenOverlayView(this) val targetRootView = rootView ?: window.decorView.findViewById(android.R.id.content) diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java index c1a93d66ed..a866f1360e 100644 --- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java +++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java @@ -48,7 +48,7 @@ import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.views.ActivityContext; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -122,7 +122,7 @@ public class PredictionRowView } private void updateVisibility() { - boolean enabled = mPredictionsEnabled && PreferenceExtensionsKt.firstBlocking(prefs2.getShowSuggestedAppsInDrawer()); + boolean enabled = mPredictionsEnabled && PreferenceCacheExtensionsKt.firstCached(prefs2.getShowSuggestedAppsInDrawer()); setVisibility(enabled ? VISIBLE : GONE); if (mActivityContext.getAppsView() != null) { if (enabled) { diff --git a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java index 3b918a0fe1..3d46cb7f43 100644 --- a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java +++ b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java @@ -66,7 +66,7 @@ import com.android.launcher3.uioverrides.PredictedAppIcon; import com.android.launcher3.uioverrides.QuickstepLauncher; import com.android.launcher3.views.Snackbar; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; @@ -394,7 +394,7 @@ public class HotseatPredictionController implements DragController.DragListener, public SystemShortcut getShortcut(QuickstepLauncher activity, ItemInfo itemInfo, View originalView) { PreferenceManager2 prefs = PreferenceManager2.getInstance(activity); - if (PreferenceExtensionsKt.firstBlocking(prefs.getLockHomeScreen())) { + if (PreferenceCacheExtensionsKt.firstCached(prefs.getLockHomeScreen())) { return null; } if (itemInfo.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) { diff --git a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java index 0f7b914990..a364b4446f 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java +++ b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java @@ -44,7 +44,7 @@ import com.android.quickstep.util.BaseDepthController; import java.io.PrintWriter; import java.util.function.Consumer; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.compat.LawnchairQuickstepCompat; import app.lawnchair.preferences2.PreferenceManager2; @@ -74,8 +74,9 @@ public class DepthController extends BaseDepthController implements StateHandler public DepthController(QuickstepLauncher launcher) { super(launcher); - var pref = PreferenceManager2.getInstance(launcher).getWallpaperDepthEffect(); - mEnableDepth = PreferenceExtensionsKt.firstBlocking(pref); + var prefs = PreferenceManager2.getInstance(launcher); + var pref = prefs.getWallpaperDepthEffect(); + mEnableDepth = PreferenceCacheExtensionsKt.firstCached(pref); } private void onLauncherDraw() { diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index f594b93f6b..c787a3803a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -78,7 +78,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.hotseat.HotseatMode; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.tokens.ColorTokens; @@ -167,7 +167,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(context); - HotseatMode hotseatMode = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getHotseatMode()); + HotseatMode hotseatMode = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getHotseatMode()); mActivityContext = ActivityContext.lookupContext(context); mIconLayoutBounds = mActivityContext.getTransientTaskbarBounds(); Resources resources = getResources(); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java index 75193dd303..0a1cb79244 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java @@ -40,7 +40,7 @@ import com.android.wm.shell.shared.animation.Interpolators; import com.android.wm.shell.shared.bubbles.BubbleBarLocation; import com.android.wm.shell.shared.bubbles.BubbleInfo; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.ColorOption; @@ -262,10 +262,10 @@ public class BubbleView extends ConstraintLayout { mAppIcon.setVisibility(GONE); } mDotColor = bubble.getDotColor(); - ColorOption dotColorOption = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getNotificationDotColor()); + ColorOption dotColorOption = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getNotificationDotColor()); int dotColor = dotColorOption.getColorPreferenceEntry().getLightColor().invoke(getContext()); - ColorOption counterColorOption = PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getNotificationDotTextColor()); + ColorOption counterColorOption = PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getNotificationDotTextColor(), preferenceManager2); int countColor = counterColorOption.getColorPreferenceEntry().getLightColor().invoke(getContext()); mDotRenderer = new DotRenderer(mBubbleSize, bubble.getDotPath(), DEFAULT_PATH_SIZE, false, null, dotColor, countColor); diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java index 29e73e4cc2..6fd48b5f23 100644 --- a/src/com/android/launcher3/AppWidgetResizeFrame.java +++ b/src/com/android/launcher3/AppWidgetResizeFrame.java @@ -54,7 +54,7 @@ import com.android.launcher3.widget.util.WidgetSizes; import java.util.ArrayList; import java.util.List; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.tokens.ColorTokens; import app.lawnchair.theme.drawable.DrawableTokens; @@ -220,8 +220,8 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) { PreferenceManager2 pref2 = PreferenceManager2.getInstance(widget.getContext()); - boolean force = PreferenceExtensionsKt.firstBlocking(pref2.getForceWidgetResize()); - boolean unlimited = PreferenceExtensionsKt.firstBlocking(pref2.getWidgetUnlimitedSize()); + boolean force = PreferenceCacheExtensionsKt.firstCached(pref2.getForceWidgetResize()); + boolean unlimited = PreferenceCacheExtensionsKt.firstCached(pref2.getWidgetUnlimitedSize()); // If widget is not added to view hierarchy, we cannot show resize frame at correct location if (widget.getParent() == null) { diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 91c84d1b29..97b4d6b0c6 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -110,7 +110,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Objects; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.LawnchairApp; import app.lawnchair.font.FontManager; import app.lawnchair.gestures.IconGestureListener; @@ -1186,7 +1186,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, ItemInfo info = tag instanceof ItemInfo ? (ItemInfo) tag : null; return info == null || info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT && info.container != LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION - || PreferenceExtensionsKt.firstBlocking(pref2.getEnableLabelInDock()); + || PreferenceCacheExtensionsKt.firstCached(pref2.getEnableLabelInDock()); } /** diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 8f60026017..1b4c319353 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -79,7 +79,7 @@ import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.LauncherAppWidgetHostView; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import com.google.android.msdl.data.model.MSDLToken; @@ -774,7 +774,7 @@ public class CellLayout extends ViewGroup { // Hotseat icons - modified by lawnchair if (child instanceof BubbleTextView bubbleChild) { boolean enableLabel = mContainerType == HOTSEAT - ? PreferenceExtensionsKt.firstBlocking(pref.getEnableLabelInDock()) + ? PreferenceCacheExtensionsKt.firstCached(pref.getEnableLabelInDock()) : true; bubbleChild.setTextVisibility(enableLabel); } @@ -1926,7 +1926,7 @@ public class CellLayout extends ViewGroup { public boolean isOccupied(int x, int y) { if (x >= 0 && x < mCountX && y >= 0 && y < mCountY) { - return mOccupied.cells[x][y] && !PreferenceExtensionsKt.firstBlocking(pref.getAllowWidgetOverlap()); + return mOccupied.cells[x][y] && !PreferenceCacheExtensionsKt.firstCached(pref.getAllowWidgetOverlap()); } if (BuildConfigs.IS_STUDIO_BUILD) { throw new RuntimeException("Position exceeds the bound of this CellLayout"); @@ -2009,7 +2009,7 @@ public class CellLayout extends ViewGroup { } public boolean isRegionVacant(int x, int y, int spanX, int spanY) { - return mOccupied.isRegionVacant(x, y, spanX, spanY) || PreferenceExtensionsKt.firstBlocking(pref.getAllowWidgetOverlap()); + return mOccupied.isRegionVacant(x, y, spanX, spanY) || PreferenceCacheExtensionsKt.firstCached(pref.getAllowWidgetOverlap()); } public void setSpaceBetweenCellLayoutsPx(@Px int spaceBetweenCellLayoutsPx) { diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index d8eaa23fed..f825b376c9 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -33,7 +33,7 @@ import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.LauncherAppWidgetInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.Preconditions; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; @@ -125,7 +125,7 @@ public class DeleteDropTarget extends ButtonDropTarget { } private boolean canRemove(ItemInfo item) { - boolean isDeckLayoutFirst = PreferenceExtensionsKt.firstBlocking(pref2.getDeckLayout()); + boolean isDeckLayoutFirst = PreferenceCacheExtensionsKt.firstCached(pref2.getDeckLayout()); return isDeckLayoutFirst ? isCanDrop(item) : item.id != ItemInfo.NO_ID; } @@ -169,7 +169,7 @@ public class DeleteDropTarget extends ButtonDropTarget { // because we already remove the drag view from the folder (if the drag originated from // a folder) in Folder.beginDrag() CharSequence announcement = getContext().getString(R.string.item_removed); - if (!PreferenceExtensionsKt.firstBlocking(pref2.getDeckLayout())) { + if (!PreferenceCacheExtensionsKt.firstCached(pref2.getDeckLayout())) { mDropTargetHandler.onAccessibilityDelete(view, item, announcement); } } diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index b7f36a0049..c7a3c50d1b 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -88,7 +88,7 @@ import java.io.PrintWriter; import java.util.Locale; import java.util.function.Consumer; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.DeviceProfileOverrides; import app.lawnchair.LawnchairApp; import app.lawnchair.LawnchairAppKt; @@ -355,18 +355,18 @@ public class DeviceProfile { mTextFactors = DeviceProfileOverrides.INSTANCE.get(context).getTextFactors(); preferenceManager2 = PreferenceManager2.INSTANCE.get(context); - allAppsCellHeightMultiplier = PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getDrawerCellHeightFactor()); + allAppsCellHeightMultiplier = PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getDrawerCellHeightFactor()); // Lawnchair: clamp the user padding factors to their slider ranges so a restored or // manually edited preference can't feed out-of-range values into the layout math. - workspacePaddingHorizontalFactor = Utilities.boundToRange(PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getWorkspacePaddingHorizontalFactor()), 0f, 2f); - workspacePaddingVerticalFactor = Utilities.boundToRange(PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getWorkspacePaddingVerticalFactor()), 0f, 2f); - widgetPaddingFactor = Utilities.boundToRange(PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getWidgetPaddingFactor()), 0f, 2f); - drawerPaddingTopFactor = Utilities.boundToRange(PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getDrawerPaddingTopFactor()), 1f, 2f); + workspacePaddingHorizontalFactor = Utilities.boundToRange(PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getWorkspacePaddingHorizontalFactor()), 0f, 2f); + workspacePaddingVerticalFactor = Utilities.boundToRange(PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getWorkspacePaddingVerticalFactor()), 0f, 2f); + widgetPaddingFactor = Utilities.boundToRange(PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getWidgetPaddingFactor()), 0f, 2f); + drawerPaddingTopFactor = Utilities.boundToRange(PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getDrawerPaddingTopFactor()), 1f, 2f); this.inv = inv; mDeviceProperties = DeviceProperties.Factory.createDeviceProperties( @@ -392,7 +392,7 @@ public class DeviceProfile { mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode; // Determine device posture. mInfo = info; - boolean isTaskBarEnabled = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getEnableTaskbarOnPhone()); + boolean isTaskBarEnabled = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getEnableTaskbarOnPhone()); boolean taskbarOrBubbleBarOnPhones = enableTinyTaskbar() || (enableBubbleBar() && enableBubbleBarOnPhones()); isTaskbarPresent = isTaskBarEnabled && (mDeviceProperties.isTablet() || (taskbarOrBubbleBarOnPhones && isGestureMode)) @@ -409,8 +409,8 @@ public class DeviceProfile { workspacePageIndicatorHeight = res.getDimensionPixelSize( R.dimen.workspace_page_indicator_height); - workspacePageIndicatorHeight *= PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getPageIndicatorHeightFactor()); + workspacePageIndicatorHeight *= PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getPageIndicatorHeightFactor()); mWorkspacePageIndicatorOverlapWorkspace = res.getDimensionPixelSize(R.dimen.workspace_page_indicator_overlap_workspace); @@ -507,7 +507,7 @@ public class DeviceProfile { workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x); - HotseatMode hotseatMode = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getHotseatMode()); + HotseatMode hotseatMode = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getHotseatMode()); boolean isQsbEnable = hotseatMode.getLayoutResourceId() != R.layout.empty_view; numShownHotseatIcons = displayOptionSpec.numShownHotseatIcons; @@ -717,8 +717,8 @@ public class DeviceProfile { dimensionOverrideProvider.accept(this); // Check if notification dots should show the notification count - boolean showNotificationCount = PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getShowNotificationCount()); + boolean showNotificationCount = PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getShowNotificationCount()); // Load the default font to use on notification dots Typeface typeface = null; @@ -727,12 +727,12 @@ public class DeviceProfile { } // Load dot color - ColorOption dotColorOption = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getNotificationDotColor()); + ColorOption dotColorOption = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getNotificationDotColor()); int dotColor = dotColorOption.getColorPreferenceEntry().getLightColor().invoke(context); // Load counter color - ColorOption counterColorOption = PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getNotificationDotTextColor()); + ColorOption counterColorOption = PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getNotificationDotTextColor()); int countColor = counterColorOption.getColorPreferenceEntry().getLightColor().invoke(context); // This is done last, after iconSizePx is calculated above. @@ -880,7 +880,7 @@ public class DeviceProfile { /** Updates hotseatCellHeightPx and hotseatBarSizePx */ private void updateHotseatSizes(int hotseatIconSizePx) { int iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx); - boolean isLabelInDock = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getEnableLabelInDock()); + boolean isLabelInDock = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getEnableLabelInDock()); // Ensure there is enough space for folder icons, which have a slightly larger radius. hotseatCellHeightPx = getIconSizeWithOverlap(hotseatIconSizePx * 2) - hotseatIconSizePx / 2; hotseatCellHeightPx += isLabelInDock ? iconTextHeight : 0; @@ -888,8 +888,8 @@ public class DeviceProfile { int space = Math.abs(hotseatCellHeightPx / 2) - 16; - hotseatBarBottomSpacePx *= PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getHotseatBottomFactor()); + hotseatBarBottomSpacePx *= PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getHotseatBottomFactor()); if (isVerticalBarLayout()) { hotseatBarSizePx = hotseatIconSizePx + getHotseatProfile().getBarEdgePaddingPx() @@ -906,7 +906,7 @@ public class DeviceProfile { + hotseatBarBottomSpacePx + space; } - var isHotseatEnabled = PreferenceExtensionsKt.firstBlocking(preferenceManager2.isHotseatEnabled()); + var isHotseatEnabled = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.isHotseatEnabled()); if (!isHotseatEnabled) { hotseatBarSizePx = 0; } @@ -1413,8 +1413,8 @@ public class DeviceProfile { Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding - (getAllAppsProfile().getBorderSpacePx().x / 2)); } - var allAppLeftRightMarginMultiplier = PreferenceExtensionsKt - .firstBlocking(preferenceManager2.getDrawerLeftRightMarginFactor()); + var allAppLeftRightMarginMultiplier = PreferenceCacheExtensionsKt + .firstCached(preferenceManager2.getDrawerLeftRightMarginFactor()); var marginMultiplier = allAppLeftRightMarginMultiplier * (!getDeviceProperties().isTablet() ? 100 : 2); allAppsLeftRightMargin = (int) (allAppsLeftRightMargin * marginMultiplier); diff --git a/src/com/android/launcher3/FastScrollRecyclerView.java b/src/com/android/launcher3/FastScrollRecyclerView.java index 456dbc4eed..976469242e 100644 --- a/src/com/android/launcher3/FastScrollRecyclerView.java +++ b/src/com/android/launcher3/FastScrollRecyclerView.java @@ -31,7 +31,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.compat.AccessibilityManagerCompat; import com.android.launcher3.views.RecyclerViewFastScroller; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; /** @@ -99,7 +99,7 @@ public abstract class FastScrollRecyclerView extends RecyclerView { * Saved the scroll position */ public void saveScrollPosition() { - savedScrollPosition = PreferenceExtensionsKt.firstBlocking(pref2.getRememberPosition()) + savedScrollPosition = PreferenceCacheExtensionsKt.firstCached(pref2.getRememberPosition()) ? computeVerticalScrollOffset() : 0; } diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index ff6b5b548f..d79d98636a 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -62,7 +62,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import com.hoko.blur.HokoBlur; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.hotseat.DisabledHotseat; import app.lawnchair.hotseat.HotseatMode; import app.lawnchair.hotseat.LawnchairHotseat; @@ -128,8 +128,8 @@ public class Hotseat extends CellLayout implements Insettable { preferenceManager2 = PreferenceManager2.getInstance(context); preferenceManager = PreferenceManager.getInstance(context); - HotseatMode hotseatMode = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getHotseatMode()); - var hotseatEnabled = PreferenceExtensionsKt.firstBlocking(preferenceManager2.isHotseatEnabled()); + HotseatMode hotseatMode = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getHotseatMode()); + var hotseatEnabled = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.isHotseatEnabled()); if (!hotseatEnabled) { hotseatMode = DisabledHotseat.INSTANCE; @@ -139,7 +139,7 @@ public class Hotseat extends CellLayout implements Insettable { // The current hotseat mode is not available, // setting the hotseat mode to one that is always available hotseatMode = LawnchairHotseat.INSTANCE; - PreferenceExtensionsKt.setBlocking(preferenceManager2.getHotseatMode(), hotseatMode); + com.patrykmichalik.opto.core.PreferenceExtensionsKt.setBlocking(preferenceManager2.getHotseatMode(), hotseatMode); } int layoutId = hotseatMode.getLayoutResourceId(); @@ -170,7 +170,7 @@ public class Hotseat extends CellLayout implements Insettable { private void setUpBackground() { if(!preferenceManager.getHotseatBG().get()) return; - var bgColor = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getHotseatBackgroundColor()); + var bgColor = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getHotseatBackgroundColor()); var transparency = preferenceManager.getHotseatBGAlpha().get(); var alphaValue = (transparency * 255) / 100; var baseColor = bgColor.getColorPreferenceEntry().getLightColor().invoke(getContext()); diff --git a/src/com/android/launcher3/LauncherRootView.java b/src/com/android/launcher3/LauncherRootView.java index fdae191d48..b78ecaae5e 100644 --- a/src/com/android/launcher3/LauncherRootView.java +++ b/src/com/android/launcher3/LauncherRootView.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.List; import com.hoko.blur.HokoBlur; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences.PreferenceManager; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.util.FileAccessManager; @@ -61,7 +61,7 @@ public class LauncherRootView extends InsettableFrameLayout { pref = PreferenceManager.getInstance(context); PreferenceManager2 prefs2 = PreferenceManager2.getInstance(context); - mEnableTaskbarOnPhone = PreferenceExtensionsKt.firstBlocking(prefs2.getEnableTaskbarOnPhone()); + mEnableTaskbarOnPhone = PreferenceCacheExtensionsKt.firstCached(prefs2.getEnableTaskbarOnPhone()); FileAccessManager fileAccessManager = FileAccessManager.getInstance(context); FileAccessState wallpaperAccessState = fileAccessManager.getWallpaperAccessState().getValue(); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index a305c2c1c7..d51570f075 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -63,7 +63,7 @@ import com.android.launcher3.util.IntSet; import com.android.launcher3.util.Thunk; import com.android.launcher3.views.ActivityContext; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.ArrayList; import java.util.function.Consumer; @@ -1423,7 +1423,7 @@ public abstract class PagedView extends ViewGrou // move to the left and fling to the right will register as a fling to the right. boolean infiniteScroll = prefs.getInfiniteScrolling().get(); - boolean enableFeed = PreferenceExtensionsKt.firstBlocking(prefs2.getEnableFeed()); + boolean enableFeed = PreferenceCacheExtensionsKt.firstCached(prefs2.getEnableFeed()); if (((isSignificantMove && !isDeltaLeft && !isFling) || (isFling && !isVelocityLeft)) && mCurrentPage > 0) { diff --git a/src/com/android/launcher3/SessionCommitReceiver.java b/src/com/android/launcher3/SessionCommitReceiver.java index ce094670db..24ef9fb2d8 100644 --- a/src/com/android/launcher3/SessionCommitReceiver.java +++ b/src/com/android/launcher3/SessionCommitReceiver.java @@ -32,8 +32,7 @@ import com.android.launcher3.model.ItemInstallQueue; import com.android.launcher3.pm.InstallSessionHelper; import com.android.launcher3.pm.UserCache; import com.android.launcher3.util.Executors; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; - +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; import java.util.Locale; @@ -112,10 +111,12 @@ public class SessionCommitReceiver extends BroadcastReceiver { */ public static boolean isEnabled(Context context, UserHandle user) { if (Flags.privateSpaceRestrictItemDrag() - && PreferenceExtensionsKt.firstBlocking(PreferenceManager2.getInstance(context).getLockHomeScreen()) - && user != null - && UserCache.getInstance(context).getUserInfo(user).isPrivate()) { - return false; + && user != null) { + PreferenceManager2 prefs2 = PreferenceManager2.getInstance(context); + if (PreferenceCacheExtensionsKt.firstCached(prefs2.getLockHomeScreen()) + && UserCache.getInstance(context).getUserInfo(user).isPrivate()) { + return false; + } } return LauncherPrefs.getPrefs(context).getBoolean(ADD_ICON_PREFERENCE_KEY, true); } diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index 881adfc69a..1bf80c4172 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -43,7 +43,7 @@ import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.NavigableAppWidgetHostView; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; @@ -87,7 +87,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - boolean mAllowWidgetOverlap = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getAllowWidgetOverlap()); + boolean mAllowWidgetOverlap = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getAllowWidgetOverlap()); setClipChildren(!mAllowWidgetOverlap); setClipToPadding(!mAllowWidgetOverlap); setClipToOutline(!mAllowWidgetOverlap); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 2e2f7e5e87..1635c9ea05 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -145,7 +145,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import static app.lawnchair.util.LawnchairUtilsKt.toBitmap; import app.lawnchair.LawnchairApp; import app.lawnchair.LawnchairAppKt; @@ -612,7 +612,7 @@ public class Workspace extends PagedView } public void updateStatusbarClock() { - if (mCurrentPage == 0 && PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getStatusBarClock())) { + if (mCurrentPage == 0 && PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getStatusBarClock())) { LawnchairAppKt.getLawnchairApp(mLauncher).hideClockInStatusBar(); } else { LawnchairAppKt.getLawnchairApp(mLauncher).restoreClockInStatusBar(); @@ -662,18 +662,18 @@ public class Workspace extends PagedView public void bindAndInitFirstWorkspaceScreen() { // Add the first page CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, getChildCount()); - if (!PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getEnableSmartspace())) { + if (!PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getEnableSmartspace())) { mFirstPagePinnedItem = null; return; } if (mFirstPagePinnedItem == null) { - SmartspaceMode smartspaceMode = PreferenceExtensionsKt - .firstBlocking(mPreferenceManager2.getSmartspaceMode()); + SmartspaceMode smartspaceMode = PreferenceCacheExtensionsKt + .firstCached(mPreferenceManager2.getSmartspaceMode()); if (!smartspaceMode.isAvailable(this.mLauncher)) { // The current smartspace mode is not available, // setting the smartspace mode to one that is always available smartspaceMode = LawnchairSmartspace.INSTANCE; - PreferenceExtensionsKt.setBlocking(mPreferenceManager2.getSmartspaceMode(), smartspaceMode); + com.patrykmichalik.opto.core.PreferenceExtensionsKt.setBlocking(mPreferenceManager2.getSmartspaceMode(), smartspaceMode); } // In transposed layout, we add the first page pinned widget in the Grid. // As workspace does not touch the edges, we do not need a full @@ -1113,7 +1113,7 @@ public class Workspace extends PagedView id, persistedScreenIds, isExtraEmptyScreen(id))) { continue; } - if ((!PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(getContext()).getEnableSmartspace()) || id > FIRST_SCREEN_ID) + if ((!PreferenceCacheExtensionsKt.firstCached(PreferenceManager2.INSTANCE.get(getContext()).getEnableSmartspace(), PreferenceManager2.INSTANCE.get(getContext())) || id > FIRST_SCREEN_ID) && cl.getShortcutsAndWidgets().getChildCount() == 0) { removeScreens.add(id); } @@ -1174,7 +1174,7 @@ public class Workspace extends PagedView updateAccessibilityViewPageDescription(); // Reset default home page if it's now out of range after page removal - int storedDefault = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getDefaultHomePage()); + int storedDefault = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getDefaultHomePage()); if (storedDefault >= getChildCount()) { setDefaultPage(DEFAULT_PAGE); } @@ -1494,7 +1494,7 @@ public class Workspace extends PagedView public void showPageIndicatorAtCurrentScroll() { if (mPageIndicator != null) { mPageIndicator.setScroll(getScrollX(), computeMaxScroll()); - var isHotseatEnabled = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.isHotseatEnabled()); + var isHotseatEnabled = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.isHotseatEnabled()); mPageIndicator.setVisibility(isHotseatEnabled ? VISIBLE : INVISIBLE); } } @@ -1940,7 +1940,7 @@ public class Workspace extends PagedView } } - boolean lockHomeScreen = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getLockHomeScreen()); + boolean lockHomeScreen = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getLockHomeScreen()); if (lockHomeScreen) { child.setVisibility(View.VISIBLE); @@ -2226,7 +2226,7 @@ public class Workspace extends PagedView boolean snappedToNewPage = false; boolean resizeOnDrop = false; Runnable onCompleteRunnable = null; - boolean forceWidgetResize = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getForceWidgetResize()); + boolean forceWidgetResize = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getForceWidgetResize()); if (d.dragSource != this || mDragInfo == null) { final int[] touchXY = new int[]{(int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1]}; @@ -3862,7 +3862,7 @@ public class Workspace extends PagedView * Falls back to {@link #DEFAULT_PAGE} if the stored page is out of range. */ public int getDefaultPage() { - int storedPage = PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getDefaultHomePage()); + int storedPage = PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getDefaultHomePage()); int pageCount = getChildCount(); if (storedPage >= 0 && storedPage < pageCount) { return storedPage; @@ -3874,7 +3874,7 @@ public class Workspace extends PagedView * Sets the given page index as the default home page. */ public void setDefaultPage(int pageIndex) { - PreferenceExtensionsKt.setBlocking(mPreferenceManager2.getDefaultHomePage(), pageIndex); + com.patrykmichalik.opto.core.PreferenceExtensionsKt.setBlocking(mPreferenceManager2.getDefaultHomePage(), pageIndex); } /** diff --git a/src/com/android/launcher3/WorkspaceLayoutManager.java b/src/com/android/launcher3/WorkspaceLayoutManager.java index a4ff5e2426..226aeceddf 100644 --- a/src/com/android/launcher3/WorkspaceLayoutManager.java +++ b/src/com/android/launcher3/WorkspaceLayoutManager.java @@ -28,7 +28,7 @@ import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.touch.ItemLongClickListener; import app.lawnchair.preferences2.PreferenceManager2; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import com.android.launcher3.util.IntSet; public interface WorkspaceLayoutManager { @@ -110,10 +110,10 @@ public interface WorkspaceLayoutManager { // Hide folder title in the hotseat if (child instanceof FolderIcon) { + PreferenceManager2 prefs = PreferenceManager2.getInstance(child.getContext()); ((FolderIcon) child).setTextVisible( - PreferenceExtensionsKt.firstBlocking( - PreferenceManager2.getInstance(child.getContext()) - .getEnableLabelInDock())); // LC-Note: Show/hide folder title based on dock label preference + PreferenceCacheExtensionsKt.firstCached( + prefs.getEnableLabelInDock())); } } else { // Show folder title if not in the hotseat diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java index 23d95c24ad..b578819aa7 100644 --- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java @@ -111,7 +111,7 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import static com.topjohnwu.superuser.internal.Utils.context; import app.lawnchair.allapps.LawnchairAlphabeticalAppsList; import app.lawnchair.font.FontManager; @@ -283,7 +283,7 @@ public class ActivityAllAppsContainerView * onFinishInflate -> onPostCreate */ protected void initContent() { - showFastScroller = PreferenceExtensionsKt.firstBlocking(pref2.getShowScrollbar()); + showFastScroller = PreferenceCacheExtensionsKt.firstCached(pref2.getShowScrollbar()); mMainAdapterProvider = mSearchUiDelegate.createMainAdapterProvider(); @@ -543,7 +543,7 @@ public class ActivityAllAppsContainerView */ public void reset(boolean animate, boolean exitSearch) { // Scroll Main and Work RV to top. Search RV is done in `resetSearch`. - if (!PreferenceExtensionsKt.firstBlocking(pref2.getRememberPosition())) { + if (!PreferenceCacheExtensionsKt.firstCached(pref2.getRememberPosition())) { for (int i = 0; i < mAH.size(); i++) { if (i != SEARCH && mAH.get(i).mRecyclerView != null) { mAH.get(i).mRecyclerView.scrollToTop(); @@ -817,7 +817,7 @@ public class ActivityAllAppsContainerView void setupHeader() { mAdditionalHeaderRows.forEach(row -> mHeader.onPluginDisconnected(row)); - var hideHeader = PreferenceExtensionsKt.firstBlocking(pref2.getHideAppDrawerSearchBar()); + var hideHeader = PreferenceCacheExtensionsKt.firstCached(pref2.getHideAppDrawerSearchBar()); mHeader.setVisibility(hideHeader ? View.GONE : View.VISIBLE); boolean tabsHidden = !mUsingTabs; mHeader.setup( @@ -870,12 +870,12 @@ public class ActivityAllAppsContainerView } protected void updateHeaderScroll(int scrolledOffset) { - if (PreferenceExtensionsKt.firstBlocking(pref2.getHideAppDrawerSearchBar())) + if (PreferenceCacheExtensionsKt.firstCached(pref2.getHideAppDrawerSearchBar())) return; // Check if tab container background should be shown - boolean showTabContainerBackground = PreferenceExtensionsKt.firstBlocking( - pref2.getWorkProfileTabContainerBackground()); + boolean showTabContainerBackground = PreferenceCacheExtensionsKt.firstCached( + pref2.getWorkProfileTabContainerBackground(), pref2); float prog = Utilities.boundToRange((float) scrolledOffset / mHeaderThreshold, 0f, 1f); int headerColor = getHeaderColor(prog); @@ -904,8 +904,8 @@ public class ActivityAllAppsContainerView protected int getHeaderColor(float blendRatio) { if (!mActivityContext.getDeviceProfile().shouldShowAllAppsOnSheet()) { float opacity = mSearchContainer.getAlpha(); - var showHeaderBackground = PreferenceExtensionsKt.firstBlocking( - pref2.getAppDrawerSearchBarBackground()); + var showHeaderBackground = PreferenceCacheExtensionsKt.firstCached( + pref2.getAppDrawerSearchBarBackground(), pref2); if (showHeaderBackground) { opacity = pref.getDrawerOpacity().get(); } @@ -1034,7 +1034,7 @@ public class ActivityAllAppsContainerView private void alignParentTop(View v, boolean includeTabsMargin) { if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams) - || PreferenceExtensionsKt.firstBlocking(pref2.getHideAppDrawerSearchBar())) { + || PreferenceCacheExtensionsKt.firstCached(pref2.getHideAppDrawerSearchBar())) { return; } @@ -1049,7 +1049,7 @@ public class ActivityAllAppsContainerView private void removeCustomRules(View v) { if (!(v.getLayoutParams() instanceof RelativeLayout.LayoutParams) - || PreferenceExtensionsKt.firstBlocking(pref2.getHideAppDrawerSearchBar())) { + || PreferenceCacheExtensionsKt.firstCached(pref2.getHideAppDrawerSearchBar())) { return; } diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java index c0472ded4b..9f62bd66c3 100644 --- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java +++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java @@ -67,7 +67,7 @@ import com.android.launcher3.views.ScrimView; import com.google.android.msdl.data.model.MSDLToken; import app.lawnchair.preferences2.PreferenceManager2; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; /** * Handles AllApps view transition. @@ -404,8 +404,9 @@ public class AllAppsTransitionController setAlphas(toState, config, builder); // This controls both haptics for tapping on QSB and going to all apps. if (ALL_APPS.equals(toState) && mLauncher.isInState(NORMAL)) { - boolean hapticEnabled = PreferenceExtensionsKt.firstBlocking( - PreferenceManager2.getInstance(mLauncher).getAppDrawerHapticFeedback()); + PreferenceManager2 prefs = PreferenceManager2.getInstance(mLauncher); + boolean hapticEnabled = PreferenceCacheExtensionsKt.firstCached( + prefs.getAppDrawerHapticFeedback(), prefs); if (hapticEnabled) { if (Flags.msdlFeedback()) { diff --git a/src/com/android/launcher3/allapps/FloatingHeaderView.java b/src/com/android/launcher3/allapps/FloatingHeaderView.java index fe95c4abf4..5dee5c4eb1 100644 --- a/src/com/android/launcher3/allapps/FloatingHeaderView.java +++ b/src/com/android/launcher3/allapps/FloatingHeaderView.java @@ -42,7 +42,7 @@ import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip; import com.android.systemui.plugins.AllAppsRow; import com.android.systemui.plugins.AllAppsRow.OnHeightUpdatedListener; import com.android.systemui.plugins.PluginListener; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.ArrayList; import java.util.Arrays; @@ -405,7 +405,7 @@ public class FloatingHeaderView extends LinearLayout implements } mHeaderCollapsed = false; mSnappedScrolledY = -mMaxTranslation; - if (!PreferenceExtensionsKt.firstBlocking (pref2.getRememberPosition ())) { + if (!PreferenceCacheExtensionsKt.firstCached(pref2.getRememberPosition())) { mCurrentRV.scrollToTop(); } } diff --git a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java index a56d0811c1..0d71f4beb0 100644 --- a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java +++ b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.stream.Collectors; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; /** * Contains the logic of a reorder. @@ -134,7 +134,7 @@ public class ReorderAlgorithm { Rect occupiedRect = new Rect(cellX, cellY, cellX + spanX, cellY + spanY); // Lawnchair: Widget overlap - if (PreferenceExtensionsKt.firstBlocking(mCellLayout.pref.getAllowWidgetOverlap())) { + if (PreferenceCacheExtensionsKt.firstCached(mCellLayout.pref.getAllowWidgetOverlap(), mCellLayout.pref)) { solution.intersectingViews = new ArrayList<>(intersectingViews); return true; } diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index 6ba2b3dce0..41d8fb767a 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -44,7 +44,7 @@ import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.TouchController; import com.android.launcher3.views.ActivityContext; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.ArrayList; import java.util.Optional; @@ -558,7 +558,7 @@ public abstract class DragController dropTarget.onDrop(mDragObject, mOptions); } accepted = true; - if (PreferenceExtensionsKt.firstBlocking(pref2.getDeckLayout()) && dropTarget instanceof DeleteDropTarget && + if (PreferenceCacheExtensionsKt.firstCached(pref2.getDeckLayout()) && dropTarget instanceof DeleteDropTarget && isNeedCancelDrag(mDragObject.dragInfo)) { cancelDrag(); } diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java index 63d9e27747..0ad5bb8096 100644 --- a/src/com/android/launcher3/folder/FolderAnimationManager.java +++ b/src/com/android/launcher3/folder/FolderAnimationManager.java @@ -53,7 +53,7 @@ import com.android.launcher3.graphics.ThemeManager; import com.android.launcher3.util.Themes; import com.android.launcher3.views.BaseDragLayer; import com.androidinternal.graphics.ColorUtils; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.List; @@ -197,7 +197,7 @@ public class FolderAnimationManager implements FolderAnimationCreator { int initialColor = ColorUtils.setAlphaComponent(previewColor, LawnchairUtilsKt.getFolderPreviewAlpha(mContext)); int finalColor = ColorTokens.FolderBackgroundColor.resolveColor(mContext); - ColorOption colorOption = PreferenceExtensionsKt.firstBlocking(mFolder.preferenceManager2.getFolderColor()); + ColorOption colorOption = PreferenceCacheExtensionsKt.firstCached(mFolder.preferenceManager2.getFolderColor(), mFolder.preferenceManager2); int folderColor = colorOption.getColorPreferenceEntry().getLightColor().invoke(mContext); if (folderColor != 0) { @@ -530,4 +530,4 @@ public class FolderAnimationManager implements FolderAnimationCreator { ? ((AppPairIcon) v).getTitleTextView() : (BubbleTextView) v; } -} \ No newline at end of file +} diff --git a/src/com/android/launcher3/folder/FolderNameEditText.java b/src/com/android/launcher3/folder/FolderNameEditText.java index b87207900f..6254588133 100644 --- a/src/com/android/launcher3/folder/FolderNameEditText.java +++ b/src/com/android/launcher3/folder/FolderNameEditText.java @@ -27,7 +27,7 @@ import android.view.inputmethod.InputConnectionWrapper; import android.view.inputmethod.InputMethodManager; import com.android.launcher3.ExtendedEditText; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.List; @@ -139,7 +139,7 @@ public class FolderNameEditText extends ExtendedEditText { @Override public boolean onTouchEvent(MotionEvent event) { - if (PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getLockHomeScreen())) return true; + if (PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getLockHomeScreen())) return true; return super.onTouchEvent(event); } } diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java index 352154288d..9328747edc 100644 --- a/src/com/android/launcher3/folder/PreviewBackground.java +++ b/src/com/android/launcher3/folder/PreviewBackground.java @@ -56,7 +56,7 @@ import com.android.launcher3.graphics.ShapeDelegate; import com.android.launcher3.graphics.ThemeManager; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.ColorOption; @@ -192,11 +192,11 @@ public class PreviewBackground extends DelegatedCellDrawing { PreferenceManager2 preferenceManager2 = PreferenceManager2.INSTANCE.get(context); // Load folder color - ColorOption colorOption = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getFolderColor()); + ColorOption colorOption = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getFolderColor()); int folderColor = colorOption.getColorPreferenceEntry().getLightColor().invoke(context); TypedArray ta = context.getTheme().obtainStyledAttributes(R.styleable.FolderIconPreview); - ColorOption dotColorOption = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getNotificationDotColor()); + ColorOption dotColorOption = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getNotificationDotColor()); mDotColor = dotColorOption.getColorPreferenceEntry().getLightColor().invoke(context); mStrokeColor = ColorTokens.FolderIconBorderColor.resolveColor(context); if (folderColor != 0) { diff --git a/src/com/android/launcher3/model/DatabaseHelper.java b/src/com/android/launcher3/model/DatabaseHelper.java index d68ac79319..33f4aef50e 100644 --- a/src/com/android/launcher3/model/DatabaseHelper.java +++ b/src/com/android/launcher3/model/DatabaseHelper.java @@ -53,7 +53,8 @@ import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Thunk; import com.android.launcher3.widget.LauncherWidgetHolder; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; +import app.lawnchair.preferences2.PreferenceManager2; import java.io.File; import java.net.URISyntaxException; import java.util.Arrays; @@ -259,7 +260,8 @@ public class DatabaseHelper extends NoLocaleSQLiteHelper implements Favorites.SCREEN, IntArray.wrap(-777, -778)), null); } case 30: { - if (PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(mContext).getEnableSmartspace())) { + PreferenceManager2 prefs = PreferenceManager2.INSTANCE.get(mContext); + if (PreferenceCacheExtensionsKt.firstCached(prefs.getEnableSmartspace())) { // Clean up first row in screen 0 as it might contain junk data. Log.d(TAG, "Cleaning up first row"); db.delete(Favorites.TABLE_NAME, diff --git a/src/com/android/launcher3/model/GridSizeMigrationDBController.java b/src/com/android/launcher3/model/GridSizeMigrationDBController.java index 8352b2c377..c53d476641 100644 --- a/src/com/android/launcher3/model/GridSizeMigrationDBController.java +++ b/src/com/android/launcher3/model/GridSizeMigrationDBController.java @@ -55,7 +55,7 @@ import com.android.launcher3.util.IntArray; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; import com.android.launcher3.widget.WidgetManagerHelper; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -400,7 +400,7 @@ public class GridSizeMigrationDBController { @NonNull final List sortedItemsToPlace, List idsInUse, Context context) { PreferenceManager2 prefs2 = PreferenceManager2.INSTANCE.get(context); - boolean smartspaceEnabled = PreferenceExtensionsKt.firstBlocking(prefs2.getEnableSmartspace()); + boolean smartspaceEnabled = PreferenceCacheExtensionsKt.firstCached(prefs2.getEnableSmartspace()); final GridOccupancy occupied = new GridOccupancy(trgX, trgY); final Point trg = new Point(trgX, trgY); diff --git a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt index e33e64b31b..167620ad45 100644 --- a/src/com/android/launcher3/model/GridSizeMigrationLogic.kt +++ b/src/com/android/launcher3/model/GridSizeMigrationLogic.kt @@ -44,7 +44,7 @@ import com.android.launcher3.provider.LauncherDbUtils.shiftWorkspaceByXCells import com.android.launcher3.util.CellAndSpan import com.android.launcher3.util.GridOccupancy import com.android.launcher3.util.IntArray -import com.patrykmichalik.opto.core.firstBlocking +import app.lawnchair.preferences2.firstCached class GridSizeMigrationLogic { /** @@ -507,7 +507,7 @@ class GridSizeMigrationLogic { val prefs2 = PreferenceManager2.INSTANCE.get(context) val next: Point = - if (screenId == 0 && prefs2.enableSmartspace.firstBlocking()) { + if (screenId == 0 && prefs2.enableSmartspace.firstCached()) { Point(0, 1 /* smartspace */) } else { Point(0, 0) diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index d3c979302a..63fa296839 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -80,7 +80,7 @@ import dagger.assisted.AssistedInject; import java.net.URISyntaxException; import java.security.InvalidParameterException; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.LawnchairApp; import app.lawnchair.preferences2.PreferenceManager2; @@ -646,7 +646,7 @@ public class LoaderCursor extends CursorWrapper { if (!mOccupied.containsKey(item.screenId)) { GridOccupancy screen = new GridOccupancy(countX + 1, countY + 1); - if (item.screenId == Workspace.FIRST_SCREEN_ID && PreferenceExtensionsKt.firstBlocking(preferenceManager2.getEnableSmartspace())) { + if (item.screenId == Workspace.FIRST_SCREEN_ID && PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getEnableSmartspace())) { // Mark the first X columns (X is width of the search container) in the first row as // occupied (if the feature is enabled) in order to account for the search // container. @@ -667,7 +667,7 @@ public class LoaderCursor extends CursorWrapper { + " into cell (" + containerIndex + "-" + item.screenId + ":" + item.cellX + "," + item.cellX + "," + item.spanX + "," + item.spanY + ") already occupied"); - return PreferenceExtensionsKt.firstBlocking(preferenceManager2.getAllowWidgetOverlap()); + return PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getAllowWidgetOverlap()); } } diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index 10821dfcea..8cdd1dad69 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -72,7 +72,7 @@ import java.util.stream.Collectors; import app.lawnchair.deck.LawndeckManager; import app.lawnchair.preferences.PreferenceManager; import app.lawnchair.preferences2.PreferenceManager2; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; /** * Handles updates due to changes in package manager (app installed/updated/removed) @@ -465,7 +465,7 @@ public class PackageUpdatedTask implements ModelUpdateTask { // If deck layout is enabled, add newly installed apps to workspace with categorization PreferenceManager2 pref2 = PreferenceManager2.INSTANCE.get(context); - if (PreferenceExtensionsKt.firstBlocking(pref2.getDeckLayout())) { + if (PreferenceCacheExtensionsKt.firstCached(pref2.getDeckLayout())) { LawndeckManager deckManager = new LawndeckManager(context); ModelWriter modelWriter = taskController.getModelWriter(); for (int i = 0; i < packageCount; i++) { diff --git a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java index 5db08169a8..e1f9be88fe 100644 --- a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java +++ b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java @@ -31,7 +31,8 @@ import com.android.launcher3.util.GridOccupancy; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; +import app.lawnchair.preferences2.PreferenceManager2; import java.util.ArrayList; import javax.inject.Inject; @@ -97,7 +98,8 @@ public class WorkspaceItemSpaceFinder { // First check the preferred screen. IntSet screensToExclude = new IntSet(); - boolean smartspaceEnabled = PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(context).getEnableSmartspace()); + PreferenceManager2 prefs = PreferenceManager2.INSTANCE.get(context); + boolean smartspaceEnabled = PreferenceCacheExtensionsKt.firstCached(prefs.getEnableSmartspace()); if (smartspaceEnabled) { screensToExclude.add(FIRST_SCREEN_ID); } diff --git a/src/com/android/launcher3/model/data/WorkspaceData.kt b/src/com/android/launcher3/model/data/WorkspaceData.kt index 7cd52f6811..ee5cd44c74 100644 --- a/src/com/android/launcher3/model/data/WorkspaceData.kt +++ b/src/com/android/launcher3/model/data/WorkspaceData.kt @@ -33,7 +33,7 @@ import com.android.launcher3.model.data.WorkspaceChangeEvent.UpdateEvent import com.android.launcher3.util.IntArray import com.android.launcher3.util.IntSet import com.android.launcher3.util.ItemInfoMatcher -import com.patrykmichalik.opto.core.firstBlocking +import app.lawnchair.preferences2.firstCached import java.util.concurrent.atomic.AtomicInteger import java.util.stream.Stream import java.util.stream.StreamSupport @@ -48,7 +48,7 @@ sealed class WorkspaceData : Iterable { // LC-Note: Add context to replace QSB_ON_FIRST_SCREEN config fun collectWorkspaceScreens(context: Context): IntArray { val prefs2 = PreferenceManager2.INSTANCE.get(context) - val smartspaceEnabled = prefs2.enableSmartspace.firstBlocking() + val smartspaceEnabled = prefs2.enableSmartspace.firstCached() val screenSet = IntSet() forEach { if (it.container == CONTAINER_DESKTOP) screenSet.add(it.screenId) } diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index a01ea5fa57..5198185bdb 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -52,7 +52,7 @@ import com.android.launcher3.widget.picker.model.data.WidgetPickerData; import java.net.URISyntaxException; import java.util.Arrays; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; /** @@ -136,7 +136,7 @@ public abstract class SystemShortcut extends ItemInfo private static boolean isHomeLocked(ActivityContext context) { PreferenceManager2 prefs = PreferenceManager2.getInstance(context.asContext()); - return PreferenceExtensionsKt.firstBlocking(prefs.getLockHomeScreen()); + return PreferenceCacheExtensionsKt.firstCached(prefs.getLockHomeScreen()); } public static final Factory WIDGETS = (context, itemInfo, originalView) -> { diff --git a/src/com/android/launcher3/preview/LauncherPreviewRenderer.java b/src/com/android/launcher3/preview/LauncherPreviewRenderer.java index 8fff605590..83fd79d11f 100644 --- a/src/com/android/launcher3/preview/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/preview/LauncherPreviewRenderer.java @@ -79,7 +79,7 @@ import com.android.launcher3.util.window.WindowManagerProxy; import com.android.launcher3.views.BaseDragLayer; import com.android.launcher3.widget.LauncherWidgetHolder; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -345,7 +345,7 @@ public class LauncherPreviewRenderer extends BaseContext populateHotseatPredictions(itemIdMap); // Add first page QSB - if (PreferenceExtensionsKt.firstBlocking(mPreferenceManager2.getEnableSmartspace())) { + if (PreferenceCacheExtensionsKt.firstCached(mPreferenceManager2.getEnableSmartspace())) { CellLayout firstScreen = mWorkspaceScreens.get(FIRST_SCREEN_ID); if (firstScreen != null) { View qsb = mHomeElementInflater.inflate(mWorkspaceSearchContainer, firstScreen, false); diff --git a/src/com/android/launcher3/util/Themes.java b/src/com/android/launcher3/util/Themes.java index 2723593ec5..05e4be06d3 100644 --- a/src/com/android/launcher3/util/Themes.java +++ b/src/com/android/launcher3/util/Themes.java @@ -36,7 +36,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.views.ActivityContext; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences.PreferenceManager; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.theme.color.ColorMode; @@ -68,7 +68,7 @@ public class Themes { public static int getActivityThemeRes(Context context, int wallpaperColorHints) { PreferenceManager2 prefs2 = PreferenceManager2.getInstance(context); - ColorMode colorMode = PreferenceExtensionsKt.firstBlocking(prefs2.getWorkspaceTextColor()); + ColorMode colorMode = PreferenceCacheExtensionsKt.firstCached(prefs2.getWorkspaceTextColor()); boolean supportsDarkText = (wallpaperColorHints & HINT_SUPPORTS_DARK_TEXT) != 0; boolean isMainColorDark = (wallpaperColorHints & HINT_SUPPORTS_DARK_THEME) != 0; diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java index 8c462ba13a..664e1d6fd9 100644 --- a/src/com/android/launcher3/views/OptionsPopupView.java +++ b/src/com/android/launcher3/views/OptionsPopupView.java @@ -57,7 +57,7 @@ import com.android.launcher3.testing.shared.TestProtocol; import java.util.ArrayList; import java.util.List; -import com.patrykmichalik.opto.core.PreferenceExtensionsKt; +import app.lawnchair.preferences2.PreferenceCacheExtensionsKt; import app.lawnchair.preferences2.PreferenceManager2; import app.lawnchair.ui.popup.LauncherOptionsPopup; @@ -274,8 +274,8 @@ public class OptionsPopupView extends Arrow private static boolean toggleHomeScreenLock(View v) { Context context = v.getContext(); PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(context); - boolean oldValue = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getLockHomeScreen()); - PreferenceExtensionsKt.setBlocking(preferenceManager2.getLockHomeScreen(), !oldValue); + boolean oldValue = PreferenceCacheExtensionsKt.firstCached(preferenceManager2.getLockHomeScreen()); + com.patrykmichalik.opto.core.PreferenceExtensionsKt.setBlocking(preferenceManager2.getLockHomeScreen(), !oldValue); return true; }