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
6 changed files with 12 additions and 30 deletions
|
@ -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
|
||||
|
|
|
@ -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>) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -316,8 +316,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
|||
}
|
||||
|
||||
runBlocking {
|
||||
// TODO: The enable / disable operations should really be one
|
||||
preferenceRepository.notificationEnableFlow.first()
|
||||
preferenceRepository.notificationSwitchFlow.first()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue