ソースを参照

feat: Unified notification type for enabling / disabling

Peter Cai 1 年間 前
コミット
3f0e789997

+ 1 - 5
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

+ 2 - 5
app-common/src/main/java/im/angry/openeuicc/ui/SettingsFragment.kt

@@ -39,11 +39,8 @@ class SettingsFragment: PreferenceFragmentCompat() {
         findPreference<CheckBoxPreference>("pref_notifications_delete")
             ?.bindBooleanFlow(preferenceRepository.notificationDeleteFlow, PreferenceKeys.NOTIFICATION_DELETE)
 
-        findPreference<CheckBoxPreference>("pref_notifications_enable")
-            ?.bindBooleanFlow(preferenceRepository.notificationEnableFlow, PreferenceKeys.NOTIFICATION_ENABLE)
-
-        findPreference<CheckBoxPreference>("pref_notifications_disable")
-            ?.bindBooleanFlow(preferenceRepository.notificationDisableFlow, PreferenceKeys.NOTIFICATION_DISABLE)
+        findPreference<CheckBoxPreference>("pref_notifications_switch")
+            ?.bindBooleanFlow(preferenceRepository.notificationSwitchFlow, PreferenceKeys.NOTIFICATION_SWITCH)
     }
 
     private fun CheckBoxPreference.bindBooleanFlow(flow: Flow<Boolean>, key: Preferences.Key<Boolean>) {

+ 3 - 6
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<Boolean> =
         dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DELETE] ?: true }
 
-    // Enabling / disabling notifications are not sent by default
-    val notificationEnableFlow: Flow<Boolean> =
-        dataStore.data.map { it[PreferenceKeys.NOTIFICATION_ENABLE] ?: false }
-
-    val notificationDisableFlow: Flow<Boolean> =
-        dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DISABLE] ?: false }
+    val notificationSwitchFlow: Flow<Boolean> =
+        dataStore.data.map { it[PreferenceKeys.NOTIFICATION_SWITCH] ?: false }
 
     suspend fun <T> updatePreference(key: Preferences.Key<T>, value: T) {
         dataStore.edit {

+ 2 - 4
app-common/src/main/res/values/strings.xml

@@ -67,10 +67,8 @@
     <string name="pref_notifications_download_desc">Send notifications for <i>downloading</i> profiles</string>
     <string name="pref_notifications_delete">Deletion</string>
     <string name="pref_notifications_delete_desc">Send notifications for <i>deleting</i> profiles</string>
-    <string name="pref_notifications_enable">Enabling</string>
-    <string name="pref_notifications_enable_desc">Send notifications for <i>enabling</i> profiles\nNote that this type of notification is unreliable.</string>
-    <string name="pref_notifications_disable">Disabling</string>
-    <string name="pref_notifications_disable_desc">Send notifications for <i>disabling</i> profiles\nNote that this type of notification is unreliable.</string>
+    <string name="pref_notifications_switch">Switching</string>
+    <string name="pref_notifications_switch_desc">Send notifications for <i>switching</i> profiles\nNote that this type of notification is unreliable.</string>
     <string name="pref_advanced">Advanced</string>
     <string name="pref_advanced_logs">Logs</string>
     <string name="pref_advanced_logs_desc">View recent debug logs of the application</string>

+ 3 - 8
app-common/src/main/res/xml/pref_settings.xml

@@ -16,14 +16,9 @@
             app:key="pref_notifications_delete" />
         <CheckBoxPreference
             app:iconSpaceReserved="false"
-            app:title="@string/pref_notifications_enable"
-            app:summary="@string/pref_notifications_enable_desc"
-            app:key="pref_notifications_enable" />
-        <CheckBoxPreference
-            app:iconSpaceReserved="false"
-            app:title="@string/pref_notifications_disable"
-            app:summary="@string/pref_notifications_disable_desc"
-            app:key="pref_notifications_disable" />
+            app:title="@string/pref_notifications_switch"
+            app:summary="@string/pref_notifications_switch_desc"
+            app:key="pref_notifications_switch" />
     </im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory>
 
     <PreferenceCategory

+ 1 - 2
app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt

@@ -316,8 +316,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
                 }
 
                 runBlocking {
-                    // TODO: The enable / disable operations should really be one
-                    preferenceRepository.notificationEnableFlow.first()
+                    preferenceRepository.notificationSwitchFlow.first()
                 }
             }