Skip to content

Commit

Permalink
Toggle burnOnRead/openDiscussion mutually: Both can't be on at same time
Browse files Browse the repository at this point in the history
  • Loading branch information
nain-F49FF806 committed Oct 21, 2024
1 parent 5de395b commit fb5e737
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import alt.nainapps.sharepaste.common.units.ExpandableOptionsCard
import alt.nainapps.sharepaste.common.units.OptionMenu
import alt.nainapps.sharepaste.common.units.OutputLinkWithShareIcon
import alt.nainapps.sharepaste.common.units.OutputTextWithCopyIcon
import alt.nainapps.sharepaste.common.units.SwithWithOnOffIcons
import alt.nainapps.sharepaste.common.units.SwitchWithOnOffIcons
import alt.nainapps.sharepaste.rsnative.PrivateBinRs
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -88,18 +88,28 @@ fun EncryptAndShareUI(

Spacer(modifier = Modifier.height(16.dp))

SwithWithOnOffIcons(label = "Burn on read", checked = burnOnRead) { burnOnRead = it }
SwitchWithOnOffIcons(label = "Burn on read", checked = burnOnRead) {
burnOnRead = it
if (burnOnRead) {
openDiscussion = false
}
}

Spacer(modifier = Modifier.height(16.dp))

ExpandableOptionsCard(
title = "More options",
defaultExpanded = !attachName.isNullOrEmpty()
) {
SwithWithOnOffIcons(
SwitchWithOnOffIcons(
label = "Enable Discussions",
checked = openDiscussion
) { openDiscussion = it }
) {
openDiscussion = it
if (openDiscussion) {
burnOnRead = false
}
}
if (!attachName.isNullOrEmpty()) {
Row(
horizontalArrangement = Arrangement.SpaceEvenly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package alt.nainapps.sharepaste.common.units
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
Expand All @@ -13,20 +12,18 @@ import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun SwithWithOnOffIcons (label: String, checked: Boolean = false, onCheckedChange: (Boolean) -> Unit) {
var checked by remember { mutableStateOf(checked) }
fun SwitchWithOnOffIcons(
label: String,
checked: Boolean = false,
onCheckedChange: (Boolean) -> Unit
) {
// Icon isn't focusable, so no need for content description here
val icon: (@Composable () -> Unit)? = if (checked) {
{
Expand Down Expand Up @@ -54,10 +51,7 @@ fun SwithWithOnOffIcons (label: String, checked: Boolean = false, onCheckedChang
Switch(
modifier = Modifier.semantics { contentDescription = "$label toggle switch" },
checked = checked,
onCheckedChange = {
checked = it
onCheckedChange(checked)
},
onCheckedChange = onCheckedChange,
thumbContent = icon
)
}
Expand All @@ -67,5 +61,5 @@ fun SwithWithOnOffIcons (label: String, checked: Boolean = false, onCheckedChang
@Preview(showBackground = true)
@Composable
fun ToggleSwitchPreview() {
SwithWithOnOffIcons(label = "Let's do this?", checked = true) {}
SwitchWithOnOffIcons(label = "Let's do this?", checked = true) {}
}

0 comments on commit fb5e737

Please sign in to comment.