From 4ab9e18a8217a6b1dcf85b9fec1075b0d374e975 Mon Sep 17 00:00:00 2001 From: andrekir Date: Fri, 6 Jan 2023 22:20:39 -0300 Subject: [PATCH] refactor: replace hardcoded config totals --- .../com/geeksville/mesh/ui/SettingsFragment.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index b2b4bd35..4a38b69f 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -31,6 +31,7 @@ import com.geeksville.mesh.android.hideKeyboard import com.geeksville.mesh.MainActivity import com.geeksville.mesh.R import com.geeksville.mesh.ConfigProtos +import com.geeksville.mesh.ModuleConfigProtos import com.geeksville.mesh.android.* import com.geeksville.mesh.databinding.SettingsFragmentBinding import com.geeksville.mesh.model.BTScanModel @@ -306,23 +307,26 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { model.localConfig.asLiveData().observe(viewLifecycleOwner) { if (!model.isConnected()) { val configCount = it.allFields.size + val configTotal = ConfigProtos.Config.getDescriptor().fields.size if (configCount > 0) - binding.scanStatusText.text = "Device config ($configCount / 7)" + binding.scanStatusText.text = "Device config ($configCount / $configTotal)" } else updateNodeInfo() } model.moduleConfig.asLiveData().observe(viewLifecycleOwner) { if (!model.isConnected()) { val moduleCount = it.allFields.size + val moduleTotal = ModuleConfigProtos.ModuleConfig.getDescriptor().fields.size if (moduleCount > 0) - binding.scanStatusText.text = "Module config ($moduleCount / 8)" + binding.scanStatusText.text = "Module config ($moduleCount / $moduleTotal)" } else updateNodeInfo() } model.channels.asLiveData().observe(viewLifecycleOwner) { if (!model.isConnected()) it.protobuf.let { ch -> + val maxChannels = model.myNodeInfo.value?.maxChannels 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 private fun scanLeDevice() { var scanning = false - val SCAN_PERIOD: Long = 10000 // Stops scanning after 10 seconds if (!scanning) { // Stops scanning after a pre-defined scan period. Handler(Looper.getMainLooper()).postDelayed({ @@ -619,4 +622,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { if (binding.provideLocationCheckbox.isChecked) checkLocationEnabled(getString(R.string.location_disabled)) } + companion object { + const val SCAN_PERIOD: Long = 10000 // Stops scanning after 10 seconds + } }