From 39da3050a3cfed9ae5c6403d3f4cb39038cf6c53 Mon Sep 17 00:00:00 2001
From: Tom Schwanke <tomschwanke80@gmail.com>
Date: Thu, 25 Jun 2020 12:57:33 +0200
Subject: [PATCH] Make entire SettingsRow toggle the setting (closes #455)
 (#466)

* fixes #455 by referencing the entire SettingsSwitchRow instead of just the SettingsSwitchRowSwitch

* Fixed Switched having no OnClickListener anymore and therefore not working. Switches AND Rows now have an OnClickListener to change the setting.

* implemented requested changes from harambasicluka; (in onClickListener) checking if row is enabled before executing action

* fixed formatting that caused quickBuild to fail

* moved the isEnabled check to the row instead of switch

Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
---
 .../ui/settings/SettingsNotificationFragment.kt    | 14 ++++++++++++++
 .../ui/settings/SettingsTracingFragment.kt         |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt
index 2baecf127..cdb1888d5 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/ui/settings/SettingsNotificationFragment.kt
@@ -64,9 +64,15 @@ class SettingsNotificationFragment : Fragment() {
         // Notifications about risk status
         val updateRiskNotificationSwitch =
             binding.settingsSwitchRowNotificationsRisk.settingsSwitchRowSwitch
+        // Additional click target to toggle switch
+        val updateRiskNotificationRow =
+            binding.settingsSwitchRowNotificationsRisk.settingsSwitchRow
         // Notifications about test status
         val updateTestNotificationSwitch =
             binding.settingsSwitchRowNotificationsTest.settingsSwitchRowSwitch
+        // Additional click target to toggle switch
+        val updateTestNotificationRow =
+            binding.settingsSwitchRowNotificationsTest.settingsSwitchRow
         // Settings
         val settingsRow = binding.settingsNotificationsCard.tracingStatusCardButton
         val goBack =
@@ -75,10 +81,18 @@ class SettingsNotificationFragment : Fragment() {
         updateRiskNotificationSwitch.setOnClickListener {
             settingsViewModel.toggleNotificationsRiskEnabled()
         }
+        // Additional click target to toggle switch
+        updateRiskNotificationRow.setOnClickListener {
+            if (updateRiskNotificationRow.isEnabled) settingsViewModel.toggleNotificationsRiskEnabled()
+        }
         // Update Test
         updateTestNotificationSwitch.setOnClickListener {
             settingsViewModel.toggleNotificationsTestEnabled()
         }
+        // Additional click target to toggle switch
+        updateTestNotificationRow.setOnClickListener {
+            if (updateTestNotificationRow.isEnabled) settingsViewModel.toggleNotificationsTestEnabled()
+        }
         goBack.setOnClickListener {
             (activity as MainActivity).goBack()
         }
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 2b41203d1..5cc6b9251 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
@@ -92,6 +92,7 @@ class SettingsTracingFragment : Fragment(),
     }
 
     private fun setButtonOnClickListener() {
+        val row = binding.settingsTracingSwitchRow.settingsSwitchRow
         val switch = binding.settingsTracingSwitchRow.settingsSwitchRowSwitch
         val back = binding.settingsTracingHeader.headerButtonBack.buttonIcon
         val bluetooth = binding.settingsTracingStatusBluetooth.tracingStatusCardButton
@@ -101,6 +102,10 @@ class SettingsTracingFragment : Fragment(),
         switch.setOnClickListener {
             startStopTracing()
         }
+        // Additional click target to toggle switch
+        row.setOnClickListener {
+            if (row.isEnabled) startStopTracing()
+        }
         back.setOnClickListener {
             (activity as MainActivity).goBack()
         }
-- 
GitLab