From 3f0e789997aaf43e23ee02553537d091caa96dda Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Mon, 1 Jul 2024 19:54:44 -0400 Subject: [PATCH] feat: Unified notification type for enabling / disabling --- .../im/angry/openeuicc/ui/EuiccManagementFragment.kt | 6 +----- .../java/im/angry/openeuicc/ui/SettingsFragment.kt | 7 ++----- .../java/im/angry/openeuicc/util/PreferenceUtils.kt | 9 +++------ app-common/src/main/res/values/strings.xml | 6 ++---- app-common/src/main/res/xml/pref_settings.xml | 11 +++-------- .../im/angry/openeuicc/service/OpenEuiccService.kt | 3 +-- 6 files changed, 12 insertions(+), 30 deletions(-) diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt index b83b241..00d7629 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/EuiccManagementFragment.kt @@ -204,11 +204,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener, } } - if (enable) { - preferenceRepository.notificationEnableFlow.first() - } else { - preferenceRepository.notificationDisableFlow.first() - } + preferenceRepository.notificationSwitchFlow.first() } refresh() fab.isEnabled = true diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/SettingsFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/SettingsFragment.kt index 5de89b2..e3336a0 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/SettingsFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/SettingsFragment.kt @@ -39,11 +39,8 @@ class SettingsFragment: PreferenceFragmentCompat() { findPreference("pref_notifications_delete") ?.bindBooleanFlow(preferenceRepository.notificationDeleteFlow, PreferenceKeys.NOTIFICATION_DELETE) - findPreference("pref_notifications_enable") - ?.bindBooleanFlow(preferenceRepository.notificationEnableFlow, PreferenceKeys.NOTIFICATION_ENABLE) - - findPreference("pref_notifications_disable") - ?.bindBooleanFlow(preferenceRepository.notificationDisableFlow, PreferenceKeys.NOTIFICATION_DISABLE) + findPreference("pref_notifications_switch") + ?.bindBooleanFlow(preferenceRepository.notificationSwitchFlow, PreferenceKeys.NOTIFICATION_SWITCH) } private fun CheckBoxPreference.bindBooleanFlow(flow: Flow, key: Preferences.Key) { diff --git a/app-common/src/main/java/im/angry/openeuicc/util/PreferenceUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/PreferenceUtils.kt index b9a854e..98d9812 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/PreferenceUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/PreferenceUtils.kt @@ -24,6 +24,7 @@ object PreferenceKeys { val NOTIFICATION_DELETE = booleanPreferencesKey("notification_delete") val NOTIFICATION_ENABLE = booleanPreferencesKey("notification_enable") val NOTIFICATION_DISABLE = booleanPreferencesKey("notification_disable") + val NOTIFICATION_SWITCH = booleanPreferencesKey("notification_switch") } class PreferenceRepository(context: Context) { @@ -37,12 +38,8 @@ class PreferenceRepository(context: Context) { val notificationDeleteFlow: Flow = dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DELETE] ?: true } - // Enabling / disabling notifications are not sent by default - val notificationEnableFlow: Flow = - dataStore.data.map { it[PreferenceKeys.NOTIFICATION_ENABLE] ?: false } - - val notificationDisableFlow: Flow = - dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DISABLE] ?: false } + val notificationSwitchFlow: Flow = + dataStore.data.map { it[PreferenceKeys.NOTIFICATION_SWITCH] ?: false } suspend fun updatePreference(key: Preferences.Key, value: T) { dataStore.edit { diff --git a/app-common/src/main/res/values/strings.xml b/app-common/src/main/res/values/strings.xml index bf6606a..21b84d6 100644 --- a/app-common/src/main/res/values/strings.xml +++ b/app-common/src/main/res/values/strings.xml @@ -67,10 +67,8 @@ Send notifications for downloading profiles Deletion Send notifications for deleting profiles - Enabling - Send notifications for enabling profiles\nNote that this type of notification is unreliable. - Disabling - Send notifications for disabling profiles\nNote that this type of notification is unreliable. + Switching + Send notifications for switching profiles\nNote that this type of notification is unreliable. Advanced Logs View recent debug logs of the application diff --git a/app-common/src/main/res/xml/pref_settings.xml b/app-common/src/main/res/xml/pref_settings.xml index 39d64f3..34466fd 100644 --- a/app-common/src/main/res/xml/pref_settings.xml +++ b/app-common/src/main/res/xml/pref_settings.xml @@ -16,14 +16,9 @@ app:key="pref_notifications_delete" /> - + app:title="@string/pref_notifications_switch" + app:summary="@string/pref_notifications_switch_desc" + app:key="pref_notifications_switch" />