mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-28 04:34:21 +01:00
Convert NotificationsSettingsFragment to compose.
This commit is contained in:
committed by
Greyson Parrelli
parent
7af811eb3f
commit
2eb4f650d8
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
@@ -44,6 +45,8 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -372,7 +375,7 @@ object Dialogs {
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 100.dp)
|
||||
.heightIn(min = 0.dp, max = getScreenHeight() - 200.dp)
|
||||
.background(
|
||||
color = SignalTheme.colors.colorSurface2,
|
||||
shape = AlertDialogDefaults.shape
|
||||
@@ -456,7 +459,7 @@ object Dialogs {
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.padding(vertical = 100.dp)
|
||||
.heightIn(min = 0.dp, max = getScreenHeight() - 200.dp)
|
||||
.background(
|
||||
color = SignalTheme.colors.colorSurface2,
|
||||
shape = AlertDialogDefaults.shape
|
||||
@@ -587,6 +590,13 @@ object Dialogs {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun getScreenHeight(): Dp {
|
||||
return with(LocalDensity.current) {
|
||||
LocalWindowInfo.current.containerSize.height.toDp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SignalPreview
|
||||
|
||||
@@ -50,6 +50,7 @@ import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.signal.core.ui.R
|
||||
import org.signal.core.ui.compose.Rows.TextAndLabel
|
||||
import org.signal.core.ui.compose.Rows.TextRow
|
||||
|
||||
object Rows {
|
||||
|
||||
@@ -150,20 +151,47 @@ object Rows {
|
||||
labels: Array<String>,
|
||||
values: Array<String>,
|
||||
selectedValue: String,
|
||||
onSelected: (String) -> Unit
|
||||
onSelected: (String) -> Unit,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
RadioListRow(
|
||||
text = { selectedIndex ->
|
||||
val selectedLabel = if (selectedIndex in labels.indices) {
|
||||
labels[selectedIndex]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
TextAndLabel(
|
||||
text = text,
|
||||
label = selectedLabel
|
||||
)
|
||||
},
|
||||
dialogTitle = text,
|
||||
labels = labels,
|
||||
values = values,
|
||||
selectedValue = selectedValue,
|
||||
onSelected = onSelected,
|
||||
enabled = enabled
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RadioListRow(
|
||||
text: @Composable RowScope.(Int) -> Unit,
|
||||
dialogTitle: String,
|
||||
labels: Array<String>,
|
||||
values: Array<String>,
|
||||
selectedValue: String,
|
||||
onSelected: (String) -> Unit,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
val selectedIndex = values.indexOf(selectedValue)
|
||||
val selectedLabel = if (selectedIndex in labels.indices) {
|
||||
labels[selectedIndex]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
var displayDialog by remember { mutableStateOf(false) }
|
||||
|
||||
TextRow(
|
||||
text = text,
|
||||
label = selectedLabel,
|
||||
text = { text(selectedIndex) },
|
||||
enabled = enabled,
|
||||
onClick = {
|
||||
displayDialog = true
|
||||
}
|
||||
@@ -175,7 +203,7 @@ object Rows {
|
||||
labels = labels,
|
||||
values = values,
|
||||
selectedIndex = selectedIndex,
|
||||
title = text,
|
||||
title = dialogTitle,
|
||||
onSelected = {
|
||||
onSelected(values[it])
|
||||
}
|
||||
@@ -183,18 +211,6 @@ object Rows {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
multiSelectPref(
|
||||
text = stringResource(R.string.preferences_chats__when_using_mobile_data),
|
||||
listItems = autoDownloadLabels,
|
||||
selected = autoDownloadValues.map { state.mobileAutoDownloadValues.contains(it) }.toBooleanArray(),
|
||||
onSelected = {
|
||||
val resultSet = it.mapIndexed { index, selected -> if (selected) autoDownloadValues[index] else null }.filterNotNull().toSet()
|
||||
viewModel.setMobileAutoDownloadValues(resultSet)
|
||||
}
|
||||
)
|
||||
*/
|
||||
|
||||
@Composable
|
||||
fun MultiSelectRow(
|
||||
text: String,
|
||||
|
||||
Reference in New Issue
Block a user