sforkowany z mirror/meshtastic-android
refactor: improve channel editor isEditing logic
rodzic
0a3a07f9ed
commit
7da958578b
|
@ -96,10 +96,14 @@ fun ChannelSettingsItemList(
|
||||||
onNegativeClicked: () -> Unit = { },
|
onNegativeClicked: () -> Unit = { },
|
||||||
@StringRes positiveText: Int = R.string.send,
|
@StringRes positiveText: Int = R.string.send,
|
||||||
onPositiveClicked: (List<ChannelSettings>) -> Unit,
|
onPositiveClicked: (List<ChannelSettings>) -> Unit,
|
||||||
) {
|
) {
|
||||||
val settingsListInput = remember {
|
val settingsListInput = remember {
|
||||||
mutableStateListOf<ChannelSettings>().apply { addAll(settingsList) }
|
mutableStateListOf<ChannelSettings>().apply { addAll(settingsList) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isEditing: Boolean = settingsList.size != settingsListInput.size
|
||||||
|
|| settingsList.zip(settingsListInput).any { (item1, item2) -> item1 != item2 }
|
||||||
|
|
||||||
var showEditChannelDialog: Int? by remember { mutableStateOf(null) }
|
var showEditChannelDialog: Int? by remember { mutableStateOf(null) }
|
||||||
|
|
||||||
if (showEditChannelDialog != null) {
|
if (showEditChannelDialog != null) {
|
||||||
|
@ -141,9 +145,7 @@ fun ChannelSettingsItemList(
|
||||||
item {
|
item {
|
||||||
PreferenceFooter(
|
PreferenceFooter(
|
||||||
// FIXME workaround until we use navigation in ChannelFragment
|
// FIXME workaround until we use navigation in ChannelFragment
|
||||||
enabled = positiveText != R.string.send
|
enabled = isEditing || positiveText != R.string.send,
|
||||||
|| !settingsListInput.containsAll(settingsList)
|
|
||||||
|| !settingsList.containsAll(settingsListInput),
|
|
||||||
negativeText = R.string.cancel,
|
negativeText = R.string.cancel,
|
||||||
onNegativeClicked = {
|
onNegativeClicked = {
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
|
|
Ładowanie…
Reference in New Issue