mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add remote node configuration (#626)
This commit is contained in:
parent
ec3a046fb6
commit
85e62eaab4
12 changed files with 523 additions and 267 deletions
|
|
@ -26,11 +26,13 @@ import com.geeksville.mesh.ui.components.SwitchPreference
|
|||
|
||||
@Composable
|
||||
fun CannedMessageConfigItemList(
|
||||
messages: String,
|
||||
cannedMessageConfig: CannedMessageConfig,
|
||||
enabled: Boolean,
|
||||
focusManager: FocusManager,
|
||||
onSaveClicked: (CannedMessageConfig) -> Unit,
|
||||
onSaveClicked: (Pair<String, CannedMessageConfig>) -> Unit,
|
||||
) {
|
||||
var messagesInput by remember(messages) { mutableStateOf(messages) }
|
||||
var cannedMessageInput by remember(cannedMessageConfig) { mutableStateOf(cannedMessageConfig) }
|
||||
|
||||
LazyColumn(
|
||||
|
|
@ -162,14 +164,29 @@ fun CannedMessageConfigItemList(
|
|||
}
|
||||
item { Divider() }
|
||||
|
||||
item {
|
||||
EditTextPreference(title = "Messages",
|
||||
value = messagesInput,
|
||||
maxSize = 200, // messages max_size:201
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { messagesInput = it }
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = cannedMessageInput != cannedMessageConfig,
|
||||
enabled = cannedMessageInput != cannedMessageConfig || messagesInput != messages,
|
||||
onCancelClicked = {
|
||||
focusManager.clearFocus()
|
||||
messagesInput = messages
|
||||
cannedMessageInput = cannedMessageConfig
|
||||
},
|
||||
onSaveClicked = { onSaveClicked(cannedMessageInput) }
|
||||
onSaveClicked = { onSaveClicked(Pair(messagesInput,cannedMessageInput)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -179,6 +196,7 @@ fun CannedMessageConfigItemList(
|
|||
@Composable
|
||||
fun CannedMessageConfigPreview(){
|
||||
CannedMessageConfigItemList(
|
||||
messages = "",
|
||||
cannedMessageConfig = CannedMessageConfig.getDefaultInstance(),
|
||||
enabled = true,
|
||||
focusManager = LocalFocusManager.current,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.geeksville.mesh.ui.components.config
|
|||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.Divider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
|
|
@ -12,6 +13,8 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusManager
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.geeksville.mesh.ModuleConfigProtos.ModuleConfig.ExternalNotificationConfig
|
||||
import com.geeksville.mesh.copy
|
||||
|
|
@ -23,13 +26,15 @@ import com.geeksville.mesh.ui.components.TextDividerPreference
|
|||
|
||||
@Composable
|
||||
fun ExternalNotificationConfigItemList(
|
||||
externalNotificationConfig: ExternalNotificationConfig,
|
||||
ringtone: String,
|
||||
extNotificationConfig: ExternalNotificationConfig,
|
||||
enabled: Boolean,
|
||||
focusManager: FocusManager,
|
||||
onSaveClicked: (ExternalNotificationConfig) -> Unit,
|
||||
onSaveClicked: (Pair<String, ExternalNotificationConfig>) -> Unit,
|
||||
) {
|
||||
var externalNotificationInput by remember(externalNotificationConfig) {
|
||||
mutableStateOf(externalNotificationConfig)
|
||||
var ringtoneInput by remember(ringtone) { mutableStateOf(ringtone) }
|
||||
var externalNotificationInput by remember(extNotificationConfig) {
|
||||
mutableStateOf(extNotificationConfig)
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
|
|
@ -183,14 +188,29 @@ fun ExternalNotificationConfigItemList(
|
|||
})
|
||||
}
|
||||
|
||||
item {
|
||||
EditTextPreference(title = "Ringtone",
|
||||
value = ringtoneInput,
|
||||
maxSize = 230, // ringtone max_size:231
|
||||
enabled = enabled,
|
||||
isError = false,
|
||||
keyboardOptions = KeyboardOptions.Default.copy(
|
||||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { ringtoneInput = it }
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = externalNotificationInput != externalNotificationConfig,
|
||||
enabled = externalNotificationInput != extNotificationConfig || ringtoneInput != ringtone,
|
||||
onCancelClicked = {
|
||||
focusManager.clearFocus()
|
||||
externalNotificationInput = externalNotificationConfig
|
||||
ringtoneInput = ringtone
|
||||
externalNotificationInput = extNotificationConfig
|
||||
},
|
||||
onSaveClicked = { onSaveClicked(externalNotificationInput) }
|
||||
onSaveClicked = { onSaveClicked(Pair(ringtoneInput, externalNotificationInput)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -200,7 +220,8 @@ fun ExternalNotificationConfigItemList(
|
|||
@Composable
|
||||
fun ExternalNotificationConfigPreview(){
|
||||
ExternalNotificationConfigItemList(
|
||||
externalNotificationConfig = ExternalNotificationConfig.getDefaultInstance(),
|
||||
ringtone = "",
|
||||
extNotificationConfig = ExternalNotificationConfig.getDefaultInstance(),
|
||||
enabled = true,
|
||||
focusManager = LocalFocusManager.current,
|
||||
onSaveClicked = { },
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ import com.geeksville.mesh.ui.components.SwitchPreference
|
|||
|
||||
@Composable
|
||||
fun PositionConfigItemList(
|
||||
positionInfo: Position?,
|
||||
locationInfo: Position?,
|
||||
positionConfig: PositionConfig,
|
||||
enabled: Boolean,
|
||||
focusManager: FocusManager,
|
||||
onSaveClicked: (Pair<Position?, PositionConfig>) -> Unit,
|
||||
) {
|
||||
var locationInput by remember(positionInfo) { mutableStateOf(positionInfo) }
|
||||
var locationInput by remember(locationInfo) { mutableStateOf(locationInfo) }
|
||||
var positionInput by remember(positionConfig) { mutableStateOf(positionConfig) }
|
||||
|
||||
LazyColumn(
|
||||
|
|
@ -175,10 +175,10 @@ fun PositionConfigItemList(
|
|||
|
||||
item {
|
||||
PreferenceFooter(
|
||||
enabled = positionInput != positionConfig || locationInput != positionInfo,
|
||||
enabled = positionInput != positionConfig || locationInput != locationInfo,
|
||||
onCancelClicked = {
|
||||
focusManager.clearFocus()
|
||||
locationInput = positionInfo
|
||||
locationInput = locationInfo
|
||||
positionInput = positionConfig
|
||||
},
|
||||
onSaveClicked = { onSaveClicked(Pair(locationInput, positionInput)) }
|
||||
|
|
@ -191,7 +191,7 @@ fun PositionConfigItemList(
|
|||
@Composable
|
||||
fun PositionConfigPreview(){
|
||||
PositionConfigItemList(
|
||||
positionInfo = null,
|
||||
locationInfo = null,
|
||||
positionConfig = PositionConfig.getDefaultInstance(),
|
||||
enabled = true,
|
||||
focusManager = LocalFocusManager.current,
|
||||
|
|
|
|||
|
|
@ -17,20 +17,21 @@ import androidx.compose.ui.text.input.ImeAction
|
|||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MeshUser
|
||||
import com.geeksville.mesh.copy
|
||||
import com.geeksville.mesh.model.getInitials
|
||||
import com.geeksville.mesh.ui.components.EditTextPreference
|
||||
import com.geeksville.mesh.ui.components.PreferenceCategory
|
||||
import com.geeksville.mesh.ui.components.PreferenceFooter
|
||||
import com.geeksville.mesh.ui.components.RegularPreference
|
||||
import com.geeksville.mesh.ui.components.SwitchPreference
|
||||
import com.geeksville.mesh.user
|
||||
|
||||
@Composable
|
||||
fun UserConfigItemList(
|
||||
userConfig: MeshUser,
|
||||
userConfig: MeshProtos.User,
|
||||
enabled: Boolean,
|
||||
focusManager: FocusManager,
|
||||
onSaveClicked: (MeshUser) -> Unit,
|
||||
onSaveClicked: (MeshProtos.User) -> Unit,
|
||||
) {
|
||||
var userInput by remember(userConfig) { mutableStateOf(userConfig) }
|
||||
|
||||
|
|
@ -57,9 +58,9 @@ fun UserConfigItemList(
|
|||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = {
|
||||
userInput = userInput.copy(longName = it)
|
||||
userInput = userInput.copy { longName = it }
|
||||
if (getInitials(it).toByteArray().size <= 4) // short_name max_size:5
|
||||
userInput = userInput.copy(shortName = getInitials(it))
|
||||
userInput = userInput.copy { shortName = getInitials(it) }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ fun UserConfigItemList(
|
|||
keyboardType = KeyboardType.Text, imeAction = ImeAction.Done
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
|
||||
onValueChanged = { userInput = userInput.copy(shortName = it) })
|
||||
onValueChanged = { userInput = userInput.copy { shortName = it } })
|
||||
}
|
||||
|
||||
item {
|
||||
|
|
@ -87,7 +88,7 @@ fun UserConfigItemList(
|
|||
SwitchPreference(title = "Licensed amateur radio",
|
||||
checked = userInput.isLicensed,
|
||||
enabled = enabled,
|
||||
onCheckedChange = { userInput = userInput.copy(isLicensed = it) })
|
||||
onCheckedChange = { userInput = userInput.copy { isLicensed = it } })
|
||||
}
|
||||
item { Divider() }
|
||||
|
||||
|
|
@ -107,13 +108,13 @@ fun UserConfigItemList(
|
|||
@Composable
|
||||
fun UserConfigPreview(){
|
||||
UserConfigItemList(
|
||||
userConfig = MeshUser(
|
||||
id = "!a280d9c8",
|
||||
longName = "Meshtastic d9c8",
|
||||
shortName = "d9c8",
|
||||
hwModel = MeshProtos.HardwareModel.RAK4631,
|
||||
userConfig = user {
|
||||
id = "!a280d9c8"
|
||||
longName = "Meshtastic d9c8"
|
||||
shortName = "d9c8"
|
||||
hwModel = MeshProtos.HardwareModel.RAK4631
|
||||
isLicensed = false
|
||||
),
|
||||
},
|
||||
enabled = true,
|
||||
focusManager = LocalFocusManager.current,
|
||||
onSaveClicked = { },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue