mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
update protobufs
This commit is contained in:
parent
60f6e0a96f
commit
48fd657d8a
15 changed files with 140 additions and 150 deletions
|
|
@ -37,18 +37,18 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
model.radioConfig.observe(viewLifecycleOwner) {
|
||||
model.deviceConfig.observe(viewLifecycleOwner) {
|
||||
binding.positionBroadcastPeriodEditText.setText(model.positionBroadcastSecs.toString())
|
||||
binding.lsSleepEditText.setText(model.lsSleepSecs.toString())
|
||||
binding.positionBroadcastPeriodView.isEnabled = !model.locationShareDisabled
|
||||
binding.positionBroadcastSwitch.isChecked = !model.locationShareDisabled
|
||||
binding.positionBroadcastPeriodView.isEnabled = !model.gpsDisabled
|
||||
binding.positionBroadcastSwitch.isChecked = !model.gpsDisabled
|
||||
binding.lsSleepView.isEnabled = model.isPowerSaving ?: false
|
||||
binding.lsSleepSwitch.isChecked = model.isPowerSaving ?: false
|
||||
}
|
||||
|
||||
model.connectionState.observe(viewLifecycleOwner) { connectionState ->
|
||||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
binding.positionBroadcastPeriodView.isEnabled = connected && !model.locationShareDisabled
|
||||
binding.positionBroadcastPeriodView.isEnabled = connected && !model.gpsDisabled
|
||||
binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false
|
||||
binding.positionBroadcastSwitch.isEnabled = connected
|
||||
binding.lsSleepSwitch.isEnabled = connected
|
||||
|
|
@ -58,7 +58,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
|||
val textEdit = binding.positionBroadcastPeriodEditText
|
||||
val n = textEdit.text.toString().toIntOrNull()
|
||||
val minBroadcastPeriodSecs =
|
||||
ChannelOption.fromConfig(model.primaryChannel?.modemConfig)?.minBroadcastPeriodSecs
|
||||
ChannelOption.fromConfig(model.deviceConfig.value?.lora?.modemPreset)?.minBroadcastPeriodSecs
|
||||
?: ChannelOption.defaultMinBroadcastPeriod
|
||||
|
||||
if (n != null && n < MAX_INT_DEVICE && (n == 0 || n >= minBroadcastPeriodSecs)) {
|
||||
|
|
@ -81,7 +81,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
|
|||
|
||||
binding.positionBroadcastSwitch.setOnCheckedChangeListener { view, isChecked ->
|
||||
if (view.isPressed) {
|
||||
model.locationShareDisabled = !isChecked
|
||||
model.gpsDisabled = !isChecked
|
||||
debug("User changed locationShare to $isChecked")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.geeksville.android.hideKeyboard
|
|||
import com.geeksville.android.isGooglePlayAvailable
|
||||
import com.geeksville.mesh.AppOnlyProtos
|
||||
import com.geeksville.mesh.ChannelProtos
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.hasCameraPermission
|
||||
import com.geeksville.mesh.databinding.ChannelFragmentBinding
|
||||
|
|
@ -107,15 +108,15 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
binding.channelNameEdit.setText(channel.humanName)
|
||||
|
||||
// For now, we only let the user edit/save channels while the radio is awake - because the service
|
||||
// doesn't cache radioconfig writes.
|
||||
// doesn't cache DeviceConfig writes.
|
||||
binding.editableCheckbox.isEnabled = connected
|
||||
|
||||
val bitmap = channels.qrCode
|
||||
if (bitmap != null)
|
||||
binding.qrView.setImageBitmap(bitmap)
|
||||
|
||||
val modemConfig = channel.modemConfig
|
||||
val channelOption = ChannelOption.fromConfig(modemConfig)
|
||||
val modemPreset = model.deviceConfig.value?.lora?.modemPreset
|
||||
val channelOption = ChannelOption.fromConfig(modemPreset)
|
||||
binding.filledExposedDropdown.setText(
|
||||
getString(
|
||||
channelOption?.configRes ?: R.string.modem_config_unrecognized
|
||||
|
|
@ -128,12 +129,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
binding.editableCheckbox.isEnabled = false
|
||||
}
|
||||
|
||||
val modemConfigs = ChannelOption.values()
|
||||
val modemConfigList = modemConfigs.map { getString(it.configRes) }
|
||||
val modemPresets = ChannelOption.values()
|
||||
val modemPresetList = modemPresets.map { getString(it.configRes) }
|
||||
val adapter = ArrayAdapter(
|
||||
requireContext(),
|
||||
R.layout.dropdown_menu_popup_item,
|
||||
modemConfigList
|
||||
modemPresetList
|
||||
)
|
||||
|
||||
binding.filledExposedDropdown.setAdapter(adapter)
|
||||
|
|
@ -174,10 +175,10 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
private fun installSettings(newChannel: ChannelProtos.ChannelSettings) {
|
||||
val newSet =
|
||||
ChannelSet(AppOnlyProtos.ChannelSet.newBuilder().addSettings(newChannel).build())
|
||||
// Try to change the radio, if it fails, tell the user why and throw away their redits
|
||||
// Try to change the radio, if it fails, tell the user why and throw away their edits
|
||||
try {
|
||||
model.setChannels(newSet)
|
||||
// Since we are writing to radioconfig, that will trigger the rest of the GUI update (QR code etc)
|
||||
// Since we are writing to DeviceConfig, that will trigger the rest of the GUI update (QR code etc)
|
||||
} catch (ex: RemoteException) {
|
||||
errormsg("ignoring channel problem", ex)
|
||||
|
||||
|
|
@ -282,7 +283,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
if (checked) {
|
||||
// User just unlocked for editing - remove the # goo around the channel name
|
||||
model.channels.value?.primaryChannel?.let { ch ->
|
||||
// Note: We are careful to show the emptystring here if the user was on a default channel, so the user knows they should it for any changes
|
||||
// Note: We are careful to show the empty string here if the user was on a default channel, so the user knows they should it for any changes
|
||||
originalName = ch.settings.name
|
||||
binding.channelNameEdit.setText(originalName)
|
||||
}
|
||||
|
|
@ -303,18 +304,20 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
// Find the new modem config
|
||||
val selectedChannelOptionString =
|
||||
binding.filledExposedDropdown.editableText.toString()
|
||||
var modemConfig = getModemConfig(selectedChannelOptionString)
|
||||
if (modemConfig == ChannelProtos.ChannelSettings.ModemConfig.UNRECOGNIZED) // Huh? didn't find it - keep same
|
||||
modemConfig = oldPrimary.settings.modemConfig
|
||||
var modemPreset = getModemPreset(selectedChannelOptionString)
|
||||
// if (modemPreset == ConfigProtos.Config.LoRaConfig.ModemPreset.UNRECOGNIZED) // Huh? didn't find it - keep same
|
||||
// modemPreset = oldPrimary.settings.modemConfig -> TODO add from LoraConfig.ModemPreset?
|
||||
|
||||
// Generate a new AES256 key if the user changes channel name or the name is non-default and the settings changed
|
||||
if (newName != originalName || (newName.isNotEmpty() && modemConfig != oldPrimary.settings.modemConfig)) {
|
||||
// if (newName != originalName || (newName.isNotEmpty() && modemConfig != oldPrimary.settings.modemConfig)) {
|
||||
if (newName != originalName || newName.isNotEmpty()) {
|
||||
|
||||
// Install a new customized channel
|
||||
debug("ASSIGNING NEW AES256 KEY")
|
||||
val random = SecureRandom()
|
||||
val bytes = ByteArray(32)
|
||||
random.nextBytes(bytes)
|
||||
newSettings.name = newName
|
||||
newSettings.name = newName.take(11) // proto max_size:12
|
||||
newSettings.psk = ByteString.copyFrom(bytes)
|
||||
} else {
|
||||
debug("Switching back to default channel")
|
||||
|
|
@ -322,7 +325,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
}
|
||||
|
||||
// No matter what apply the speed selection from the user
|
||||
newSettings.modemConfig = modemConfig
|
||||
// newSettings.modemConfig = modemPreset -> TODO add from LoraConfig.ModemPreset?
|
||||
|
||||
installSettings(newSettings.build())
|
||||
}
|
||||
|
|
@ -348,12 +351,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getModemConfig(selectedChannelOptionString: String): ChannelProtos.ChannelSettings.ModemConfig {
|
||||
private fun getModemPreset(selectedChannelOptionString: String): ConfigProtos.Config.LoRaConfig.ModemPreset {
|
||||
for (item in ChannelOption.values()) {
|
||||
if (getString(item.configRes) == selectedChannelOptionString)
|
||||
return item.modemConfig
|
||||
return item.modemPreset
|
||||
}
|
||||
return ChannelProtos.ChannelSettings.ModemConfig.UNRECOGNIZED
|
||||
return ConfigProtos.Config.LoRaConfig.ModemPreset.UNRECOGNIZED
|
||||
}
|
||||
|
||||
private val requestPermissionAndScanLauncher =
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class ContactsFragment : ScreenFragment("Messages"), Logging {
|
|||
val nodes = model.nodeDB.nodes.value!!
|
||||
val node = nodes[if (isLocal) contact.to else contact.from]
|
||||
|
||||
//grab channel names from RadioConfig
|
||||
//grab channel names from DeviceConfig
|
||||
val channels = model.channels.value
|
||||
val primaryChannel = channels?.primaryChannel
|
||||
|
||||
|
|
|
|||
|
|
@ -296,9 +296,6 @@ class MessagesFragment : Fragment(), Logging {
|
|||
val connected = connectionState == MeshService.ConnectionState.CONNECTED
|
||||
binding.textInputLayout.isEnabled = connected
|
||||
binding.sendButton.isEnabled = connected
|
||||
|
||||
// Just being connected is enough to allow sending texts I think
|
||||
// && model.nodeDB.myId.value != null && model.radioConfig.value != null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import com.geeksville.android.hideKeyboard
|
|||
import com.geeksville.android.isGooglePlayAvailable
|
||||
import com.geeksville.mesh.MainActivity
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.RadioConfigProtos
|
||||
import com.geeksville.mesh.ConfigProtos
|
||||
import com.geeksville.mesh.android.*
|
||||
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
||||
import com.geeksville.mesh.model.BluetoothViewModel
|
||||
|
|
@ -659,7 +659,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
// update the region selection from the device
|
||||
val region = model.region
|
||||
val spinner = binding.regionSpinner
|
||||
val unsetIndex = regions.indexOf(RadioConfigProtos.RegionCode.Unset.name)
|
||||
val unsetIndex = regions.indexOf(ConfigProtos.Config.LoRaConfig.RegionCode.Unset.name)
|
||||
spinner.onItemSelectedListener = null
|
||||
|
||||
debug("current region is $region")
|
||||
|
|
@ -673,7 +673,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
spinner.isEnabled = true
|
||||
|
||||
// If actively connected possibly let the user update firmware
|
||||
refreshUpdateButton(region != RadioConfigProtos.RegionCode.Unset)
|
||||
refreshUpdateButton(region != ConfigProtos.Config.LoRaConfig.RegionCode.Unset)
|
||||
|
||||
// Update the status string (highest priority messages first)
|
||||
val info = model.myNodeInfo.value
|
||||
|
|
@ -683,7 +683,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
(permissionsWarning != null) ->
|
||||
statusText.text = permissionsWarning
|
||||
|
||||
region == RadioConfigProtos.RegionCode.Unset ->
|
||||
region == ConfigProtos.Config.LoRaConfig.RegionCode.Unset ->
|
||||
statusText.text = getString(R.string.must_set_region)
|
||||
|
||||
connected == MeshService.ConnectionState.CONNECTED -> {
|
||||
|
|
@ -705,7 +705,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
id: Long
|
||||
) {
|
||||
val item = parent.getItemAtPosition(position) as String?
|
||||
val asProto = item!!.let { RadioConfigProtos.RegionCode.valueOf(it) }
|
||||
val asProto = item!!.let { ConfigProtos.Config.LoRaConfig.RegionCode.valueOf(it) }
|
||||
exceptionToSnackbar(requireView()) {
|
||||
model.region = asProto
|
||||
}
|
||||
|
|
@ -718,8 +718,8 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
}
|
||||
|
||||
/// the sorted list of region names like arrayOf("US", "CN", "EU488")
|
||||
private val regions = RadioConfigProtos.RegionCode.values().filter {
|
||||
it != RadioConfigProtos.RegionCode.UNRECOGNIZED
|
||||
private val regions = ConfigProtos.Config.LoRaConfig.RegionCode.values().filter {
|
||||
it != ConfigProtos.Config.LoRaConfig.RegionCode.UNRECOGNIZED
|
||||
}.map {
|
||||
it.name
|
||||
}.sorted()
|
||||
|
|
@ -746,10 +746,10 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
updateDevicesButtons(scanModel.devices.value)
|
||||
}
|
||||
|
||||
model.radioConfig.observe(viewLifecycleOwner) {
|
||||
model.deviceConfig.observe(viewLifecycleOwner) {
|
||||
binding.provideLocationCheckbox.isEnabled =
|
||||
isGooglePlayAvailable(requireContext()) && !model.locationShareDisabled
|
||||
if (model.locationShareDisabled) {
|
||||
isGooglePlayAvailable(requireContext()) && !model.gpsDisabled
|
||||
if (model.gpsDisabled) {
|
||||
model.provideLocation.value = false
|
||||
binding.provideLocationCheckbox.isChecked = false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue