kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: replace hardcoded config totals
rodzic
9425b4d172
commit
4ab9e18a82
|
@ -31,6 +31,7 @@ import com.geeksville.mesh.android.hideKeyboard
|
||||||
import com.geeksville.mesh.MainActivity
|
import com.geeksville.mesh.MainActivity
|
||||||
import com.geeksville.mesh.R
|
import com.geeksville.mesh.R
|
||||||
import com.geeksville.mesh.ConfigProtos
|
import com.geeksville.mesh.ConfigProtos
|
||||||
|
import com.geeksville.mesh.ModuleConfigProtos
|
||||||
import com.geeksville.mesh.android.*
|
import com.geeksville.mesh.android.*
|
||||||
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
import com.geeksville.mesh.databinding.SettingsFragmentBinding
|
||||||
import com.geeksville.mesh.model.BTScanModel
|
import com.geeksville.mesh.model.BTScanModel
|
||||||
|
@ -306,23 +307,26 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
model.localConfig.asLiveData().observe(viewLifecycleOwner) {
|
model.localConfig.asLiveData().observe(viewLifecycleOwner) {
|
||||||
if (!model.isConnected()) {
|
if (!model.isConnected()) {
|
||||||
val configCount = it.allFields.size
|
val configCount = it.allFields.size
|
||||||
|
val configTotal = ConfigProtos.Config.getDescriptor().fields.size
|
||||||
if (configCount > 0)
|
if (configCount > 0)
|
||||||
binding.scanStatusText.text = "Device config ($configCount / 7)"
|
binding.scanStatusText.text = "Device config ($configCount / $configTotal)"
|
||||||
} else updateNodeInfo()
|
} else updateNodeInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
model.moduleConfig.asLiveData().observe(viewLifecycleOwner) {
|
model.moduleConfig.asLiveData().observe(viewLifecycleOwner) {
|
||||||
if (!model.isConnected()) {
|
if (!model.isConnected()) {
|
||||||
val moduleCount = it.allFields.size
|
val moduleCount = it.allFields.size
|
||||||
|
val moduleTotal = ModuleConfigProtos.ModuleConfig.getDescriptor().fields.size
|
||||||
if (moduleCount > 0)
|
if (moduleCount > 0)
|
||||||
binding.scanStatusText.text = "Module config ($moduleCount / 8)"
|
binding.scanStatusText.text = "Module config ($moduleCount / $moduleTotal)"
|
||||||
} else updateNodeInfo()
|
} else updateNodeInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
model.channels.asLiveData().observe(viewLifecycleOwner) {
|
model.channels.asLiveData().observe(viewLifecycleOwner) {
|
||||||
if (!model.isConnected()) it.protobuf.let { ch ->
|
if (!model.isConnected()) it.protobuf.let { ch ->
|
||||||
|
val maxChannels = model.myNodeInfo.value?.maxChannels
|
||||||
if (!ch.hasLoraConfig() && ch.settingsCount > 0)
|
if (!ch.hasLoraConfig() && ch.settingsCount > 0)
|
||||||
binding.scanStatusText.text = "Channels (${ch.settingsCount} / 8)"
|
binding.scanStatusText.text = "Channels (${ch.settingsCount} / $maxChannels)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +506,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
// per https://developer.android.com/guide/topics/connectivity/bluetooth/find-ble-devices
|
// per https://developer.android.com/guide/topics/connectivity/bluetooth/find-ble-devices
|
||||||
private fun scanLeDevice() {
|
private fun scanLeDevice() {
|
||||||
var scanning = false
|
var scanning = false
|
||||||
val SCAN_PERIOD: Long = 10000 // Stops scanning after 10 seconds
|
|
||||||
|
|
||||||
if (!scanning) { // Stops scanning after a pre-defined scan period.
|
if (!scanning) { // Stops scanning after a pre-defined scan period.
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
|
@ -619,4 +622,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
if (binding.provideLocationCheckbox.isChecked)
|
if (binding.provideLocationCheckbox.isChecked)
|
||||||
checkLocationEnabled(getString(R.string.location_disabled))
|
checkLocationEnabled(getString(R.string.location_disabled))
|
||||||
}
|
}
|
||||||
|
companion object {
|
||||||
|
const val SCAN_PERIOD: Long = 10000 // Stops scanning after 10 seconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue