From 9a860223429b93a5088bbf354bb700d2489dac84 Mon Sep 17 00:00:00 2001 From: AdityaBhawsar Date: Fri, 22 Jul 2022 11:15:06 +0530 Subject: [PATCH] Added changes to add a mentions section --- .../notifications/NotificationScreen.kt | 77 +---------------- .../components/MentionsSection.kt | 84 +++++++++++++++++++ app/src/main/res/values/strings.xml | 7 ++ 3 files changed, 93 insertions(+), 75 deletions(-) create mode 100644 app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/components/MentionsSection.kt diff --git a/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/NotificationScreen.kt b/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/NotificationScreen.kt index 141409e..a2e1d61 100644 --- a/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/NotificationScreen.kt +++ b/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/NotificationScreen.kt @@ -20,6 +20,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController import dev.baseio.discordjetpackcompose.R import dev.baseio.discordjetpackcompose.navigator.ComposeNavigator import dev.baseio.discordjetpackcompose.ui.components.DiscordScaffold +import dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components.MentionsSection import dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components.NotificationFrequencySection import dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components.SubtitledAppBar import dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.models.NotificationSettingsType @@ -87,7 +88,7 @@ fun NotificationScreen( } if (screenType == NotificationSettingsType.SERVER) { - MentionsSection() + MentionsSection(isMute) SectionEndDivider() SectionTitleHeader(stringResource = R.string.notification_overrides) NotificationOverridesSection() @@ -147,80 +148,6 @@ fun NotificationOverridesSection() { } -@Composable -fun MentionsSection() { - var suppressEveryoneMentions by remember { mutableStateOf(false) } - var suppressRoleMentions by remember { mutableStateOf(false) } - var suppressPush by remember { mutableStateOf(false) } - - MentionsItem(action = ServerInfoAction( - trailingComposable = { - Switch( - checked = suppressEveryoneMentions, - onCheckedChange = { isChecked -> suppressEveryoneMentions = isChecked }, - colors = DiscordSwitchColors - ) - }, - title = "Suppress @Everyone and @here mentions", - titleColor = Color.LightGray, - subtitle = null, - onClick = { - suppressEveryoneMentions = !suppressEveryoneMentions - } - )) - MentionsItem(action = ServerInfoAction( - trailingComposable = { - Switch( - checked = suppressRoleMentions, - onCheckedChange = { isChecked -> suppressRoleMentions = isChecked }, - colors = DiscordSwitchColors - ) - }, - title = "Suppress All Role @mentions", - titleColor = Color.LightGray, - subtitle = null, - onClick = { - suppressRoleMentions = !suppressRoleMentions - } - )) - MentionsItem(action = ServerInfoAction( - trailingComposable = { - Switch( - checked = suppressPush, - onCheckedChange = { isChecked -> suppressPush = isChecked }, - colors = DiscordSwitchColors - ) - }, - title = "Mobile Push Notification", - titleColor = Color.LightGray, - subtitle = null, - onClick = { - suppressPush = !suppressPush - } - )) -} - -@Composable -fun MentionsItem(action: ServerInfoAction) { - Row( - modifier = Modifier - .fillMaxWidth() - .clickable(onClick = action.onClick) - .padding(horizontal = 16.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Column(modifier = Modifier.padding(vertical = 16.dp)) { - Text( - text = action.title, - style = DirectMessageListTypography.h6, - color = action.titleColor - ) - } - action.trailingComposable() - } -} - @Composable fun SectionTitleHeader( stringResource: Int diff --git a/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/components/MentionsSection.kt b/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/components/MentionsSection.kt new file mode 100644 index 0000000..4ed8ba1 --- /dev/null +++ b/app/src/main/java/dev/baseio/discordjetpackcompose/ui/routes/dashboard/notifications/components/MentionsSection.kt @@ -0,0 +1,84 @@ +package dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components + +import androidx.compose.material.Switch +import androidx.compose.material.Text +import androidx.compose.runtime.* +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.withStyle +import dev.baseio.discordjetpackcompose.R +import dev.baseio.discordjetpackcompose.ui.routes.dashboard.serverinfo.DiscordSwitchColors + +@Composable +fun MentionsSection( + isMute: Boolean +) { + var suppressEveryoneMentions by remember { mutableStateOf(false) } + var suppressRoleMentions by remember { mutableStateOf(false) } + var suppressPush by remember { mutableStateOf(false) } + + SwitchItem( + onClick = { + suppressEveryoneMentions = !suppressEveryoneMentions + }, + title = buildAnnotatedString { + append(stringResource(id = R.string.suppress)) + withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)){ + append(" "+stringResource(id = R.string.at_everyone)) + } + append(" "+stringResource(id = R.string.and)) + withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)){ + append(" "+stringResource(id = R.string.at_here)) + } + }, + disabled = false, + isChecked = suppressEveryoneMentions + ) + SwitchItem( + onClick = { + suppressRoleMentions = !suppressRoleMentions + }, + title = buildAnnotatedString { append(stringResource(id = R.string.role_mentions)) }, + disabled = false, + isChecked = suppressRoleMentions + ) + SwitchItem( + onClick = { + if (isMute) return@SwitchItem + suppressPush = !suppressPush + }, + title = buildAnnotatedString { append(stringResource(id = R.string.mobile_push)) }, + disabled = isMute, + isChecked = suppressPush + ) +} + +@Composable +fun SwitchItem( + onClick: () -> Unit, + title: AnnotatedString, + disabled: Boolean, + isChecked: Boolean +) { + SectionItem( + disabled = disabled, + onClick = onClick, + leadingComposable = { + Text( + text = title, + color = Color.LightGray + ) + }, + trailingComposable = { + Switch( + checked = isChecked, + onCheckedChange = { onClick() }, + colors = DiscordSwitchColors + ) + } + ) +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 94450cd..597b98e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -47,6 +47,13 @@ All Messages Only \@mentions + \@everyone + \@here + Suppress + mentions + And + Mobile Push Notification + Suppress All Role @mentions Nothing Mute Unmute