From f507bf41046d6829c8e69bd5e39447c9d58e6d5c Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Thu, 21 Apr 2022 13:45:53 +0200 Subject: [PATCH] Fixes #1301 --- .../preferences/PreferencesFragment.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/PreferencesFragment.kt b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/PreferencesFragment.kt index 736ff65fc..97c13e2d4 100644 --- a/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/PreferencesFragment.kt +++ b/Habitica/src/main/java/com/habitrpg/android/habitica/ui/fragments/preferences/PreferencesFragment.kt @@ -70,14 +70,6 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare val useReminder = preferenceManager.sharedPreferences?.getBoolean("use_reminder", false) timePreference?.isEnabled = useReminder ?: false - pushNotificationsPreference = findPreference("pushNotifications") as? PreferenceScreen - val usePushNotifications = preferenceManager.sharedPreferences?.getBoolean("usePushNotifications", true) - pushNotificationsPreference?.isEnabled = usePushNotifications ?: false - - emailNotificationsPreference = findPreference("emailNotifications") as? PreferenceScreen - val useEmailNotifications = preferenceManager.sharedPreferences?.getBoolean("useEmailNotifications", true) - emailNotificationsPreference?.isEnabled = useEmailNotifications ?: false - classSelectionPreference = findPreference("choose_class") val weekdayPreference = findPreference("FirstDayOfTheWeek") as? ListPreference @@ -193,15 +185,17 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare "usePushNotifications" -> { val userPushNotifications = sharedPreferences.getBoolean(key, false) pushNotificationsPreference?.isEnabled = userPushNotifications + userRepository.updateUser("preferences.pushNotifications.unsubscribeFromAll", userPushNotifications).subscribe() if (userPushNotifications) { pushNotificationManager.addPushDeviceUsingStoredToken() } else { pushNotificationManager.removePushDeviceUsingStoredToken() } } - "useEmailNotifications" -> { + "useEmails" -> { val useEmailNotifications = sharedPreferences.getBoolean(key, false) emailNotificationsPreference?.isEnabled = useEmailNotifications + userRepository.updateUser("preferences.emailNotifications.unsubscribeFromAll", useEmailNotifications).subscribe() } "cds_time" -> { val timeval = sharedPreferences.getString("cds_time", "0") ?: "0" @@ -345,6 +339,18 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare val inbox = user?.inbox disablePMsPreference?.isChecked = inbox?.optOut ?: true + val usePushPreference = findPreference("usePushNotifications") as? CheckBoxPreference + pushNotificationsPreference = findPreference("pushNotifications") as? PreferenceScreen + val usePushNotifications = user?.preferences?.pushNotifications?.unsubscribeFromAll ?: false + pushNotificationsPreference?.isEnabled = usePushNotifications + usePushPreference?.isChecked = usePushNotifications + + val useEmailPreference = findPreference("useEmails") as? CheckBoxPreference + emailNotificationsPreference = findPreference("emailNotifications") as? PreferenceScreen + val useEmailNotifications = user?.preferences?.emailNotifications?.unsubscribeFromAll ?: false + emailNotificationsPreference?.isEnabled = useEmailNotifications + useEmailPreference?.isChecked = useEmailNotifications + if (configManager.testingLevel() == AppTestingLevel.STAFF || BuildConfig.DEBUG) { serverUrlPreference?.isVisible = true taskListPreference?.isVisible = true