Update text & add Experimental Features screen to Settings
This commit is contained in:
@@ -204,4 +204,10 @@
|
||||
<string name="icon_pack_external_picker">Open External Picker</string>
|
||||
<string name="recents_actions_label">Quick Actions</string>
|
||||
<string name="recents_clear_all">Clear All</string>
|
||||
<string name="pick_icon_from_label">Pick Icon From</string>
|
||||
<string name="experimental_features_label">Experimental Features</string>
|
||||
<string name="icon_picker_label">Per-App Icon Customization</string>
|
||||
<string name="icon_picker_description">May cause Lawnchair to freeze.</string>
|
||||
<string name="font_picker_label">Font Customization</string>
|
||||
<string name="font_picker_description">Some text remains unchanged.</string>
|
||||
</resources>
|
||||
|
||||
@@ -17,4 +17,7 @@ interface IconOverrideDao {
|
||||
|
||||
@Query("SELECT * FROM iconoverride WHERE target = :target")
|
||||
fun observeTarget(target: ComponentKey): Flow<IconOverride?>
|
||||
|
||||
@Query("DELETE FROM iconoverride")
|
||||
fun deleteAll()
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ class IconOverrideRepository(private val context: Context) {
|
||||
|
||||
fun observeTarget(target: ComponentKey) = dao.observeTarget(target)
|
||||
|
||||
fun deleteAll() {
|
||||
dao.deleteAll()
|
||||
reloadIcons()
|
||||
}
|
||||
|
||||
private fun reloadIcons() {
|
||||
val las = LauncherAppState.getInstance(context)
|
||||
val idp = las.invariantDeviceProfile
|
||||
|
||||
@@ -133,6 +133,7 @@ class PreferenceManager private constructor(private val context: Context) : Base
|
||||
val recentsActionShare = BoolPref("pref_recentsActionShare", isOnePlusStock)
|
||||
val recentsActionLens = BoolPref("pref_recentsActionLens", true)
|
||||
val recentsActionClearAll = BoolPref("pref_clearAllAsAction", false)
|
||||
val enableFontSelection = BoolPref("pref_enableFontSelection", true)
|
||||
|
||||
init {
|
||||
sp.registerOnSharedPreferenceChangeListener(this)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package app.lawnchair.ui.preferences
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import app.lawnchair.data.iconoverride.IconOverrideRepository
|
||||
import app.lawnchair.font.FontCache
|
||||
import app.lawnchair.preferences.getAdapter
|
||||
import app.lawnchair.preferences.preferenceManager
|
||||
import app.lawnchair.ui.preferences.components.PreferenceGroup
|
||||
import app.lawnchair.ui.preferences.components.PreferenceLayout
|
||||
import app.lawnchair.ui.preferences.components.SwitchPreference
|
||||
import com.android.launcher3.R
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
fun NavGraphBuilder.experimentalFeaturesGraph(route: String) {
|
||||
preferenceGraph(route, { ExperimentalFeaturesPreferences() })
|
||||
}
|
||||
|
||||
@Composable
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
fun ExperimentalFeaturesPreferences() {
|
||||
val preferenceManager = preferenceManager()
|
||||
val context = LocalContext.current
|
||||
|
||||
PreferenceLayout(label = stringResource(id = R.string.experimental_features_label)) {
|
||||
PreferenceGroup(isFirstChild = true) {
|
||||
SwitchPreference(
|
||||
adapter = preferenceManager.enableFontSelection.getAdapter(),
|
||||
label = stringResource(id = R.string.font_picker_label),
|
||||
description = stringResource(id = R.string.font_picker_description),
|
||||
onChange = {
|
||||
if (!it) {
|
||||
val fontCache = FontCache.INSTANCE.get(context)
|
||||
preferenceManager.workspaceFont.set(newValue = fontCache.uiText)
|
||||
}
|
||||
}
|
||||
)
|
||||
SwitchPreference(
|
||||
adapter = preferenceManager.enableIconSelection.getAdapter(),
|
||||
label = stringResource(id = R.string.icon_picker_label),
|
||||
description = stringResource(id = R.string.icon_picker_description),
|
||||
onChange = {
|
||||
if (!it) {
|
||||
val iconOverrideRepository = IconOverrideRepository.INSTANCE.get(context)
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
iconOverrideRepository.deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,10 +70,12 @@ fun GeneralPreferences() {
|
||||
description = if (!themedIconsAvailable) stringResource(id = R.string.lawnicons_not_installed_description) else null
|
||||
)
|
||||
IconShapePreference()
|
||||
FontPreference(
|
||||
adapter = prefs.workspaceFont.getAdapter(),
|
||||
label = stringResource(id = R.string.font_label)
|
||||
)
|
||||
if (prefs.enableFontSelection.get()) {
|
||||
FontPreference(
|
||||
adapter = prefs.workspaceFont.getAdapter(),
|
||||
label = stringResource(id = R.string.font_label),
|
||||
)
|
||||
}
|
||||
}
|
||||
PreferenceGroup(
|
||||
heading = stringResource(id = R.string.colors)
|
||||
|
||||
@@ -48,6 +48,7 @@ object Routes {
|
||||
const val DEBUG_MENU: String = "debugMenu"
|
||||
const val SELECT_ICON: String = "selectIcon"
|
||||
const val ICON_PICKER: String = "iconPicker"
|
||||
const val EXPERIMENTAL_FEATURES: String = "experimentalFeatures"
|
||||
}
|
||||
|
||||
val LocalNavController = staticCompositionLocalOf<NavController> {
|
||||
@@ -94,6 +95,7 @@ fun Preferences(interactor: PreferenceInteractor = viewModel<PreferenceViewModel
|
||||
debugMenuGraph(route = subRoute(Routes.DEBUG_MENU))
|
||||
selectIconGraph(route = subRoute(Routes.SELECT_ICON))
|
||||
iconPickerGraph(route = subRoute(Routes.ICON_PICKER))
|
||||
experimentalFeaturesGraph(route = subRoute(Routes.EXPERIMENTAL_FEATURES))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +91,10 @@ fun PreferencesDashboard() {
|
||||
|
||||
@Composable
|
||||
fun PreferencesOverflowMenu() {
|
||||
val navController = LocalNavController.current
|
||||
val enableDebug by preferenceManager().enableDebugMenu.observeAsState()
|
||||
val experimentalFeaturesRoute = subRoute(name = Routes.EXPERIMENTAL_FEATURES)
|
||||
if (enableDebug) {
|
||||
val navController = LocalNavController.current
|
||||
val resolvedRoute = subRoute(name = Routes.DEBUG_MENU)
|
||||
ClickableIcon(
|
||||
imageVector = Icons.Rounded.Build,
|
||||
@@ -114,6 +115,12 @@ fun PreferencesOverflowMenu() {
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.debug_restart_launcher))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
navController.navigate(experimentalFeaturesRoute)
|
||||
hideMenu()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.experimental_features_label))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import app.lawnchair.ui.preferences.components.ClickablePreference
|
||||
import app.lawnchair.ui.preferences.components.PreferenceLayoutLazyColumn
|
||||
import app.lawnchair.ui.preferences.components.preferenceGroupItems
|
||||
import app.lawnchair.ui.util.OnResult
|
||||
import com.android.launcher3.LauncherAppState
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.util.ComponentKey
|
||||
import com.google.accompanist.navigation.animation.composable
|
||||
@@ -90,7 +89,7 @@ fun SelectIconPreference(componentKey: ComponentKey) {
|
||||
}
|
||||
}
|
||||
preferenceGroupItems(
|
||||
heading = { "Choose icon from" },
|
||||
heading = { stringResource(id = R.string.pick_icon_from_label) },
|
||||
items = iconPacks,
|
||||
isFirstChild = !hasOverride
|
||||
) { _, iconPack ->
|
||||
|
||||
@@ -33,7 +33,8 @@ fun SwitchPreference(
|
||||
label: String,
|
||||
description: String? = null,
|
||||
enabled: Boolean = true,
|
||||
showDivider: Boolean = false
|
||||
showDivider: Boolean = false,
|
||||
onChange: (Boolean) -> Unit = {},
|
||||
) {
|
||||
PreferenceTemplate(
|
||||
title = { Text(text = label) },
|
||||
@@ -43,13 +44,19 @@ fun SwitchPreference(
|
||||
modifier = Modifier
|
||||
.height(24.dp),
|
||||
checked = adapter.state.value,
|
||||
onCheckedChange = adapter::onChange,
|
||||
onCheckedChange = {
|
||||
adapter.onChange(it)
|
||||
onChange(it)
|
||||
},
|
||||
enabled = enabled,
|
||||
colors = SwitchDefaults.colors(checkedThumbColor = MaterialTheme.colorScheme.primary),
|
||||
)
|
||||
},
|
||||
modifier = Modifier
|
||||
.clickable(enabled) { adapter.onChange(!adapter.state.value) },
|
||||
.clickable(enabled) {
|
||||
onChange(!adapter.state.value)
|
||||
adapter.onChange(!adapter.state.value)
|
||||
},
|
||||
enabled = enabled,
|
||||
showDivider = showDivider
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user