From d0614c7934aa7e6392b9cddd801d9d4a9eb10209 Mon Sep 17 00:00:00 2001 From: andrekir Date: Sat, 8 Jan 2022 16:30:06 -0300 Subject: [PATCH] update initCommonUI --- .../geeksville/mesh/ui/SettingsFragment.kt | 70 ++++++++----------- app/src/main/res/layout/settings_fragment.xml | 1 + 2 files changed, 29 insertions(+), 42 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 9888caf57..ce5b6dd8b 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -627,6 +627,20 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { updateNodeInfo() }) + scanModel.errorText.observe(viewLifecycleOwner, Observer { errMsg -> + if (errMsg != null) { + binding.scanStatusText.text = errMsg + } + }) + + scanModel.devices.observe( + viewLifecycleOwner, + Observer { devices -> updateDevicesButtons(devices) }) + + model.isConnected.observe( + viewLifecycleOwner, + { updateDevicesButtons(scanModel.devices.value) }) + binding.updateFirmwareButton.setOnClickListener { doFirmwareUpdate() } @@ -727,12 +741,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { } } - /// Show the GUI for classic scanning - private fun showClassicWidgets(visible: Int) { - binding.scanProgressBar.visibility = visible - binding.deviceRadioGroup.visibility = visible - } - private fun updateDevicesButtons(devices: MutableMap?) { // Remove the old radio buttons and repopulate binding.deviceRadioGroup.removeAllViews() @@ -790,42 +798,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { View.GONE else View.VISIBLE - } - - /// Setup the GUI to do a classic (pre SDK 26 BLE scan) - private fun initClassicScan() { - // Turn off the widgets for the new API (we turn on/off hte classic widgets when we start scanning - binding.changeRadioButton.visibility = View.GONE - - showClassicWidgets(View.VISIBLE) - - model.bluetoothEnabled.observe(viewLifecycleOwner, Observer { enabled -> - if (enabled) - scanModel.startScan() - else - scanModel.stopScan() - }) - - scanModel.errorText.observe(viewLifecycleOwner, Observer { errMsg -> - if (errMsg != null) { - binding.scanStatusText.text = errMsg - } - }) - - scanModel.devices.observe( - viewLifecycleOwner, - Observer { devices -> updateDevicesButtons(devices) }) - - model.isConnected.observe( - viewLifecycleOwner, - { updateDevicesButtons(scanModel.devices.value) }) - } - - private fun initModernScan() { - // Turn off the widgets for the classic API - binding.scanProgressBar.visibility = View.GONE - binding.deviceRadioGroup.visibility = View.GONE - binding.changeRadioButton.visibility = View.VISIBLE val curRadio = RadioInterfaceService.getBondedDeviceAddress(requireContext()) @@ -834,6 +806,20 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { } else { binding.scanStatusText.text = getString(R.string.not_paired_yet) } + } + + private fun initClassicScan() { + + model.bluetoothEnabled.observe(viewLifecycleOwner, Observer { enabled -> + if (enabled) + scanModel.startScan() + else + scanModel.stopScan() + }) + } + + private fun initModernScan() { + binding.changeRadioButton.setOnClickListener { myActivity.startCompanionScan() } diff --git a/app/src/main/res/layout/settings_fragment.xml b/app/src/main/res/layout/settings_fragment.xml index c9d1372b3..48190d6a2 100644 --- a/app/src/main/res/layout/settings_fragment.xml +++ b/app/src/main/res/layout/settings_fragment.xml @@ -85,6 +85,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" + android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/deviceRadioGroup" />