Update design of NotificationDotsPreference

This commit is contained in:
Patryk Michalik
2021-08-26 16:51:18 +02:00
parent 7ed761e0f5
commit b07c0a9b8e
2 changed files with 77 additions and 39 deletions
+18
View File
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M3.6035,17.499L11.1346,4.4907C11.5197,3.8254 12.4803,3.8254 12.8654,4.4907L20.3965,17.499C20.7825,18.1656 20.3014,19 19.5311,19H4.4689C3.6986,19 3.2175,18.1656 3.6035,17.499Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:pathData="M12,16m-1,0a1,1 0,1 1,2 0a1,1 0,1 1,-2 0"
android:fillColor="#000000"/>
<path
android:pathData="M12,9L12,9A1,1 0,0 1,13 10L13,12A1,1 0,0 1,12 13L12,13A1,1 0,0 1,11 12L11,10A1,1 0,0 1,12 9z"
android:fillColor="#000000"/>
</vector>
@@ -31,15 +31,20 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.Lifecycle
import app.lawnchair.ui.AlertBottomSheetContent
import app.lawnchair.util.lifecycleState
import com.android.launcher3.R
import com.android.launcher3.notification.NotificationListener
import com.android.launcher3.settings.SettingsActivity
import com.android.launcher3.util.SecureSettingsObserver
import kotlinx.coroutines.launch
@Composable
@ExperimentalMaterialApi
fun NotificationDotsPreference() {
val context = LocalContext.current
val sheetState = rememberBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
val coroutineScope = rememberCoroutineScope()
val enabled = notificationDotsEnabled()
val serviceEnabled = notificationServiceEnabled()
@@ -51,10 +56,14 @@ fun NotificationDotsPreference() {
else -> R.string.notification_dots_desc_off
}
var showDialog by remember { mutableStateOf(false) }
if (showDialog) {
NotificationAccessConfirmation(onDismissRequest = { showDialog = false })
}
NotificationAccessConfirmation(
sheetState = sheetState,
onDismissRequest = {
coroutineScope.launch {
sheetState.hide()
}
}
)
PreferenceTemplate(height = 72.dp) {
Row(
@@ -62,7 +71,9 @@ fun NotificationDotsPreference() {
modifier = Modifier
.clickable {
if (showWarning) {
showDialog = true
coroutineScope.launch {
sheetState.show()
}
} else {
val intent = Intent("android.settings.NOTIFICATION_SETTINGS")
.putExtra(
@@ -107,43 +118,52 @@ fun NotificationDotsPreference() {
}
@Composable
fun NotificationAccessConfirmation(onDismissRequest: () -> Unit) {
@ExperimentalMaterialApi
fun NotificationAccessConfirmation(
sheetState: BottomSheetState,
onDismissRequest: () -> Unit
) {
val context = LocalContext.current
val elevationOverlay = LocalElevationOverlay.current
val surface = MaterialTheme.colors.surface
val backgroundColor = elevationOverlay?.apply(surface, 16.dp) ?: surface
AlertDialog(
onDismissRequest = onDismissRequest,
confirmButton = { TextButton(onClick = {
onDismissRequest()
val cn = ComponentName(context, NotificationListener::class.java)
val showFragmentArgs = Bundle()
showFragmentArgs.putString(
SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
cn.flattenToString()
)
BottomSheet(sheetState = sheetState) {
AlertBottomSheetContent(
title = { Text(text = stringResource(id = R.string.missing_notification_access_label)) },
text = {
val appName = stringResource(id = R.string.derived_app_name)
Text(text = stringResource(id = R.string.msg_missing_notification_access, appName))
},
buttons = {
OutlinedButton(
shape = MaterialTheme.shapes.small,
onClick = onDismissRequest
) {
Text(text = stringResource(id = android.R.string.cancel))
}
Spacer(modifier = Modifier.requiredWidth(16.dp))
Button(
shape = MaterialTheme.shapes.small,
onClick = {
onDismissRequest()
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString())
.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs)
context.startActivity(intent)
}) {
Text(text = stringResource(id = R.string.title_change_settings))
} },
dismissButton = { TextButton(onClick = onDismissRequest) {
Text(text = stringResource(id = android.R.string.cancel))
} },
title = {
Text(text = stringResource(id = R.string.missing_notification_access_label))
},
text = {
val appName = stringResource(id = R.string.derived_app_name)
Text(text = stringResource(id = R.string.msg_missing_notification_access, appName))
},
backgroundColor = backgroundColor
)
val cn = ComponentName(context, NotificationListener::class.java)
val showFragmentArgs = Bundle()
showFragmentArgs.putString(
SettingsActivity.EXTRA_FRAGMENT_ARG_KEY,
cn.flattenToString()
)
val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString())
.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs)
context.startActivity(intent)
}
) {
Text(text = stringResource(id = R.string.title_change_settings))
}
}
)
}
}
@Composable