From 2db640ba230e9d4eeefdfe45c6f36ff31182a162 Mon Sep 17 00:00:00 2001 From: harambasicluka <64483219+harambasicluka@users.noreply.github.com> Date: Tue, 2 Jun 2020 12:07:27 +0200 Subject: [PATCH] Tracing start/stop fix due to missing handling inside tracing (#99) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakob Möller <jakob.moeller@sap.com> --- .../ui/settings/SettingsTracingFragment.kt | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt index 7a7064c9e..20055ffcb 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsTracingFragment.kt @@ -89,27 +89,16 @@ class SettingsTracingFragment : BaseFragment(), exception?.localizedMessage ?: "Unknown Error", Toast.LENGTH_SHORT ).show() - tracingViewModel.refreshIsTracingEnabled() } private fun setButtonOnClickListener() { val switch = binding.settingsTracingSwitchRow.settingsSwitchRowSwitch - val row = binding.settingsTracingSwitchRow.settingsSwitchRow internalExposureNotificationPermissionHelper = InternalExposureNotificationPermissionHelper(this, this) switch.setOnCheckedChangeListener { _, _ -> // android calls this listener also on start, so it has to be verified if the user pressed the switch if (switch.isPressed) { - ViewBlocker.runAndBlockInteraction(arrayOf(row, switch)) { - startStopTracing() - } - } - } - row.setOnClickListener { - ViewBlocker.runAndBlockInteraction(arrayOf(row, switch)) { - // only if the switch is enabled the user is allowed to toggle it, this implements the - // same behaviour if he clicks on the row - if (switch.isEnabled) { + ViewBlocker.runAndBlockInteraction(arrayOf(switch)) { startStopTracing() } } @@ -126,10 +115,9 @@ class SettingsTracingFragment : BaseFragment(), } private fun startStopTracing() { - if (tracingViewModel.isTracingEnabled.value != null) { - // if tracing is enabled when listener is activated it should be disabled - if (tracingViewModel.isTracingEnabled.value!!) { - lifecycleScope.launch { + // if tracing is enabled when listener is activated it should be disabled + lifecycleScope.launch { + if (InternalExposureNotificationClient.asyncIsEnabled()) { try { Toast.makeText( requireContext(), @@ -137,24 +125,20 @@ class SettingsTracingFragment : BaseFragment(), Toast.LENGTH_SHORT ) .show() - tracingViewModel.refreshIsTracingEnabled() + + InternalExposureNotificationClient.asyncStop() } catch (exception: Exception) { exception.report( ExceptionCategory.EXPOSURENOTIFICATION, TAG, null ) - tracingViewModel.refreshIsTracingEnabled() } - InternalExposureNotificationClient.asyncStop() tracingViewModel.refreshIsTracingEnabled() BackgroundWorkScheduler.stopWorkScheduler() - } } else { internalExposureNotificationPermissionHelper.requestPermissionToStartTracing() } } - tracingViewModel.refreshIsTracingEnabled() - settingsViewModel.refreshBluetoothEnabled() } } -- GitLab