mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Add a debug menu to settings
This commit is contained in:
@@ -118,4 +118,5 @@
|
||||
<string name="missing_notification_access_description">Notification access needed.</string>
|
||||
<string name="msg_missing_notification_access">To use Notification Dots, turn on app notifications for <xliff:g id="name" example="My App">%1$s</xliff:g>.</string>
|
||||
<string name="title_change_settings">Change Settings</string>
|
||||
<string name="debug_restart_launcher">Restart Lawnchair</string>
|
||||
</resources>
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
package app.lawnchair.ui.preferences
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.pm.LauncherApps
|
||||
import android.os.Process
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.MoreVert
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.content.getSystemService
|
||||
import app.lawnchair.LawnchairApp
|
||||
import app.lawnchair.LawnchairLauncher
|
||||
import app.lawnchair.preferences.getMajorVersion
|
||||
import app.lawnchair.ui.preferences.components.PreferenceCategory
|
||||
import app.lawnchair.ui.preferences.components.PreferenceLayout
|
||||
import app.lawnchair.util.restartLauncher
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.R
|
||||
|
||||
@@ -16,7 +26,8 @@ import com.android.launcher3.R
|
||||
fun PreferencesDashboard() {
|
||||
PreferenceLayout(
|
||||
label = stringResource(id = R.string.settings),
|
||||
backArrowVisible = false
|
||||
backArrowVisible = false,
|
||||
actions = { PreferencesOverflowMenu() }
|
||||
) {
|
||||
PreferenceCategory(
|
||||
label = stringResource(R.string.general_label),
|
||||
@@ -72,3 +83,35 @@ fun PreferencesDashboard() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PreferencesOverflowMenu() {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
|
||||
IconButton(onClick = { showMenu = true }) {
|
||||
Icon(Icons.Rounded.MoreVert, "")
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showMenu,
|
||||
onDismissRequest = { showMenu = false }
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
DropdownMenuItem(onClick = {
|
||||
openAppInfo(context)
|
||||
showMenu = false
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.app_info_drop_target_label))
|
||||
}
|
||||
DropdownMenuItem(onClick = {
|
||||
restartLauncher(context)
|
||||
showMenu = false
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.debug_restart_launcher))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openAppInfo(context: Context) {
|
||||
val launcherApps = context.getSystemService<LauncherApps>()
|
||||
val componentName = ComponentName(context, LawnchairLauncher::class.java)
|
||||
launcherApps?.startAppDetailsActivity(componentName, Process.myUserHandle(), null, null)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
@@ -37,6 +38,7 @@ fun PreferenceLayout(
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
scrollState: ScrollState = rememberScrollState(),
|
||||
label: String,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
backArrowVisible: Boolean = true,
|
||||
content: @Composable ColumnScope.() -> Unit
|
||||
) {
|
||||
@@ -44,6 +46,7 @@ fun PreferenceLayout(
|
||||
backArrowVisible = backArrowVisible,
|
||||
floating = rememberFloatingState(scrollState),
|
||||
label = label,
|
||||
actions = actions,
|
||||
) {
|
||||
PreferenceColumn(
|
||||
verticalArrangement = verticalArrangement,
|
||||
@@ -61,13 +64,15 @@ fun PreferenceLayoutLazyColumn(
|
||||
enabled: Boolean = true,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
label: String,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
backArrowVisible: Boolean = true,
|
||||
content: LazyListScope.() -> Unit
|
||||
) {
|
||||
PreferenceScaffold(
|
||||
backArrowVisible = backArrowVisible,
|
||||
floating = rememberFloatingState(state),
|
||||
label = label
|
||||
label = label,
|
||||
actions = actions,
|
||||
) {
|
||||
PreferenceLazyColumn(
|
||||
modifier = modifier,
|
||||
|
||||
@@ -21,6 +21,7 @@ fun PreferenceScaffold(
|
||||
backArrowVisible: Boolean = true,
|
||||
floating: State<Boolean> = remember { mutableStateOf(false) },
|
||||
label: String,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
content: @Composable (PaddingValues) -> Unit
|
||||
) {
|
||||
Scaffold(
|
||||
@@ -28,7 +29,8 @@ fun PreferenceScaffold(
|
||||
TopBar(
|
||||
backArrowVisible = backArrowVisible,
|
||||
floating = floating.value,
|
||||
label = label
|
||||
label = label,
|
||||
actions = actions,
|
||||
)
|
||||
},
|
||||
bottomBar = {
|
||||
|
||||
@@ -22,16 +22,11 @@ import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.LocalElevationOverlay
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.rounded.ArrowForward
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
@@ -53,35 +48,51 @@ import com.google.accompanist.insets.statusBarsPadding
|
||||
fun TopBar(
|
||||
backArrowVisible: Boolean,
|
||||
floating: Boolean,
|
||||
label: String
|
||||
label: String,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
) {
|
||||
val navController = LocalNavController.current
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentRoute = navBackStackEntry?.destination?.route
|
||||
|
||||
TopBarSurface(floating = floating) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(topBarSize)
|
||||
.padding(horizontal = 8.dp)
|
||||
) {
|
||||
if (backArrowVisible) {
|
||||
ClickableIcon(
|
||||
imageVector = backIcon(),
|
||||
tint = MaterialTheme.colors.onBackground,
|
||||
onClick = { if (currentRoute != "/") navController.popBackStack() }
|
||||
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colors.onSurface) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(topBarSize)
|
||||
.padding(horizontal = 4.dp)
|
||||
) {
|
||||
if (backArrowVisible) {
|
||||
IconButton(onClick = { if (currentRoute != "/") navController.popBackStack() }) {
|
||||
Icon(
|
||||
imageVector = backIcon(),
|
||||
contentDescription = "",
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
}
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.h6,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp)
|
||||
.weight(1f),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
|
||||
Row(
|
||||
Modifier.fillMaxHeight(),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
content = actions
|
||||
)
|
||||
}
|
||||
}
|
||||
Text(
|
||||
text = label,
|
||||
style = MaterialTheme.typography.h6,
|
||||
modifier = Modifier.padding(start = 8.dp),
|
||||
color = MaterialTheme.colors.onSurface,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user