From e8563b34eade8ddb9ad7199fac3ce54cdf80c2af Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong Date: Fri, 11 Jun 2021 20:17:26 +0700 Subject: [PATCH] Refactor preferences dashboard --- .../lawnchair/ui/preferences/Preferences.kt | 74 +------------------ .../ui/preferences/PreferencesDashboard.kt | 61 +++++++++++++++ ...egoryListItem.kt => PreferenceCategory.kt} | 10 ++- .../components/PreferenceCategoryList.kt | 40 ---------- 4 files changed, 71 insertions(+), 114 deletions(-) create mode 100644 lawnchair/src/app/lawnchair/ui/preferences/PreferencesDashboard.kt rename lawnchair/src/app/lawnchair/ui/preferences/components/{PreferenceCategoryListItem.kt => PreferenceCategory.kt} (90%) delete mode 100644 lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt diff --git a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt index 894c1b277f..d596fdf17e 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/Preferences.kt @@ -16,8 +16,6 @@ package app.lawnchair.ui.preferences -import android.content.Context -import androidx.annotation.DrawableRes import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.MaterialTheme @@ -31,9 +29,8 @@ import androidx.navigation.NavController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController -import app.lawnchair.preferences.getMajorVersion import app.lawnchair.ui.preferences.about.aboutGraph -import app.lawnchair.ui.preferences.components.PreferenceCategoryList +import app.lawnchair.ui.preferences.components.PreferenceLayout import app.lawnchair.ui.preferences.components.SystemUi import app.lawnchair.ui.preferences.components.TopBar import app.lawnchair.ui.util.portal.ProvidePortalNode @@ -52,71 +49,6 @@ object Routes { const val QUICKSTEP: String = "quickstep" } -sealed class PreferenceCategory( - val label: String, - val description: String? = null, - @DrawableRes val iconResource: Int, - val route: String -) { - class General(context: Context) : PreferenceCategory( - label = context.getString(R.string.general_label), - description = context.getString(R.string.general_description), - iconResource = R.drawable.ic_general, - route = Routes.GENERAL - ) - - class HomeScreen(context: Context) : PreferenceCategory( - 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 = 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 = 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 = context.getString(R.string.folders_label), - description = context.getString(R.string.folders_description), - iconResource = R.drawable.ic_folder, - route = Routes.FOLDERS - ) - - class Quickstep(context: Context) : PreferenceCategory( - label = context.getString(R.string.quickstep_label), - iconResource = R.drawable.ic_quickstep, - route = Routes.QUICKSTEP - ) - - class About(context: Context) : PreferenceCategory( - 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 - ) -} - -fun getPreferenceCategories(context: Context) = listOf( - PreferenceCategory.General(context), - PreferenceCategory.HomeScreen(context), - PreferenceCategory.Dock(context), - PreferenceCategory.AppDrawer(context), - PreferenceCategory.Folders(context), - PreferenceCategory.Quickstep(context), - PreferenceCategory.About(context) -) - val LocalNavController = compositionLocalOf { error("CompositionLocal LocalNavController not present") } @@ -141,7 +73,9 @@ fun Preferences(interactor: PreferenceInteractor = viewModel Unit + route: String ) { + val navController = LocalNavController.current Row( modifier = Modifier - .clickable(onClick = onClick) + .clickable(onClick = { navController.navigate(route) }) .height(72.dp) .padding(start = 16.dp, end = 16.dp) .fillMaxWidth(), diff --git a/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt b/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt deleted file mode 100644 index e7c31dc5e5..0000000000 --- a/lawnchair/src/app/lawnchair/ui/preferences/components/PreferenceCategoryList.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2021, Lawnchair - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * 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. - */ - -package app.lawnchair.ui.preferences.components - -import androidx.compose.foundation.lazy.items -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.platform.LocalContext -import androidx.navigation.NavController -import app.lawnchair.ui.preferences.getPreferenceCategories - -@Composable -fun PreferenceCategoryList(navController: NavController) { - val context = LocalContext.current - val categories = remember { getPreferenceCategories(context) } - - PreferenceLayoutLazyColumn { - items(categories) { item -> - PreferenceCategoryListItem( - label = item.label, - description = item.description, - iconResource = item.iconResource, - onClick = { navController.navigate(item.route) }) - } - } -}