diff --git a/app/src/main/java/com/geeksville/mesh/model/ChannelOption.kt b/app/src/main/java/com/geeksville/mesh/model/ChannelOption.kt index 318739496..d541828c3 100644 --- a/app/src/main/java/com/geeksville/mesh/model/ChannelOption.kt +++ b/app/src/main/java/com/geeksville/mesh/model/ChannelOption.kt @@ -7,5 +7,15 @@ enum class ChannelOption(val modemConfig: MeshProtos.ChannelSettings.ModemConfig SHORT(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128, R.string.modem_config_short), MEDIUM(MeshProtos.ChannelSettings.ModemConfig.Bw500Cr45Sf128, R.string.modem_config_medium), LONG(MeshProtos.ChannelSettings.ModemConfig.Bw31_25Cr48Sf512, R.string.modem_config_long), - VERY_LONG(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096, R.string.modem_config_very_long) + VERY_LONG(MeshProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096, R.string.modem_config_very_long); + + companion object { + fun fromConfig(modemConfig: MeshProtos.ChannelSettings.ModemConfig?): ChannelOption? { + for (option in values()) { + if (option.modemConfig == modemConfig) + return option + } + return null + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt index 63b9b28ee..a42958c56 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt @@ -12,7 +12,6 @@ import android.view.inputmethod.EditorInfo import android.widget.ArrayAdapter import android.widget.ImageView import androidx.fragment.app.activityViewModels -import androidx.lifecycle.Observer import com.geeksville.analytics.DataPair import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.Logging @@ -71,7 +70,8 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { /// Pull the latest data from the model (discarding any user edits) private fun setGUIfromModel() { - val channel = UIViewModel.getChannel(model.radioConfig.value) + val radioConfig = model.radioConfig.value + val channel = UIViewModel.getChannel(radioConfig) editableCheckbox.isChecked = false // start locked if (channel != null) { @@ -85,6 +85,11 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { editableCheckbox.isEnabled = connected qrView.setImageBitmap(channel.getChannelQR()) + + val modemConfig = radioConfig?.channelSettings?.modemConfig + val channelOption = ChannelOption.fromConfig(modemConfig) + filled_exposed_dropdown.setText(getString(channelOption?.configRes ?: R.string.modem_config_unrecognized), false) + } else { qrView.visibility = View.INVISIBLE channelNameEdit.visibility = View.INVISIBLE @@ -205,12 +210,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging { shareChannel() } - model.radioConfig.observe(viewLifecycleOwner, Observer { + model.radioConfig.observe(viewLifecycleOwner, { setGUIfromModel() }) // If connection state changes, we might need to enable/disable buttons - model.isConnected.observe(viewLifecycleOwner, Observer { + model.isConnected.observe(viewLifecycleOwner, { setGUIfromModel() }) }