Skip to content

Commit

Permalink
Added changes to add mute unmute toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-bhawsar-mm committed Jul 22, 2022
1 parent 9a86022 commit 1c73716
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
package dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
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.*
import androidx.compose.ui.text.font.FontWeight
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.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.NotificationsMuteSection
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.*

@Composable
Expand All @@ -44,7 +40,7 @@ fun NotificationScreen(

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

DiscordScaffold(
modifier = Modifier.statusBarsPadding(),
Expand All @@ -64,7 +60,9 @@ fun NotificationScreen(
.background(color = create_server_screen)
.verticalScroll(scrollState)
) {
ServerChannelMuteSection(

// Notifications Mute Un-Mute
NotificationsMuteSection(
isMute = isMute,
name = nameEntity,
screenType = screenType
Expand All @@ -73,6 +71,7 @@ fun NotificationScreen(
}
SectionEndDivider()

// Notification Settings and Frequency
if (screenType != NotificationSettingsType.SERVER || !isMute) {
SectionTitleHeader(
stringResource = if (screenType == NotificationSettingsType.SERVER)
Expand All @@ -81,68 +80,23 @@ fun NotificationScreen(
R.string.frequency
)

NotificationFrequencySection(
isMute = isMute
)
NotificationFrequencySection(isMute = isMute)
SectionEndDivider()
}

if (screenType == NotificationSettingsType.SERVER) {
// Mentions Sections
MentionsSection(isMute)
SectionEndDivider()

// Notification override section
SectionTitleHeader(stringResource = R.string.notification_overrides)
NotificationOverridesSection()
}
}
}
}

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

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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun RadioSelectionItem(
) {
SectionItem(
disabled = disabled,
paddingVertical = 6.dp,
paddingVertical = 4.dp,
onClick = onClick,
leadingComposable = {
Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.*
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.baseio.discordjetpackcompose.R
import dev.baseio.discordjetpackcompose.ui.routes.dashboard.notifications.models.NotificationSettingsType

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

MuteUnMuteToggle(isMute = isMute, name = name) { onMuteChange() }

if (isMute) {
Text(
text = buildAnnotatedString {
append(stringResource(id = R.string.muted_msg))
append(" " + stringResource(id = typeMessageMuted(screenType = screenType)))
},
style = TextStyle(color = Color.LightGray, fontSize = 12.sp),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 6.dp, horizontal = 12.dp)
)
}

val messageRes = typeMessageForScreenType(screenType)

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 MuteUnMuteToggle(
isMute: Boolean,
name: String?,
onMuteChange: () -> Unit
) {
val spannedString = muteSectionTitle(isMute, name)

SectionItem(
onClick = { onMuteChange() },
paddingHorizontal = 12.dp,
paddingVertical = 8.dp,
leadingComposable = {
Text(text = spannedString)
},
trailingComposable = {
Icon(
imageVector = Icons.Filled.ChevronRight,
contentDescription = null,
modifier = Modifier.padding(start = 8.dp),
)
}
)



}

@Composable
private fun typeMessageForScreenType(screenType: NotificationSettingsType): Int {
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
}
return messageRes
}

@Composable
private fun typeMessageMuted(screenType: NotificationSettingsType): Int {
val messageRes = when (screenType) {
NotificationSettingsType.SERVER -> R.string.server
NotificationSettingsType.CATEGORY -> R.string.category
NotificationSettingsType.CHANNEL -> R.string.channel
}
return messageRes
}

@Composable
private fun muteSectionTitle(
isMute: Boolean,
name: String?
): AnnotatedString {
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")
}
}
}
return spannedString
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.unit.dp
fun SectionItem(
disabled: Boolean = false,
paddingVertical: Dp = 0.dp,
paddingHorizontal: Dp = 16.dp,
onClick: () -> Unit,
leadingComposable: @Composable () -> Unit = {},
trailingComposable: @Composable () -> Unit = {},
Expand All @@ -26,7 +27,7 @@ fun SectionItem(
.fillMaxWidth()
.alpha(if(disabled) ContentAlpha.disabled else 1.0f)
.clickable(onClick = onClick)
.padding(horizontal = 16.dp, vertical = paddingVertical),
.padding(horizontal = paddingHorizontal, vertical = paddingVertical),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<string name="welcome_message">Join over 100 million people who use Discord to talk with communities and friends</string>
<string name="register">Register</string>
<string name="wave_to">Wave to MEE6</string>
<string name="server">server</string>
<string name="category">category</string>
<string name="channel">channel</string>
<string name="login">Login</string>
<string name="dm_list_screen_title">Direct Messages</string>
<string name="dm_list_screen_search_hint">Find or start a conversation</string>
Expand Down Expand Up @@ -53,6 +56,7 @@
<string name="mentions">mentions</string>
<string name="and">And</string>
<string name="mobile_push">Mobile Push Notification</string>
<string name="muted_msg">You have muted this </string>
<string name="role_mentions">Suppress All Role @mentions</string>
<string name="nothing">Nothing</string>
<string name="mute">Mute</string>
Expand Down

0 comments on commit 1c73716

Please sign in to comment.