Merge pull request #152 from lgoix/channeloption

Show network range setting when locked #138
This commit is contained in:
Lgx
2020-09-04 13:16:45 -04:00
committed by GitHub
2 changed files with 20 additions and 5 deletions

View File

@@ -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
}
}
}

View File

@@ -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()
})
}