feat: Unified notification type for enabling / disabling
Some checks failed
/ build-debug (push) Has been cancelled
Some checks failed
/ build-debug (push) Has been cancelled
This commit is contained in:
parent
c7afeea845
commit
3f0e789997
|
@ -204,11 +204,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enable) {
|
preferenceRepository.notificationSwitchFlow.first()
|
||||||
preferenceRepository.notificationEnableFlow.first()
|
|
||||||
} else {
|
|
||||||
preferenceRepository.notificationDisableFlow.first()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
refresh()
|
refresh()
|
||||||
fab.isEnabled = true
|
fab.isEnabled = true
|
||||||
|
|
|
@ -39,11 +39,8 @@ class SettingsFragment: PreferenceFragmentCompat() {
|
||||||
findPreference<CheckBoxPreference>("pref_notifications_delete")
|
findPreference<CheckBoxPreference>("pref_notifications_delete")
|
||||||
?.bindBooleanFlow(preferenceRepository.notificationDeleteFlow, PreferenceKeys.NOTIFICATION_DELETE)
|
?.bindBooleanFlow(preferenceRepository.notificationDeleteFlow, PreferenceKeys.NOTIFICATION_DELETE)
|
||||||
|
|
||||||
findPreference<CheckBoxPreference>("pref_notifications_enable")
|
findPreference<CheckBoxPreference>("pref_notifications_switch")
|
||||||
?.bindBooleanFlow(preferenceRepository.notificationEnableFlow, PreferenceKeys.NOTIFICATION_ENABLE)
|
?.bindBooleanFlow(preferenceRepository.notificationSwitchFlow, PreferenceKeys.NOTIFICATION_SWITCH)
|
||||||
|
|
||||||
findPreference<CheckBoxPreference>("pref_notifications_disable")
|
|
||||||
?.bindBooleanFlow(preferenceRepository.notificationDisableFlow, PreferenceKeys.NOTIFICATION_DISABLE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CheckBoxPreference.bindBooleanFlow(flow: Flow<Boolean>, key: Preferences.Key<Boolean>) {
|
private fun CheckBoxPreference.bindBooleanFlow(flow: Flow<Boolean>, key: Preferences.Key<Boolean>) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ object PreferenceKeys {
|
||||||
val NOTIFICATION_DELETE = booleanPreferencesKey("notification_delete")
|
val NOTIFICATION_DELETE = booleanPreferencesKey("notification_delete")
|
||||||
val NOTIFICATION_ENABLE = booleanPreferencesKey("notification_enable")
|
val NOTIFICATION_ENABLE = booleanPreferencesKey("notification_enable")
|
||||||
val NOTIFICATION_DISABLE = booleanPreferencesKey("notification_disable")
|
val NOTIFICATION_DISABLE = booleanPreferencesKey("notification_disable")
|
||||||
|
val NOTIFICATION_SWITCH = booleanPreferencesKey("notification_switch")
|
||||||
}
|
}
|
||||||
|
|
||||||
class PreferenceRepository(context: Context) {
|
class PreferenceRepository(context: Context) {
|
||||||
|
@ -37,12 +38,8 @@ class PreferenceRepository(context: Context) {
|
||||||
val notificationDeleteFlow: Flow<Boolean> =
|
val notificationDeleteFlow: Flow<Boolean> =
|
||||||
dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DELETE] ?: true }
|
dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DELETE] ?: true }
|
||||||
|
|
||||||
// Enabling / disabling notifications are not sent by default
|
val notificationSwitchFlow: Flow<Boolean> =
|
||||||
val notificationEnableFlow: Flow<Boolean> =
|
dataStore.data.map { it[PreferenceKeys.NOTIFICATION_SWITCH] ?: false }
|
||||||
dataStore.data.map { it[PreferenceKeys.NOTIFICATION_ENABLE] ?: false }
|
|
||||||
|
|
||||||
val notificationDisableFlow: Flow<Boolean> =
|
|
||||||
dataStore.data.map { it[PreferenceKeys.NOTIFICATION_DISABLE] ?: false }
|
|
||||||
|
|
||||||
suspend fun <T> updatePreference(key: Preferences.Key<T>, value: T) {
|
suspend fun <T> updatePreference(key: Preferences.Key<T>, value: T) {
|
||||||
dataStore.edit {
|
dataStore.edit {
|
||||||
|
|
|
@ -67,10 +67,8 @@
|
||||||
<string name="pref_notifications_download_desc">Send notifications for <i>downloading</i> profiles</string>
|
<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">Deletion</string>
|
||||||
<string name="pref_notifications_delete_desc">Send notifications for <i>deleting</i> profiles</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_switch">Switching</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_switch_desc">Send notifications for <i>switching</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_advanced">Advanced</string>
|
<string name="pref_advanced">Advanced</string>
|
||||||
<string name="pref_advanced_logs">Logs</string>
|
<string name="pref_advanced_logs">Logs</string>
|
||||||
<string name="pref_advanced_logs_desc">View recent debug logs of the application</string>
|
<string name="pref_advanced_logs_desc">View recent debug logs of the application</string>
|
||||||
|
|
|
@ -16,14 +16,9 @@
|
||||||
app:key="pref_notifications_delete" />
|
app:key="pref_notifications_delete" />
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:title="@string/pref_notifications_enable"
|
app:title="@string/pref_notifications_switch"
|
||||||
app:summary="@string/pref_notifications_enable_desc"
|
app:summary="@string/pref_notifications_switch_desc"
|
||||||
app:key="pref_notifications_enable" />
|
app:key="pref_notifications_switch" />
|
||||||
<CheckBoxPreference
|
|
||||||
app:iconSpaceReserved="false"
|
|
||||||
app:title="@string/pref_notifications_disable"
|
|
||||||
app:summary="@string/pref_notifications_disable_desc"
|
|
||||||
app:key="pref_notifications_disable" />
|
|
||||||
</im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory>
|
</im.angry.openeuicc.ui.preference.LongSummaryPreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|
|
@ -316,8 +316,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
// TODO: The enable / disable operations should really be one
|
preferenceRepository.notificationSwitchFlow.first()
|
||||||
preferenceRepository.notificationEnableFlow.first()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue