Skip to content

Commit

Permalink
Added changes to show notification frequency section
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-bhawsar-mm committed Jul 21, 2022
1 parent 7a38338 commit fbeade6
Show file tree
Hide file tree
Showing 6 changed files with 306 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.*
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.intl.Locale.Companion.current
import androidx.compose.ui.text.intl.LocaleList.Companion.current
import androidx.compose.ui.text.toUpperCase
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.insets.statusBarsPadding
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import dev.baseio.discordjetpackcompose.R
import dev.baseio.discordjetpackcompose.navigator.ComposeNavigator
import dev.baseio.discordjetpackcompose.ui.components.DiscordAppBar
import dev.baseio.discordjetpackcompose.ui.components.DiscordScaffold
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
import dev.baseio.discordjetpackcompose.ui.routes.dashboard.serverinfo.DiscordSwitchColors
import dev.baseio.discordjetpackcompose.ui.routes.dashboard.serverinfo.components.models.ServerInfoAction
import dev.baseio.discordjetpackcompose.ui.theme.*
import dev.baseio.discordjetpackcompose.ui.utils.clickableWithRipple
import java.util.*

@Composable
fun NotificationScreen(
composeNavigator: ComposeNavigator,
subtitle: String? = "channel"
screenType: NotificationSettingsType = NotificationSettingsType.SERVER,
nameEntity: String? = "server"
) {
val sysUiController = rememberSystemUiController()
val colors = DiscordColorProvider.colors
Expand All @@ -46,12 +43,17 @@ fun NotificationScreen(

val scrollState = rememberScrollState()
val scaffoldState = rememberScaffoldState()
var isMute by remember { mutableStateOf(false) }

DiscordScaffold(
modifier = Modifier.statusBarsPadding(),
scaffoldState = scaffoldState,
topAppBar = {
NotificationAppBar(composeNavigator, subtitle)
SubtitledAppBar(
composeNavigator,
stringResource(id = R.string.notification_settings),
nameEntity
)
}
) { paddingValues ->
Column(
Expand All @@ -61,37 +63,88 @@ fun NotificationScreen(
.background(color = create_server_screen)
.verticalScroll(scrollState)
) {
ServerChannelMuteSection()
NotificationSettingsSection()
MentionsSection()
NotificationOverridesSection()
ServerChannelMuteSection(
isMute = isMute,
name = nameEntity,
screenType = screenType
) {
isMute = !isMute
}
SectionEndDivider()

if (screenType != NotificationSettingsType.SERVER || !isMute) {
SectionTitleHeader(
stringResource = if (screenType == NotificationSettingsType.SERVER)
R.string.notification_settings
else
R.string.frequency
)

NotificationFrequencySection(
isMute = isMute
)
SectionEndDivider()
}

if (screenType == NotificationSettingsType.SERVER) {
MentionsSection()
SectionEndDivider()
SectionTitleHeader(stringResource = R.string.notification_overrides)
NotificationOverridesSection()
}
}
}
}

@Composable
fun ServerChannelMuteSection() {
SectionEndDivider()
}
fun ServerChannelMuteSection(
isMute: Boolean,
name: String?,
screenType: NotificationSettingsType,
onMuteChange: () -> Unit
) {

@Composable
fun NotificationSettingsSection() {
SectionTitleHeader(stringResource = R.string.notification_settings)
MentionsItem(action = ServerInfoAction(
trailingComposable = {
//RadioButton(selected = , onClick = { /*TODO*/ }, colors =)
},
title = "All messages",
titleColor = Color.LightGray,
subtitle = null,
onClick = {}
))
SectionEndDivider()
var isMute by remember { mutableStateOf(false) }

val spannedString = buildAnnotatedString {
withStyle(style = SpanStyle(fontSize = 14.sp)) {
append(
if (isMute) stringResource(id = R.string.unmute)
else stringResource(id = R.string.mute)
)
}
name?.let {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold, fontSize = 16.sp)) {
append(" $name")
}
}
}

Text(
text = spannedString,
modifier = Modifier
.fillMaxWidth()
.padding(12.dp)
)

val messageRes = when (screenType) {
NotificationSettingsType.SERVER -> R.string.server_mute_msg
NotificationSettingsType.CATEGORY -> R.string.category_mute_msg
NotificationSettingsType.CHANNEL -> R.string.channel_mute_msg
}

Text(
text = stringResource(id = messageRes),
style = TextStyle(color = Color.LightGray, fontSize = 12.sp),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 22.dp)
)
}

@Composable
fun NotificationOverridesSection() {
SectionTitleHeader(stringResource = R.string.notification_overrides)

}

@Composable
Expand All @@ -102,7 +155,8 @@ fun MentionsSection() {

MentionsItem(action = ServerInfoAction(
trailingComposable = {
Switch(checked = suppressEveryoneMentions,
Switch(
checked = suppressEveryoneMentions,
onCheckedChange = { isChecked -> suppressEveryoneMentions = isChecked },
colors = DiscordSwitchColors
)
Expand All @@ -116,7 +170,8 @@ fun MentionsSection() {
))
MentionsItem(action = ServerInfoAction(
trailingComposable = {
Switch(checked = suppressRoleMentions,
Switch(
checked = suppressRoleMentions,
onCheckedChange = { isChecked -> suppressRoleMentions = isChecked },
colors = DiscordSwitchColors
)
Expand All @@ -130,7 +185,8 @@ fun MentionsSection() {
))
MentionsItem(action = ServerInfoAction(
trailingComposable = {
Switch(checked = suppressPush,
Switch(
checked = suppressPush,
onCheckedChange = { isChecked -> suppressPush = isChecked },
colors = DiscordSwitchColors
)
Expand All @@ -139,10 +195,9 @@ fun MentionsSection() {
titleColor = Color.LightGray,
subtitle = null,
onClick = {
suppressPush= !suppressPush
suppressPush = !suppressPush
}
))
SectionEndDivider()
}

@Composable
Expand Down Expand Up @@ -171,7 +226,7 @@ fun SectionTitleHeader(
stringResource: Int
) {
Text(
modifier = Modifier.padding(top = 12.dp, start = 12.dp, end = 12.dp, bottom = 20.dp),
modifier = Modifier.padding(top = 12.dp, start = 12.dp, end = 12.dp, bottom = 16.dp),
text = stringResource(id = stringResource).uppercase(),
style = TextStyle(
fontWeight = FontWeight.Bold,
Expand All @@ -182,44 +237,10 @@ fun SectionTitleHeader(

@Composable
fun SectionEndDivider() {
Spacer(modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.background(Color.LightGray))
}

@Composable
private fun NotificationAppBar(
composeNavigator: ComposeNavigator,
subtitle: String?
) {
DiscordAppBar(
navigationIcon = {
IconButton(onClick = {
composeNavigator.navigateUp()
}) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
modifier = Modifier.padding(start = 8.dp),
)
}
},
backgroundColor = Color.Transparent,
elevation = 0.dp,
title = {
Column {
Text(
text = stringResource(id = R.string.notification_settings),
style = TextStyle(fontWeight = FontWeight.Bold, fontSize = Typography.h6.fontSize)
)
if (!subtitle.isNullOrBlank()) {
Text(
text = subtitle,
style = TextStyle(fontSize = Typography.body2.fontSize)
)
}
}
}
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.background(Color.LightGray)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components

import androidx.compose.material.*
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 androidx.compose.ui.unit.dp
import dev.baseio.discordjetpackcompose.R
import dev.baseio.discordjetpackcompose.ui.theme.DiscordColorProvider

@Composable
fun NotificationFrequencySection(
isMute: Boolean
) {
var selectionState by remember { mutableStateOf(FrequencyType.ALL_MESSAGES) }

RadioSelectionItem(
title = AnnotatedString(stringResource(id = R.string.all_messages)),
onClick = {
if(isMute) return@RadioSelectionItem
selectionState = FrequencyType.ALL_MESSAGES
},
currentSelection = selectionState,
selectionValue = FrequencyType.ALL_MESSAGES,
disabled = isMute
)

RadioSelectionItem(
title = buildAnnotatedString {
append(stringResource(id = R.string.only))
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)){
append(" " + stringResource(id = R.string.at_mentions))
}
},
onClick = {
if(isMute) return@RadioSelectionItem
selectionState = FrequencyType.MENTIONS
},
currentSelection = selectionState,
selectionValue = FrequencyType.MENTIONS,
disabled = isMute
)

RadioSelectionItem(
title = AnnotatedString(stringResource(id = R.string.nothing)),
onClick = {
if(isMute) return@RadioSelectionItem
selectionState = FrequencyType.NOTHING
},
currentSelection = selectionState,
selectionValue = FrequencyType.NOTHING,
disabled = isMute
)

}

@Composable
fun RadioSelectionItem(
onClick: () -> Unit,
title: AnnotatedString,
currentSelection: FrequencyType,
selectionValue: FrequencyType,
disabled: Boolean
) {
SectionItem(
disabled = disabled,
paddingVertical = 6.dp,
onClick = onClick,
leadingComposable = {
Text(
text = title,
color = Color.LightGray
)
},
trailingComposable = {
RadioButton(
selected = currentSelection == selectionValue,
onClick = onClick,
colors = DiscordRadioButtonColors
)
}
)
}

val DiscordRadioButtonColors @Composable get() = RadioButtonDefaults.colors(
selectedColor = DiscordColorProvider.colors.primary,
unselectedColor = DiscordColorProvider.colors.surface
)

enum class FrequencyType {
ALL_MESSAGES,
MENTIONS,
NOTHING
}
Loading

0 comments on commit fbeade6

Please sign in to comment.