mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add feedback for configuration changes
This commit is contained in:
parent
2dd0e1f1e2
commit
7c30d86e39
6 changed files with 138 additions and 143 deletions
|
|
@ -191,7 +191,7 @@ private fun getName(route: Any): String = when (route) {
|
|||
*/
|
||||
sealed class ResponseState<out T> {
|
||||
data object Empty : ResponseState<Nothing>()
|
||||
data class Loading(var total: Int = 0, var completed: Int = 0) : ResponseState<Nothing>()
|
||||
data class Loading(var total: Int = 1, var completed: Int = 0) : ResponseState<Nothing>()
|
||||
data class Success<T>(val result: T) : ResponseState<T>()
|
||||
data class Error(val error: String) : ResponseState<Nothing>()
|
||||
}
|
||||
|
|
@ -231,7 +231,6 @@ fun RadioConfigNavHost(
|
|||
|
||||
val destNum = node?.num ?: 0
|
||||
val isLocal = destNum == viewModel.myNodeNum
|
||||
val maxChannels = viewModel.maxChannels
|
||||
|
||||
val radioConfigState by viewModel.radioConfigState.collectAsStateWithLifecycle()
|
||||
var location by remember(node) { mutableStateOf(node?.position) } // FIXME
|
||||
|
|
@ -314,12 +313,15 @@ fun RadioConfigNavHost(
|
|||
onRouteClick = { route ->
|
||||
viewModel.setResponseStateLoading(getName(route))
|
||||
when (route) {
|
||||
ConfigRoute.USER -> { viewModel.getOwner(destNum) }
|
||||
ConfigRoute.CHANNELS -> {
|
||||
viewModel.setResponseStateTotal(maxChannels + 1) // for lora config
|
||||
viewModel.clearRemoteChannelList()
|
||||
viewModel.getChannel(destNum, 0)
|
||||
ConfigRoute.USER -> {
|
||||
viewModel.getOwner(destNum)
|
||||
}
|
||||
|
||||
ConfigRoute.CHANNELS -> {
|
||||
viewModel.getChannel(destNum, 0)
|
||||
viewModel.getConfig(destNum, ConfigRoute.LORA.configType)
|
||||
}
|
||||
|
||||
"IMPORT" -> {
|
||||
viewModel.clearPacketResponse()
|
||||
viewModel.setDeviceProfile(null)
|
||||
|
|
@ -329,6 +331,7 @@ fun RadioConfigNavHost(
|
|||
}
|
||||
importConfigLauncher.launch(intent)
|
||||
}
|
||||
|
||||
"EXPORT" -> {
|
||||
viewModel.clearPacketResponse()
|
||||
showEditDeviceProfileDialog = true
|
||||
|
|
@ -350,23 +353,20 @@ fun RadioConfigNavHost(
|
|||
viewModel.requestNodedbReset(destNum)
|
||||
}
|
||||
|
||||
ConfigRoute.LORA -> {
|
||||
viewModel.setResponseStateTotal(2)
|
||||
viewModel.clearRemoteChannelList()
|
||||
viewModel.getChannel(destNum, 0)
|
||||
}
|
||||
is ConfigRoute -> {
|
||||
if (route == ConfigRoute.LORA) {
|
||||
viewModel.getChannel(destNum, 0)
|
||||
}
|
||||
viewModel.getConfig(destNum, route.configType)
|
||||
}
|
||||
ModuleRoute.CANNED_MESSAGE -> {
|
||||
viewModel.setResponseStateTotal(2)
|
||||
viewModel.getCannedMessages(destNum)
|
||||
}
|
||||
ModuleRoute.EXTERNAL_NOTIFICATION -> {
|
||||
viewModel.setResponseStateTotal(2)
|
||||
viewModel.getRingtone(destNum)
|
||||
}
|
||||
|
||||
is ModuleRoute -> {
|
||||
if (route == ModuleRoute.CANNED_MESSAGE) {
|
||||
viewModel.getCannedMessages(destNum)
|
||||
}
|
||||
if (route == ModuleRoute.EXTERNAL_NOTIFICATION) {
|
||||
viewModel.getRingtone(destNum)
|
||||
}
|
||||
viewModel.getModuleConfig(destNum, route.configType)
|
||||
}
|
||||
}
|
||||
|
|
@ -387,10 +387,9 @@ fun RadioConfigNavHost(
|
|||
settingsList = radioConfigState.channelList,
|
||||
modemPresetName = Channel(loraConfig = radioConfigState.radioConfig.lora).name,
|
||||
enabled = connected,
|
||||
maxChannels = maxChannels,
|
||||
maxChannels = viewModel.maxChannels,
|
||||
onPositiveClicked = { channelListInput ->
|
||||
viewModel.updateChannels(destNum, radioConfigState.channelList, channelListInput)
|
||||
viewModel.setRemoteChannelList(channelListInput)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ import androidx.compose.material.icons.twotone.Add
|
|||
import androidx.compose.material.icons.twotone.Close
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.toMutableStateList
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
|
@ -94,9 +94,7 @@ fun ChannelSettingsItemList(
|
|||
onPositiveClicked: (List<ChannelSettings>) -> Unit,
|
||||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
val settingsListInput = remember {
|
||||
mutableStateListOf<ChannelSettings>().apply { addAll(settingsList) }
|
||||
}
|
||||
val settingsListInput = remember(settingsList) { settingsList.toMutableStateList() }
|
||||
|
||||
val isEditing: Boolean = settingsList.size != settingsListInput.size
|
||||
|| settingsList.zip(settingsListInput).any { (item1, item2) -> item1 != item2 }
|
||||
|
|
@ -172,10 +170,12 @@ fun ChannelSettingsItemList(
|
|||
) {
|
||||
FloatingActionButton(
|
||||
onClick = {
|
||||
settingsListInput.add(channelSettings {
|
||||
psk = Channel.default.settings.psk
|
||||
})
|
||||
showEditChannelDialog = settingsListInput.lastIndex
|
||||
if (maxChannels > settingsListInput.size) {
|
||||
settingsListInput.add(channelSettings {
|
||||
psk = Channel.default.settings.psk
|
||||
})
|
||||
showEditChannelDialog = settingsListInput.lastIndex
|
||||
}
|
||||
},
|
||||
modifier = Modifier.padding(16.dp)
|
||||
) { Icon(Icons.TwoTone.Add, stringResource(R.string.add)) }
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ fun <T> PacketResponseStateDialog(
|
|||
if (state.total == state.completed) onComplete()
|
||||
}
|
||||
if (state is ResponseState.Success) {
|
||||
Text("Success!")
|
||||
Text("Delivery confirmed.")
|
||||
}
|
||||
if (state is ResponseState.Error) {
|
||||
Text(text = "Error\n", textAlign = TextAlign.Center)
|
||||
|
|
@ -67,13 +67,7 @@ fun <T> PacketResponseStateDialog(
|
|||
Button(
|
||||
onClick = onDismiss,
|
||||
modifier = Modifier.padding(top = 16.dp)
|
||||
) {
|
||||
if (state is ResponseState.Loading) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
} else {
|
||||
Text(stringResource(R.string.close))
|
||||
}
|
||||
}
|
||||
) { Text(stringResource(R.string.close)) }
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue