sforkowany z mirror/meshtastic-android
feat: extend PreferenceFooter button labels
rodzic
fe649157ae
commit
31aa88fdeb
|
@ -1,17 +1,11 @@
|
||||||
package com.geeksville.mesh.ui.components
|
package com.geeksville.mesh.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.material.Button
|
|
||||||
import androidx.compose.material.ButtonDefaults
|
|
||||||
import androidx.compose.material.Checkbox
|
import androidx.compose.material.Checkbox
|
||||||
import androidx.compose.material.DropdownMenu
|
import androidx.compose.material.DropdownMenu
|
||||||
import androidx.compose.material.DropdownMenuItem
|
import androidx.compose.material.DropdownMenuItem
|
||||||
import androidx.compose.material.MaterialTheme
|
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.twotone.KeyboardArrowDown
|
import androidx.compose.material.icons.twotone.KeyboardArrowDown
|
||||||
|
@ -23,11 +17,8 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -58,14 +49,14 @@ fun BitwisePreference(
|
||||||
items.forEach { item ->
|
items.forEach { item ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = { onItemSelected(value xor item.first) },
|
onClick = { onItemSelected(value xor item.first) },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
content = {
|
content = {
|
||||||
Text(
|
Text(
|
||||||
text = item.second,
|
text = item.second,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
)
|
)
|
||||||
Checkbox(
|
Checkbox(
|
||||||
modifier = Modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentWidth(Alignment.End),
|
.wrapContentWidth(Alignment.End),
|
||||||
checked = value and item.first != 0,
|
checked = value and item.first != 0,
|
||||||
|
@ -75,43 +66,14 @@ fun BitwisePreference(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Row(
|
PreferenceFooter(
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(start = 16.dp, end = 16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.End
|
|
||||||
) {
|
|
||||||
Button(
|
|
||||||
modifier = modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f),
|
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
onClick = { onItemSelected(0) },
|
negativeText = R.string.clear,
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red)
|
onNegativeClicked = { onItemSelected(0) },
|
||||||
) {
|
positiveText = R.string.close,
|
||||||
Text(
|
onPositiveClicked = { dropDownExpanded = false },
|
||||||
text = stringResource(id = R.string.clear),
|
|
||||||
style = MaterialTheme.typography.body1,
|
|
||||||
color = Color.Unspecified,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Button(
|
|
||||||
modifier = modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f),
|
|
||||||
enabled = enabled,
|
|
||||||
onClick = { dropDownExpanded = false },
|
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.close),
|
|
||||||
style = MaterialTheme.typography.body1,
|
|
||||||
color = Color.DarkGray,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.geeksville.mesh.ui.components
|
package com.geeksville.mesh.ui.components
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
@ -17,24 +18,42 @@ fun PreferenceFooter(
|
||||||
onCancelClicked: () -> Unit,
|
onCancelClicked: () -> Unit,
|
||||||
onSaveClicked: () -> Unit,
|
onSaveClicked: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
PreferenceFooter(
|
||||||
|
enabled = enabled,
|
||||||
|
negativeText = R.string.cancel,
|
||||||
|
onNegativeClicked = onCancelClicked,
|
||||||
|
positiveText = R.string.send,
|
||||||
|
onPositiveClicked = onSaveClicked,
|
||||||
|
modifier = modifier,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PreferenceFooter(
|
||||||
|
enabled: Boolean,
|
||||||
|
@StringRes negativeText: Int,
|
||||||
|
onNegativeClicked: () -> Unit,
|
||||||
|
@StringRes positiveText: Int,
|
||||||
|
onPositiveClicked: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.size(48.dp),
|
.size(48.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.End
|
|
||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f),
|
.weight(1f),
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
onClick = onCancelClicked,
|
onClick = onNegativeClicked,
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red)
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Red)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.cancel),
|
text = stringResource(id = negativeText),
|
||||||
style = MaterialTheme.typography.body1,
|
style = MaterialTheme.typography.body1,
|
||||||
color = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) else Color.Unspecified,
|
color = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) else Color.Unspecified,
|
||||||
)
|
)
|
||||||
|
@ -44,11 +63,11 @@ fun PreferenceFooter(
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f),
|
.weight(1f),
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
onClick = onSaveClicked,
|
onClick = onPositiveClicked,
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green)
|
colors = ButtonDefaults.buttonColors(backgroundColor = Color.Green)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.send),
|
text = stringResource(id = positiveText),
|
||||||
style = MaterialTheme.typography.body1,
|
style = MaterialTheme.typography.body1,
|
||||||
color = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) else Color.DarkGray,
|
color = if (!enabled) MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) else Color.DarkGray,
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue