sforkowany z mirror/meshtastic-android
region setting is finished
rodzic
bd1885aaf2
commit
d15ff7ed36
|
@ -579,32 +579,42 @@ 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)
|
||||
spinner.onItemSelectedListener = null
|
||||
if(region != null) {
|
||||
val spinner = binding.regionSpinner
|
||||
var regionIndex = regions.indexOf(region.name)
|
||||
if(regionIndex == -1) // Not found, probably because the device has a region our app doesn't yet understand. Punt and say Unset
|
||||
regionIndex = regions.indexOf(RadioConfigProtos.RegionCode.Unset.name)
|
||||
regionIndex = unsetIndex
|
||||
|
||||
// We don't want to be notified of our own changes, so turn off listener while making them
|
||||
spinner.onItemSelectedListener = null
|
||||
spinner.setSelection(regionIndex, false)
|
||||
spinner.onItemSelectedListener = regionSpinnerListener
|
||||
spinner.isEnabled = true
|
||||
}
|
||||
else {
|
||||
spinner.setSelection(unsetIndex, false)
|
||||
spinner.isEnabled = false // leave disabled, because we can't get our region
|
||||
}
|
||||
|
||||
// If actively connected possibly let the user update firmware
|
||||
refreshUpdateButton()
|
||||
|
||||
// Update the status string
|
||||
// Update the status string (highest priority messages first)
|
||||
val info = model.myNodeInfo.value
|
||||
when (connected) {
|
||||
MeshService.ConnectionState.CONNECTED -> {
|
||||
val statusText = binding.scanStatusText
|
||||
when {
|
||||
region == RadioConfigProtos.RegionCode.Unset ->
|
||||
statusText.text = getString(R.string.must_set_region)
|
||||
|
||||
connected == MeshService.ConnectionState.CONNECTED -> {
|
||||
val fwStr = info?.firmwareString ?: ""
|
||||
binding.scanStatusText.text = getString(R.string.connected_to).format(fwStr)
|
||||
statusText.text = getString(R.string.connected_to).format(fwStr)
|
||||
}
|
||||
MeshService.ConnectionState.DISCONNECTED ->
|
||||
binding.scanStatusText.text = getString(R.string.not_connected)
|
||||
MeshService.ConnectionState.DEVICE_SLEEP ->
|
||||
binding.scanStatusText.text = getString(R.string.connected_sleeping)
|
||||
connected == MeshService.ConnectionState.DISCONNECTED ->
|
||||
statusText.text = getString(R.string.not_connected)
|
||||
connected == MeshService.ConnectionState.DEVICE_SLEEP ->
|
||||
statusText.text = getString(R.string.connected_sleeping)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -620,6 +630,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
exceptionToSnackbar(requireView()) {
|
||||
model.region = asProto
|
||||
}
|
||||
updateNodeInfo() // We might have just changed Unset to set
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||
|
@ -627,7 +638,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
}
|
||||
}
|
||||
|
||||
/// the sorted list of region names
|
||||
/// the sorted list of region names like arrayOf("US", "CN", "EU488")
|
||||
private val regions = RadioConfigProtos.RegionCode.values().filter {
|
||||
it != RadioConfigProtos.RegionCode.UNRECOGNIZED
|
||||
}.map {
|
||||
|
@ -637,7 +648,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
/// Setup the ui widgets unrelated to BLE scanning
|
||||
private fun initCommonUI() {
|
||||
|
||||
// val regions = arrayOf("US", "CN", "EU488")
|
||||
// init our region spinner
|
||||
val spinner = binding.regionSpinner
|
||||
val regionAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, regions)
|
||||
regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
|
|
|
@ -56,17 +56,29 @@
|
|||
android:singleLine="true" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/regionLabel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/region"
|
||||
app:layout_constraintEnd_toEndOf="@+id/regionSpinner"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Region" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/regionSpinner"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:entries="@array/regions"
|
||||
android:theme="@style/AppTheme.Spinner"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/regionLabel"
|
||||
app:layout_constraintStart_toEndOf="@+id/usernameView"
|
||||
android:entries="@array/regions"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
|
|
|
@ -92,4 +92,6 @@
|
|||
<string name="firmware_too_old">Firmware update required</string>
|
||||
<string name="firmware_old">The radio firmware is too old to talk to this application, please go to the settings pane and choose "Update Firmware". For more information on this see <a href="https://www.meshtastic.org/software/firmware-too-old.html">our wiki</a>.</string>
|
||||
<string name="okay">Okay</string>
|
||||
<string name="must_set_region">You must set a region!</string>
|
||||
<string name="region">Region</string>
|
||||
</resources>
|
||||
|
|
Ładowanie…
Reference in New Issue