Skip to content

Commit

Permalink
Added changes to add a mentions section
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-bhawsar-mm committed Jul 22, 2022
1 parent fbeade6 commit 9a86022
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,7 +88,7 @@ fun NotificationScreen(
}

if (screenType == NotificationSettingsType.SERVER) {
MentionsSection()
MentionsSection(isMute)
SectionEndDivider()
SectionTitleHeader(stringResource = R.string.notification_overrides)
NotificationOverridesSection()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}
)
}
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
<string name="all_messages">All Messages</string>
<string name="only">Only</string>
<string name="at_mentions">\@mentions</string>
<string name="at_everyone">\@everyone</string>
<string name="at_here">\@here</string>
<string name="suppress">Suppress</string>
<string name="mentions">mentions</string>
<string name="and">And</string>
<string name="mobile_push">Mobile Push Notification</string>
<string name="role_mentions">Suppress All Role @mentions</string>
<string name="nothing">Nothing</string>
<string name="mute">Mute</string>
<string name="unmute">Unmute</string>
Expand Down

0 comments on commit 9a86022

Please sign in to comment.