Migrate “pref_showSysUiScrim” to Preferences DataStore
This commit is contained in:
@@ -75,7 +75,6 @@ class PreferenceManager private constructor(private val context: Context) : Base
|
||||
val windowCornerRadius = IntPref("pref_windowCornerRadius", 80, recreate)
|
||||
val autoLaunchRoot = BoolPref("pref_autoLaunchRoot", false)
|
||||
val wallpaperScrolling = BoolPref("pref_wallpaperScrolling", true)
|
||||
val showSysUiScrim = BoolPref("pref_showSysUiScrim", true)
|
||||
val allAppsIconLabels = BoolPref("pref_allAppsIconLabels", true, reloadGrid)
|
||||
val searchAutoShowKeyboard = BoolPref("pref_searchAutoShowKeyboard", false)
|
||||
val enableDebugMenu = BoolPref("pref_enableDebugMenu", false)
|
||||
|
||||
@@ -86,6 +86,11 @@ class PreferenceManager2(private val context: Context) : PreferenceManager {
|
||||
defaultValue = true,
|
||||
)
|
||||
|
||||
val showTopShadow = preference(
|
||||
key = booleanPreferencesKey(name = "show_top_shadow"),
|
||||
defaultValue = true,
|
||||
)
|
||||
|
||||
companion object {
|
||||
private val Context.preferencesDataStore by preferencesDataStore(
|
||||
name = "preferences",
|
||||
|
||||
@@ -30,7 +30,7 @@ class SharedPreferencesMigration(private val context: Context) {
|
||||
"pref_darkStatusBar" to "dark_status_bar", "pref_dockSearchBar" to "dock_search_bar",
|
||||
"pref_iconShape" to "icon_shape", "pref_themedHotseatQsb" to "themed_hotseat_qsb",
|
||||
"pref_accentColor2" to "accent_color", "hidden-app-set" to "hidden_apps",
|
||||
"pref_showStatusBar" to "show_status_bar",
|
||||
"pref_showStatusBar" to "show_status_bar", "pref_showSysUiScrim" to "show_top_shadow",
|
||||
)
|
||||
|
||||
fun produceMigration() = androidx.datastore.migrations.SharedPreferencesMigration(
|
||||
|
||||
@@ -49,6 +49,7 @@ interface HomeScreenPreferenceCollectorScope : PreferenceCollectorScope {
|
||||
val darkStatusBar: Boolean
|
||||
val roundedWidgets: Boolean
|
||||
val showStatusBar: Boolean
|
||||
val showTopShadow: Boolean
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -57,11 +58,16 @@ fun HomeScreenPreferenceCollector(content: @Composable HomeScreenPreferenceColle
|
||||
val darkStatusBar by preferenceManager.darkStatusBar.state()
|
||||
val roundedWidgets by preferenceManager.roundedWidgets.state()
|
||||
val showStatusBar by preferenceManager.showStatusBar.state()
|
||||
ifNotNull(darkStatusBar, roundedWidgets, showStatusBar) {
|
||||
val showTopShadow by preferenceManager.showTopShadow.state()
|
||||
ifNotNull(
|
||||
darkStatusBar, roundedWidgets,
|
||||
showStatusBar, showTopShadow,
|
||||
) {
|
||||
object : HomeScreenPreferenceCollectorScope {
|
||||
override val darkStatusBar = it[0] as Boolean
|
||||
override val roundedWidgets = it[1] as Boolean
|
||||
override val showStatusBar = it[2] as Boolean
|
||||
override val showTopShadow: Boolean = it[3] as Boolean
|
||||
override val coroutineScope = rememberCoroutineScope()
|
||||
override val preferenceManager = preferenceManager
|
||||
}.content()
|
||||
@@ -120,9 +126,10 @@ fun HomeScreenPreferences() {
|
||||
label = stringResource(id = R.string.show_status_bar),
|
||||
edit = { showStatusBar.set(value = it) },
|
||||
)
|
||||
SwitchPreference(
|
||||
prefs.showSysUiScrim.getAdapter(),
|
||||
SwitchPreference2(
|
||||
checked = showTopShadow,
|
||||
label = stringResource(id = R.string.show_sys_ui_scrim),
|
||||
edit = { showTopShadow.set(value = it) },
|
||||
)
|
||||
}
|
||||
PreferenceGroup(heading = stringResource(id = R.string.icons)) {
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Modifications copyright 2022, Lawnchair
|
||||
*/
|
||||
|
||||
package com.android.launcher3.graphics;
|
||||
@@ -49,8 +51,10 @@ import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.util.DynamicResource;
|
||||
import com.android.launcher3.util.Themes;
|
||||
import com.android.systemui.plugins.ResourceProvider;
|
||||
import com.patrykmichalik.preferencemanager.PreferenceExtensionsKt;
|
||||
|
||||
import app.lawnchair.preferences.PreferenceManager;
|
||||
import app.lawnchair.preferences2.PreferenceManager2;
|
||||
import app.lawnchair.util.ViewExtensionsKt;
|
||||
|
||||
/**
|
||||
* View scrim which draws behind hotseat and workspace
|
||||
@@ -145,11 +149,16 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
|
||||
|
||||
view.addOnAttachStateChangeListener(this);
|
||||
|
||||
PreferenceManager prefs = PreferenceManager.getInstance(mRoot.getContext());
|
||||
prefs.getShowSysUiScrim().subscribeValues(mRoot, (show) -> {
|
||||
mHideSysUiScrim = !show;
|
||||
mRoot.invalidate();
|
||||
});
|
||||
PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(mRoot.getContext());
|
||||
PreferenceExtensionsKt.onEach(
|
||||
preferenceManager2.getShowTopShadow(),
|
||||
ViewExtensionsKt.getViewAttachedScope(mRoot),
|
||||
(showTopShadow) -> {
|
||||
mHideSysUiScrim = !showTopShadow;
|
||||
mRoot.invalidate();
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user