From 7ea4724b91ec2f7d04136d02898baae58340ebee Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Fri, 30 Apr 2021 11:56:10 +0700 Subject: [PATCH 1/6] Move title declaration to each preference pages --- .../src/app/lawnchair/ui/preferences/About.kt | 3 + .../ui/preferences/AppDrawerPreferences.kt | 3 + .../ui/preferences/DockPreferences.kt | 3 + .../ui/preferences/FolderPreferences.kt | 3 + .../ui/preferences/GeneralPreferences.kt | 3 + .../ui/preferences/HomeScreenPreferences.kt | 3 + .../ui/preferences/IconPackPreferences.kt | 4 ++ .../lawnchair/ui/preferences/Preferences.kt | 32 ++++------ .../app/lawnchair/ui/preferences/TopBar.kt | 63 +++++++++---------- .../app/lawnchair/util/createSideEffect.kt | 46 ++++++++++++++ lawnchair/src/app/lawnchair/util/pageMeta.kt | 12 ++++ 11 files changed, 124 insertions(+), 51 deletions(-) create mode 100644 lawnchair/src/app/lawnchair/util/createSideEffect.kt create mode 100644 lawnchair/src/app/lawnchair/util/pageMeta.kt diff --git a/lawnchair/src/app/lawnchair/ui/preferences/About.kt b/lawnchair/src/app/lawnchair/ui/preferences/About.kt index 4fc59de936..9f597030b5 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/About.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/About.kt @@ -34,6 +34,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getFormattedVersionName import com.android.launcher3.R import com.google.android.gms.oss.licenses.OssLicensesMenuActivity @@ -114,6 +116,7 @@ val teamMembers = listOf( fun About() { val context = LocalContext.current + pageMeta.provide(Meta(title = stringResource(id = R.string.about_label))) Column( modifier = Modifier .fillMaxWidth() diff --git a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt index 3f7f3053dc..3ec5f1dd6f 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt @@ -19,6 +19,8 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R @@ -27,6 +29,7 @@ import com.android.launcher3.R @Composable fun AppDrawerPreferences() { val prefs = preferenceManager() + pageMeta.provide(Meta(title = stringResource(id = R.string.app_drawer_label))) PreferenceLayout { PreferenceGroup(heading = stringResource(id = R.string.general_label), isFirstChild = true) { SliderPreference( diff --git a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt index d5a226eafc..0959e4ba69 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt @@ -19,6 +19,8 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R @@ -26,6 +28,7 @@ import com.android.launcher3.R @ExperimentalAnimationApi @Composable fun DockPreferences() { + pageMeta.provide(Meta(title = stringResource(id = R.string.dock_label))) PreferenceLayout { PreferenceGroup(heading = stringResource(id = R.string.grid), isFirstChild = true) { SliderPreference( diff --git a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt index b75069f241..cb0052ce84 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt @@ -19,6 +19,8 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R @@ -26,6 +28,7 @@ import com.android.launcher3.R @ExperimentalAnimationApi @Composable fun FolderPreferences() { + pageMeta.provide(Meta(title = stringResource(id = R.string.folders_label))) PreferenceLayout { val prefs = preferenceManager() PreferenceGroup(heading = stringResource(id = R.string.grid), isFirstChild = true) { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt index 038b725d2e..4097fccb5a 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt @@ -21,6 +21,8 @@ import androidx.compose.animation.* import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import androidx.navigation.NavController +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.* import com.android.launcher3.R @@ -28,6 +30,7 @@ import com.android.launcher3.R @Composable fun GeneralPreferences(navController: NavController, interactor: PreferenceInteractor) { val prefs = preferenceManager() + pageMeta.provide(Meta(title = stringResource(id = R.string.general_label))) PreferenceLayout { PreferenceGroup(isFirstChild = true) { SwitchPreference( diff --git a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt index 3596b71c57..c4c411f6c8 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt @@ -19,6 +19,8 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R @@ -27,6 +29,7 @@ import com.android.launcher3.R @Composable fun HomeScreenPreferences() { val prefs = preferenceManager() + pageMeta.provide(Meta(title = stringResource(id = R.string.home_screen_label))) PreferenceLayout { PreferenceGroup(heading = "General", isFirstChild = true) { SwitchPreference( diff --git a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt index 39ef44c567..83b2edbec5 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt @@ -30,8 +30,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R @@ -44,6 +47,7 @@ fun IconPackPreferences(interactor: PreferenceInteractor) { val iconPacks = interactor.getIconPacks().values.toList() val iconPackPackage = preferenceManager().iconPackPackage.getAdapter() + pageMeta.provide(Meta(title = stringResource(id = R.string.icon_pack))) PreferenceLayout { PreferenceGroup(isFirstChild = true) { // TODO: Use `LazyColumn` if possible. diff --git a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt index 6021eb092a..8351d1441f 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt @@ -26,10 +26,13 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import app.lawnchair.util.Meta +import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getMajorVersion import com.android.launcher3.R @@ -44,18 +47,6 @@ object Routes { const val ICON_PACK: String = "iconPack" } -fun getRoutesToLabels(context: Context) = - mapOf( - Routes.PREFERENCES to context.getString(R.string.settings), - Routes.GENERAL to context.getString(R.string.general_label), - Routes.ABOUT to context.getString(R.string.about_label), - Routes.HOME_SCREEN to context.getString(R.string.home_screen_label), - Routes.DOCK to context.getString(R.string.dock_label), - Routes.APP_DRAWER to context.getString(R.string.app_drawer_label), - Routes.FOLDERS to context.getString(R.string.folders_label), - Routes.ICON_PACK to context.getString(R.string.icon_pack) - ) - sealed class PreferenceCategory( val label: String, val description: String, @@ -63,42 +54,42 @@ sealed class PreferenceCategory( val route: String ) { class General(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.GENERAL]!!, + label = context.getString(R.string.settings), description = context.getString(R.string.general_description), iconResource = R.drawable.ic_general, route = Routes.GENERAL ) class HomeScreen(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.HOME_SCREEN]!!, + label = context.getString(R.string.home_screen_label), description = context.getString(R.string.home_screen_description), iconResource = R.drawable.ic_home_screen, route = Routes.HOME_SCREEN ) class Dock(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.DOCK]!!, + label = context.getString(R.string.dock_label), description = context.getString(R.string.dock_description), iconResource = R.drawable.ic_dock, route = Routes.DOCK ) class AppDrawer(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.APP_DRAWER]!!, + label = context.getString(R.string.app_drawer_label), description = context.getString(R.string.app_drawer_description), iconResource = R.drawable.ic_app_drawer, route = Routes.APP_DRAWER ) class Folders(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.FOLDERS]!!, + label = context.getString(R.string.folders_label), description = context.getString(R.string.folders_description), iconResource = R.drawable.ic_folder, route = Routes.FOLDERS ) class About(context: Context) : PreferenceCategory( - label = getRoutesToLabels(context)[Routes.ABOUT]!!, + label = context.getString(R.string.about_label), description = "${context.getString(R.string.derived_app_name)} ${getMajorVersion(context)}", iconResource = R.drawable.ic_about, route = Routes.ABOUT @@ -127,7 +118,10 @@ fun Preferences(interactor: PreferenceInteractor = viewModel + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .height(56.dp) + .background(MaterialTheme.colors.background) + ) { + AnimatedVisibility(visible = currentRoute != Routes.PREFERENCES && currentRoute != null) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .padding(start = 8.dp) + .height(40.dp) + .width(40.dp) + .clip(CircleShape) + .clickable { navController.popBackStack() } + ) { + Image( + painter = painterResource(id = R.drawable.ic_arrow_back), + contentDescription = null, + colorFilter = ColorFilter.tint(MaterialTheme.colors.onBackground) + ) + } } + Text( + text = state.title, + style = MaterialTheme.typography.h6, + modifier = Modifier.padding(start = 16.dp), + color = MaterialTheme.colors.onSurface, + ) } - Text( - text = title ?: "", - style = MaterialTheme.typography.h6, - modifier = Modifier.padding(start = 16.dp), - color = MaterialTheme.colors.onSurface, - ) } } \ No newline at end of file diff --git a/lawnchair/src/app/lawnchair/util/createSideEffect.kt b/lawnchair/src/app/lawnchair/util/createSideEffect.kt new file mode 100644 index 0000000000..4854f97151 --- /dev/null +++ b/lawnchair/src/app/lawnchair/util/createSideEffect.kt @@ -0,0 +1,46 @@ +package app.lawnchair.util + +import androidx.compose.runtime.* + +class PropsContainer

(var props: P) + +class SideEffect( + val consume: @Composable (@Composable (S) -> Unit) -> Unit, + val provide: @Composable (P) -> Unit) + +inline fun createSideEffect(crossinline reducePropsToState: (List

) -> S): SideEffect { + val mountedInstances = mutableListOf>() + var currentState = reducePropsToState(emptyList()) + var onChangeHandler: (() -> Unit)? = null + + val emitChange = { + currentState = reducePropsToState(mountedInstances.map { it.props }) + onChangeHandler?.invoke() + } + + return SideEffect( + consume = @Composable { block -> + val localState = remember { mutableStateOf(currentState) } + DisposableEffect(null) { + onChangeHandler = { localState.value = currentState } + onDispose { onChangeHandler = null } + } + block(localState.value) + }, + provide = @Composable { props -> + val currentProps = remember { PropsContainer(props) } + DisposableEffect(key1 = currentProps) { + mountedInstances.add(currentProps) + onDispose { + mountedInstances.remove(currentProps) + emitChange() + } + } + DisposableEffect(key1 = props) { + currentProps.props = props + emitChange() + onDispose { } + } + } + ) +} diff --git a/lawnchair/src/app/lawnchair/util/pageMeta.kt b/lawnchair/src/app/lawnchair/util/pageMeta.kt new file mode 100644 index 0000000000..045f8be470 --- /dev/null +++ b/lawnchair/src/app/lawnchair/util/pageMeta.kt @@ -0,0 +1,12 @@ +package app.lawnchair.util + +class MetaState(val title: String) +class Meta(val title: String?) + +private fun getTitleFromPropsList(propsList: List): String { + return propsList.lastOrNull()?.title ?: "" +} + +val pageMeta = createSideEffect { propsList -> + MetaState(title = getTitleFromPropsList(propsList)) +} From da89b742977371bbc736ba76129d777dffe69000 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Fri, 30 Apr 2021 13:23:36 +0700 Subject: [PATCH 2/6] Refactor preference package structure --- .../app/lawnchair/ui/preferences/AppDrawerPreferences.kt | 3 +++ .../src/app/lawnchair/ui/preferences/DockPreferences.kt | 3 +++ .../src/app/lawnchair/ui/preferences/FolderPreferences.kt | 3 +++ .../src/app/lawnchair/ui/preferences/GeneralPreferences.kt | 6 ++++++ .../app/lawnchair/ui/preferences/HomeScreenPreferences.kt | 4 ++++ .../src/app/lawnchair/ui/preferences/IconPackPreferences.kt | 3 +++ lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt | 4 ++++ .../src/app/lawnchair/ui/preferences/{ => about}/About.kt | 4 +++- .../lawnchair/ui/preferences/{ => about}/ContributorCard.kt | 2 +- .../lawnchair/ui/preferences/{ => about}/ContributorLink.kt | 2 +- .../lawnchair/ui/preferences/{ => about}/ContributorRow.kt | 3 ++- .../lawnchair/ui/preferences/{ => about}/LawnchairLink.kt | 2 +- .../preferences/{ => components}/ClickListenerPreference.kt | 2 +- .../{ => components}/NavigationActionPreference.kt | 2 +- .../{ => components}/NotificationDotsPreference.kt | 3 ++- .../preferences/{ => components}/PreferenceCategoryList.kt | 3 ++- .../{ => components}/PreferenceCategoryListItem.kt | 2 +- .../ui/preferences/{ => components}/PreferenceGroup.kt | 2 +- .../ui/preferences/{ => components}/PreferenceLayout.kt | 2 +- .../ui/preferences/{ => components}/PreferenceTemplate.kt | 2 +- .../ui/preferences/{ => components}/SliderPreference.kt | 2 +- .../ui/preferences/{ => components}/SwitchPreference.kt | 2 +- .../lawnchair/ui/preferences/{ => components}/SystemUi.kt | 2 +- .../app/lawnchair/ui/preferences/{ => components}/TopBar.kt | 3 ++- 24 files changed, 49 insertions(+), 17 deletions(-) rename lawnchair/src/app/lawnchair/ui/preferences/{ => about}/About.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => about}/ContributorCard.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => about}/ContributorLink.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => about}/ContributorRow.kt (96%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => about}/LawnchairLink.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/ClickListenerPreference.kt (97%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/NavigationActionPreference.kt (97%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/NotificationDotsPreference.kt (96%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/PreferenceCategoryList.kt (93%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/PreferenceCategoryListItem.kt (97%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/PreferenceGroup.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/PreferenceLayout.kt (92%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/PreferenceTemplate.kt (96%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/SliderPreference.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/SwitchPreference.kt (98%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/SystemUi.kt (96%) rename lawnchair/src/app/lawnchair/ui/preferences/{ => components}/TopBar.kt (97%) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt index 3ec5f1dd6f..ae4e6cc7c1 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt @@ -19,6 +19,9 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.SliderPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter diff --git a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt index 0959e4ba69..d79222dc47 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt @@ -19,6 +19,9 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.SliderPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter diff --git a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt index cb0052ce84..3980e64d3e 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt @@ -19,6 +19,9 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.SliderPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter diff --git a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt index 4097fccb5a..d143ce0e17 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt @@ -21,6 +21,12 @@ import androidx.compose.animation.* import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import androidx.navigation.NavController +import app.lawnchair.ui.preferences.components.NavigationActionPreference +import app.lawnchair.ui.preferences.components.NotificationDotsPreference +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.SliderPreference +import app.lawnchair.ui.preferences.components.SwitchPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt index c4c411f6c8..43428abebf 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt @@ -19,6 +19,10 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.SliderPreference +import app.lawnchair.ui.preferences.components.SwitchPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter diff --git a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt index 83b2edbec5..eba63730a4 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt @@ -33,6 +33,9 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.PreferenceLayout +import app.lawnchair.ui.preferences.components.PreferenceTemplate import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getAdapter diff --git a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt index 8351d1441f..69bbb3feee 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt @@ -31,6 +31,10 @@ import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import app.lawnchair.ui.preferences.about.About +import app.lawnchair.ui.preferences.components.PreferenceCategoryList +import app.lawnchair.ui.preferences.components.SystemUi +import app.lawnchair.ui.preferences.components.TopBar import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getMajorVersion diff --git a/lawnchair/src/app/lawnchair/ui/preferences/About.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/About.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/About.kt rename to lawnchair/src/app/lawnchair/ui/preferences/about/About.kt index 9f597030b5..6c889d5861 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/About.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/About.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.about import android.content.Intent import androidx.annotation.StringRes @@ -34,6 +34,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import app.lawnchair.ui.preferences.components.PreferenceGroup +import app.lawnchair.ui.preferences.components.ClickListenerPreference import app.lawnchair.util.Meta import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.getFormattedVersionName diff --git a/lawnchair/src/app/lawnchair/ui/preferences/ContributorCard.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorCard.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/ContributorCard.kt rename to lawnchair/src/app/lawnchair/ui/preferences/about/ContributorCard.kt index e5dba6304a..a7ce3ad414 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/ContributorCard.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorCard.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.about import androidx.compose.foundation.background import androidx.compose.foundation.border diff --git a/lawnchair/src/app/lawnchair/ui/preferences/ContributorLink.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorLink.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/ContributorLink.kt rename to lawnchair/src/app/lawnchair/ui/preferences/about/ContributorLink.kt index f8d3566f12..56fd6028e3 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/ContributorLink.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorLink.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.about import android.content.Intent import android.net.Uri diff --git a/lawnchair/src/app/lawnchair/ui/preferences/ContributorRow.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorRow.kt similarity index 96% rename from lawnchair/src/app/lawnchair/ui/preferences/ContributorRow.kt rename to lawnchair/src/app/lawnchair/ui/preferences/about/ContributorRow.kt index 4d010369e3..4db58dc9dc 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/ContributorRow.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/ContributorRow.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.about import android.content.Intent import android.net.Uri @@ -30,6 +30,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp +import app.lawnchair.ui.preferences.components.PreferenceTemplate import com.google.accompanist.glide.GlideImage @Composable diff --git a/lawnchair/src/app/lawnchair/ui/preferences/LawnchairLink.kt b/lawnchair/src/app/lawnchair/ui/preferences/about/LawnchairLink.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/LawnchairLink.kt rename to lawnchair/src/app/lawnchair/ui/preferences/about/LawnchairLink.kt index 9861b45160..cc8b072f66 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/LawnchairLink.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/about/LawnchairLink.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.about import android.content.Intent import android.net.Uri diff --git a/lawnchair/src/app/lawnchair/ui/preferences/ClickListenerPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/ClickListenerPreference.kt similarity index 97% rename from lawnchair/src/app/lawnchair/ui/preferences/ClickListenerPreference.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/ClickListenerPreference.kt index 626560917d..fe35cb1c20 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/ClickListenerPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/ClickListenerPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/NavigationActionPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/NavigationActionPreference.kt similarity index 97% rename from lawnchair/src/app/lawnchair/ui/preferences/NavigationActionPreference.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/NavigationActionPreference.kt index 68b635f913..f3fb6c5e12 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/NavigationActionPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/NavigationActionPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/NotificationDotsPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/NotificationDotsPreference.kt similarity index 96% rename from lawnchair/src/app/lawnchair/ui/preferences/NotificationDotsPreference.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/NotificationDotsPreference.kt index 5e04b730d7..ed4df858ae 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/NotificationDotsPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/NotificationDotsPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import android.content.ComponentName import android.content.Intent @@ -32,6 +32,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.os.bundleOf +import app.lawnchair.ui.preferences.PreferenceInteractor import com.android.launcher3.R import com.android.launcher3.notification.NotificationListener import android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS as actionNotificationListenerSettings diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryList.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt similarity index 93% rename from lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryList.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt index 7d298ace13..ba5e91f215 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryList.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.lazy.LazyColumn @@ -24,6 +24,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import androidx.navigation.compose.navigate +import app.lawnchair.ui.preferences.getPreferenceCategories @Composable fun PreferenceCategoryList(navController: NavController) { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryListItem.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryListItem.kt similarity index 97% rename from lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryListItem.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryListItem.kt index af556eadd5..3c66096598 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceCategoryListItem.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryListItem.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.annotation.DrawableRes import androidx.compose.foundation.Image diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceGroup.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceGroup.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/PreferenceGroup.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceGroup.kt index 1cd3aff02f..c0ff817cb3 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceGroup.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceGroup.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.animation.* import androidx.compose.foundation.layout.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceLayout.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceLayout.kt similarity index 92% rename from lawnchair/src/app/lawnchair/ui/preferences/PreferenceLayout.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceLayout.kt index 4ac77d4f78..2d16658c98 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceLayout.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceLayout.kt @@ -1,4 +1,4 @@ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxHeight diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceTemplate.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceTemplate.kt similarity index 96% rename from lawnchair/src/app/lawnchair/ui/preferences/PreferenceTemplate.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceTemplate.kt index ee54177fcd..4130dc96ab 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceTemplate.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceTemplate.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.layout.* import androidx.compose.material.Divider diff --git a/lawnchair/src/app/lawnchair/ui/preferences/SliderPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/SliderPreference.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/SliderPreference.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/SliderPreference.kt index 131dd5effd..065c53e26d 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/SliderPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/SliderPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.layout.* import androidx.compose.material.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/SwitchPreference.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/SwitchPreference.kt similarity index 98% rename from lawnchair/src/app/lawnchair/ui/preferences/SwitchPreference.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/SwitchPreference.kt index a45f38fbce..60080ade21 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/SwitchPreference.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/SwitchPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* diff --git a/lawnchair/src/app/lawnchair/ui/preferences/SystemUi.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/SystemUi.kt similarity index 96% rename from lawnchair/src/app/lawnchair/ui/preferences/SystemUi.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/SystemUi.kt index 185996fed6..f4bd9aa032 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/SystemUi.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/SystemUi.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import android.os.Build import android.view.View diff --git a/lawnchair/src/app/lawnchair/ui/preferences/TopBar.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/TopBar.kt similarity index 97% rename from lawnchair/src/app/lawnchair/ui/preferences/TopBar.kt rename to lawnchair/src/app/lawnchair/ui/preferences/components/TopBar.kt index 391e29c29f..fd1b88430d 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/TopBar.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/components/TopBar.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package app.lawnchair.ui.preferences +package app.lawnchair.ui.preferences.components import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExperimentalAnimationApi @@ -36,6 +36,7 @@ import androidx.compose.ui.unit.dp import androidx.navigation.NavController import androidx.navigation.compose.KEY_ROUTE import androidx.navigation.compose.currentBackStackEntryAsState +import app.lawnchair.ui.preferences.Routes import app.lawnchair.util.pageMeta import com.android.launcher3.R From 09207d426899f0036763c2439a45bcbb11bd842d Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 3 May 2021 19:15:41 +0700 Subject: [PATCH 3/6] Move inner preference screens' declaration to their parent --- .../ui/preferences/AppDrawerPreferences.kt | 6 +++ .../ui/preferences/DockPreferences.kt | 6 +++ .../ui/preferences/FolderPreferences.kt | 6 +++ .../ui/preferences/GeneralPreferences.kt | 20 ++++++-- .../ui/preferences/HomeScreenPreferences.kt | 6 +++ .../ui/preferences/IconPackPreferences.kt | 9 +++- .../lawnchair/ui/preferences/Preferences.kt | 46 +++++++++++-------- .../lawnchair/ui/preferences/about/About.kt | 7 +++ .../components/NavigationActionPreference.kt | 21 +++++++-- .../components/NotificationDotsPreference.kt | 5 +- .../ui/preferences/components/TopBar.kt | 5 +- .../ui/preferences/preferenceGraph.kt | 38 +++++++++++++++ 12 files changed, 142 insertions(+), 33 deletions(-) create mode 100644 lawnchair/src/app/lawnchair/ui/preferences/preferenceGraph.kt diff --git a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt index ae4e6cc7c1..5e03f60556 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/AppDrawerPreferences.kt @@ -19,6 +19,7 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.PreferenceGroup import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.SliderPreference @@ -28,6 +29,11 @@ import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R +@ExperimentalAnimationApi +fun NavGraphBuilder.appDrawerGraph(route: String) { + preferenceGraph(route, { AppDrawerPreferences() }) +} + @ExperimentalAnimationApi @Composable fun AppDrawerPreferences() { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt index d79222dc47..793dc5b4a5 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/DockPreferences.kt @@ -19,6 +19,7 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.PreferenceGroup import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.SliderPreference @@ -28,6 +29,11 @@ import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R +@ExperimentalAnimationApi +fun NavGraphBuilder.dockGraph(route: String) { + preferenceGraph(route, { DockPreferences() }) +} + @ExperimentalAnimationApi @Composable fun DockPreferences() { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt index 3980e64d3e..0a105346ff 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/FolderPreferences.kt @@ -19,6 +19,7 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.PreferenceGroup import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.SliderPreference @@ -28,6 +29,11 @@ import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R +@ExperimentalAnimationApi +fun NavGraphBuilder.folderGraph(route: String) { + preferenceGraph(route, { FolderPreferences() }) +} + @ExperimentalAnimationApi @Composable fun FolderPreferences() { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt index d143ce0e17..0025851987 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/GeneralPreferences.kt @@ -20,7 +20,7 @@ import android.os.Build import androidx.compose.animation.* import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource -import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.NavigationActionPreference import app.lawnchair.ui.preferences.components.NotificationDotsPreference import app.lawnchair.ui.preferences.components.PreferenceGroup @@ -32,9 +32,20 @@ import app.lawnchair.util.pageMeta import app.lawnchair.util.preferences.* import com.android.launcher3.R +object GeneralRoutes { + const val ICON_PACK = "iconPack" +} + +@ExperimentalAnimationApi +fun NavGraphBuilder.generalGraph(route: String) { + preferenceGraph(route, { GeneralPreferences() }) { subRoute -> + iconPackGraph(route = subRoute(GeneralRoutes.ICON_PACK)) + } +} + @ExperimentalAnimationApi @Composable -fun GeneralPreferences(navController: NavController, interactor: PreferenceInteractor) { +fun GeneralPreferences() { val prefs = preferenceManager() pageMeta.provide(Meta(title = stringResource(id = R.string.general_label))) PreferenceLayout { @@ -44,11 +55,10 @@ fun GeneralPreferences(navController: NavController, interactor: PreferenceInter label = stringResource(id = R.string.home_screen_rotation_label), description = stringResource(id = R.string.home_screen_rotaton_description) ) - NotificationDotsPreference(interactor) + NotificationDotsPreference() NavigationActionPreference( label = stringResource(id = R.string.icon_pack), - navController = navController, - destination = Routes.ICON_PACK, + destination = subRoute(name = GeneralRoutes.ICON_PACK), showDivider = false ) } diff --git a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt index 43428abebf..df4a733e52 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/HomeScreenPreferences.kt @@ -19,6 +19,7 @@ package app.lawnchair.ui.preferences import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.PreferenceGroup import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.SliderPreference @@ -29,6 +30,11 @@ import app.lawnchair.util.preferences.getAdapter import app.lawnchair.util.preferences.preferenceManager import com.android.launcher3.R +@ExperimentalAnimationApi +fun NavGraphBuilder.homeScreenGraph(route: String) { + preferenceGraph(route, { HomeScreenPreferences() }) +} + @ExperimentalAnimationApi @Composable fun HomeScreenPreferences() { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt index eba63730a4..a664ea09f7 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt @@ -33,6 +33,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap +import androidx.navigation.NavGraphBuilder import app.lawnchair.ui.preferences.components.PreferenceGroup import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.PreferenceTemplate @@ -44,9 +45,15 @@ import com.android.launcher3.R data class IconPackInfo(val name: String, val packageName: String, val icon: Drawable) +@ExperimentalAnimationApi +fun NavGraphBuilder.iconPackGraph(route: String) { + preferenceGraph(route, { IconPackPreferences() }) +} + @ExperimentalAnimationApi @Composable -fun IconPackPreferences(interactor: PreferenceInteractor) { +fun IconPackPreferences() { + val interactor = LocalPreferenceInteractor.current val iconPacks = interactor.getIconPacks().values.toList() val iconPackPackage = preferenceManager().iconPackPackage.getAdapter() diff --git a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt index 69bbb3feee..ae8f7ede37 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt @@ -25,13 +25,17 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.compositionLocalOf import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.lifecycle.viewmodel.compose.viewModel +import androidx.navigation.NavController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import app.lawnchair.ui.preferences.about.About +import app.lawnchair.ui.preferences.about.aboutGraph import app.lawnchair.ui.preferences.components.PreferenceCategoryList import app.lawnchair.ui.preferences.components.SystemUi import app.lawnchair.ui.preferences.components.TopBar @@ -48,7 +52,6 @@ object Routes { const val DOCK: String = "dock" const val APP_DRAWER: String = "appDrawer" const val FOLDERS: String = "folders" - const val ICON_PACK: String = "iconPack" } sealed class PreferenceCategory( @@ -109,6 +112,14 @@ fun getPreferenceCategories(context: Context) = listOf( PreferenceCategory.About(context) ) +val LocalNavController = compositionLocalOf { + error("CompositionLocal LocalNavController not present") +} + +val LocalPreferenceInteractor = compositionLocalOf { + error("CompositionLocal LocalPreferenceInteractor not present") +} + @ExperimentalAnimationApi @Composable fun Preferences(interactor: PreferenceInteractor = viewModel(), window: Window) { @@ -120,23 +131,22 @@ fun Preferences(interactor: PreferenceInteractor = viewModel Unit, + crossinline block: NavGraphBuilder.(subRoute: (String) -> String) -> Unit = { } +) { + val subRoute: (String) -> String = { name -> "$route/$name" } + val rootRoute = subRoute("root") + navigation(startDestination = rootRoute, route) { + composable(route = rootRoute) { + CompositionLocalProvider(LocalRoute provides route) { + root() + } + } + block(subRoute) + } +} + +inline fun NavGraphBuilder.root(crossinline content: @Composable () -> Unit) { + composable(route = "") { + content() + } +} + +val LocalRoute = compositionLocalOf { "" } + +@Composable +fun subRoute(name: String): String { + return "${LocalRoute.current}/$name" +} From d2c33464a6a8baf4cd12c5d3336b10393a7f50f3 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 3 May 2021 19:47:05 +0700 Subject: [PATCH 4/6] Sort icon packs by name --- .../ui/preferences/IconPackPreferences.kt | 3 ++- .../ui/preferences/PreferenceInteractor.kt | 2 +- .../ui/preferences/PreferenceViewModel.kt | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt index a664ea09f7..161ec13617 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/IconPackPreferences.kt @@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.* import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter @@ -54,7 +55,7 @@ fun NavGraphBuilder.iconPackGraph(route: String) { @Composable fun IconPackPreferences() { val interactor = LocalPreferenceInteractor.current - val iconPacks = interactor.getIconPacks().values.toList() + val iconPacks = remember { interactor.getIconPacks() } val iconPackPackage = preferenceManager().iconPackPackage.getAdapter() pageMeta.provide(Meta(title = stringResource(id = R.string.icon_pack))) diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceInteractor.kt b/lawnchair/src/app/lawnchair/ui/preferences/PreferenceInteractor.kt index 8d173fecbd..4706c3cf60 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceInteractor.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/PreferenceInteractor.kt @@ -21,5 +21,5 @@ import androidx.compose.runtime.State interface PreferenceInteractor { val notificationDotsEnabled: State - fun getIconPacks(): MutableMap + fun getIconPacks(): List } diff --git a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceViewModel.kt b/lawnchair/src/app/lawnchair/ui/preferences/PreferenceViewModel.kt index e979e10b87..f09130e0f6 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/PreferenceViewModel.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/PreferenceViewModel.kt @@ -40,7 +40,7 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati override val notificationDotsEnabled: MutableState = mutableStateOf(enabledNotificationListeners?.contains(lawnchairNotificationListener.flattenToString()) == true) - override fun getIconPacks(): MutableMap { + override fun getIconPacks(): List { val pm = getApplication().packageManager val iconPacks: MutableMap = HashMap() val list: MutableList = pm.queryIntentActivities(Intent("com.novalauncher.THEME"), 0) @@ -51,9 +51,6 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati pm.queryIntentActivities(Intent("android.intent.action.MAIN").addCategory("com.anddoes.launcher.THEME"), 0) ) - iconPacks["system"] = - IconPackInfo("System Icons", "", AppCompatResources.getDrawable(getApplication(), R.drawable.ic_launcher_home)!!) - for (info in list) { iconPacks[info.activityInfo.packageName] = IconPackInfo( info.loadLabel(pm).toString(), @@ -62,6 +59,17 @@ class PreferenceViewModel(application: Application) : AndroidViewModel(applicati ) } - return iconPacks + val iconPackList = iconPacks.values.toMutableList() + iconPackList.sortBy { it.name } + iconPackList.add( + 0, + IconPackInfo( + "System Icons", + "", + AppCompatResources.getDrawable(getApplication(), R.drawable.ic_launcher_home)!! + ) + ) + + return iconPackList } } From d40107c7d88874ffa812084138964651efb87a60 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 3 May 2021 20:05:23 +0700 Subject: [PATCH 5/6] Expose default value from preference entries --- .../util/preferences/BasePreferenceManager.kt | 63 ++++++++++++------- .../util/preferences/PreferenceAdapter.kt | 8 +-- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/lawnchair/src/app/lawnchair/util/preferences/BasePreferenceManager.kt b/lawnchair/src/app/lawnchair/util/preferences/BasePreferenceManager.kt index 2852fdd156..cb101eba1f 100644 --- a/lawnchair/src/app/lawnchair/util/preferences/BasePreferenceManager.kt +++ b/lawnchair/src/app/lawnchair/util/preferences/BasePreferenceManager.kt @@ -2,8 +2,6 @@ package app.lawnchair.util.preferences import android.content.Context import android.content.SharedPreferences -import android.util.Log -import androidx.compose.runtime.currentComposer import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.Utilities import java.lang.ClassCastException @@ -26,16 +24,23 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha } interface PreferenceChangeListener { - fun onPreferenceChange(pref: BasePref<*>) + fun onPreferenceChange(pref: PrefEntry<*>) } - abstract inner class BasePref(val key: String, private val primaryListener: ChangeListener?) { + interface PrefEntry { + val defaultValue: T + + fun get(): T + fun set(newValue: T) + + fun addListener(listener: PreferenceChangeListener) + fun removeListener(listener: PreferenceChangeListener) + } + + abstract inner class BasePref(val key: String, private val primaryListener: ChangeListener?) : PrefEntry { protected var loaded = false private val listeners = WeakHashMap() - abstract fun get(): T - abstract fun set(newValue: T) - fun onSharedPreferenceChange() { loaded = false primaryListener?.invoke() @@ -44,18 +49,18 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha } } - fun addListener(listener: PreferenceChangeListener) { + override fun addListener(listener: PreferenceChangeListener) { listeners[listener] = true } - fun removeListener(listener: PreferenceChangeListener) { + override fun removeListener(listener: PreferenceChangeListener) { listeners.remove(listener) } } inner class StringPref( key: String, - private val defaultValue: String, + override val defaultValue: String, primaryListener: ChangeListener? = null ) : BasePref(key, primaryListener) { private var currentValue = "" @@ -80,7 +85,7 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha inner class BoolPref( key: String, - private val defaultValue: Boolean, + override val defaultValue: Boolean, primaryListener: ChangeListener? = null ) : BasePref(key, primaryListener) { private var currentValue = false @@ -105,9 +110,10 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha open inner class IntPref( key: String, - private val defaultValue: Int, + private val defaultValueInternal: Int, primaryListener: ChangeListener? = null ) : BasePref(key, primaryListener) { + override val defaultValue = defaultValueInternal private var currentValue = 0 init { @@ -117,9 +123,9 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha override fun get(): Int { if (!loaded) { currentValue = try { - sp.getInt(key, defaultValue) + sp.getInt(key, defaultValueInternal) } catch (e: ClassCastException) { - sp.getFloat(key, defaultValue.toFloat()).toInt() + sp.getFloat(key, defaultValueInternal.toFloat()).toInt() } loaded = true } @@ -134,30 +140,45 @@ abstract class BasePreferenceManager(context: Context) : SharedPreferences.OnSha inner class IdpIntPref( key: String, - private val defaultValue: InvariantDeviceProfile.() -> Int, + private val selectDefaultValue: InvariantDeviceProfile.() -> Int, primaryListener: ChangeListener? = null ) : IntPref(key, -1, primaryListener) { + override val defaultValue: Int + get() = error("unsupported") + + override fun get(): Int { + error("unsupported") + } + + override fun set(newValue: Int) { + error("unsupported") + } + + fun defaultValue(idp: InvariantDeviceProfile): Int { + return selectDefaultValue(idp) + } + fun get(idp: InvariantDeviceProfile): Int { - val value = get() + val value = super.get() return if (value == -1) { - defaultValue(idp) + selectDefaultValue(idp) } else { value } } fun set(newValue: Int, idp: InvariantDeviceProfile) { - if (newValue == defaultValue(idp)) { - set(-1) + if (newValue == selectDefaultValue(idp)) { + super.set(-1) } else { - set(newValue) + super.set(newValue) } } } inner class FloatPref( key: String, - private val defaultValue: Float, + override val defaultValue: Float, primaryListener: ChangeListener? = null ) : BasePref(key, primaryListener) { private var currentValue = 0f diff --git a/lawnchair/src/app/lawnchair/util/preferences/PreferenceAdapter.kt b/lawnchair/src/app/lawnchair/util/preferences/PreferenceAdapter.kt index 18a079f303..e4f1de9fe2 100644 --- a/lawnchair/src/app/lawnchair/util/preferences/PreferenceAdapter.kt +++ b/lawnchair/src/app/lawnchair/util/preferences/PreferenceAdapter.kt @@ -16,7 +16,7 @@ class PreferenceAdapter( state.value = newValue } - override fun onPreferenceChange(pref: BasePreferenceManager.BasePref<*>) { + override fun onPreferenceChange(pref: BasePreferenceManager.PrefEntry<*>) { state.value = get() } } @@ -29,18 +29,18 @@ fun BasePreferenceManager.IdpIntPref.getAdapter(): PreferenceAdapter { } @Composable -fun BasePreferenceManager.BasePref.getAdapter(): PreferenceAdapter { +fun BasePreferenceManager.PrefEntry.getAdapter(): PreferenceAdapter { return getAdapter(this, ::get, ::set) } @Composable -fun BasePreferenceManager.BasePref.observeAsState(): State { +fun BasePreferenceManager.PrefEntry.observeAsState(): State { return getAdapter().state } @Composable private fun getAdapter( - pref: BasePreferenceManager.BasePref<*>, + pref: BasePreferenceManager.PrefEntry<*>, get: () -> T, set: (T) -> Unit ): PreferenceAdapter { From fdca92509aa09dc29196cd81a915f018b211c427 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Mon, 3 May 2021 20:28:31 +0700 Subject: [PATCH 6/6] Theme the acknowledgements activity --- AndroidManifest-common.xml | 2 +- lawnchair/res/values-night/themes.xml | 6 ++++++ lawnchair/res/values/themes.xml | 14 +++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/AndroidManifest-common.xml b/AndroidManifest-common.xml index 1f57611f38..626afab24d 100644 --- a/AndroidManifest-common.xml +++ b/AndroidManifest-common.xml @@ -201,7 +201,7 @@ + android:theme="@style/Theme.Acknowledgements" /> false false + + diff --git a/lawnchair/res/values/themes.xml b/lawnchair/res/values/themes.xml index a0ed6e7c99..ba40a1f23c 100644 --- a/lawnchair/res/values/themes.xml +++ b/lawnchair/res/values/themes.xml @@ -13,4 +13,16 @@ ?android:attr/colorBackground true - \ No newline at end of file + + + + +