Hide the advance setting section if there is no error and their is only one available push distributor.
This commit is contained in:
parent
eacc591824
commit
f5b495d9ff
3 changed files with 56 additions and 43 deletions
|
|
@ -50,4 +50,10 @@ data class NotificationSettingsState(
|
||||||
val systemNotificationsEnabled: Boolean,
|
val systemNotificationsEnabled: Boolean,
|
||||||
val appNotificationsEnabled: Boolean,
|
val appNotificationsEnabled: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the advanced settings should be shown.
|
||||||
|
* This is true if the current push distributor is in a failure state or if there are multiple push distributors available.
|
||||||
|
*/
|
||||||
|
val showAdvancedSettings: Boolean = currentPushDistributor.isFailure() || availablePushDistributors.size > 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,15 @@ import kotlinx.collections.immutable.toImmutableList
|
||||||
open class NotificationSettingsStateProvider : PreviewParameterProvider<NotificationSettingsState> {
|
open class NotificationSettingsStateProvider : PreviewParameterProvider<NotificationSettingsState> {
|
||||||
override val values: Sequence<NotificationSettingsState>
|
override val values: Sequence<NotificationSettingsState>
|
||||||
get() = sequenceOf(
|
get() = sequenceOf(
|
||||||
aValidNotificationSettingsState(),
|
|
||||||
aValidNotificationSettingsState(systemNotificationsEnabled = false),
|
aValidNotificationSettingsState(systemNotificationsEnabled = false),
|
||||||
|
aValidNotificationSettingsState(),
|
||||||
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading),
|
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Loading),
|
||||||
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))),
|
aValidNotificationSettingsState(changeNotificationSettingAction = AsyncAction.Failure(Throwable("error"))),
|
||||||
|
aValidNotificationSettingsState(
|
||||||
|
availablePushDistributors = listOf("Firebase"),
|
||||||
|
changeNotificationSettingAction = AsyncAction.Failure(Throwable("error")),
|
||||||
|
),
|
||||||
|
aValidNotificationSettingsState(availablePushDistributors = listOf("Firebase")),
|
||||||
aValidNotificationSettingsState(showChangePushProviderDialog = true),
|
aValidNotificationSettingsState(showChangePushProviderDialog = true),
|
||||||
aValidNotificationSettingsState(currentPushDistributor = AsyncAction.Loading),
|
aValidNotificationSettingsState(currentPushDistributor = AsyncAction.Loading),
|
||||||
aValidNotificationSettingsState(currentPushDistributor = AsyncAction.Failure(Exception("Failed to change distributor"))),
|
aValidNotificationSettingsState(currentPushDistributor = AsyncAction.Failure(Exception("Failed to change distributor"))),
|
||||||
|
|
|
||||||
|
|
@ -181,50 +181,52 @@ private fun NotificationSettingsContentView(
|
||||||
onClick = onTroubleshootNotificationsClicked
|
onClick = onTroubleshootNotificationsClicked
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
PreferenceCategory(title = stringResource(id = CommonStrings.common_advanced_settings)) {
|
if (state.showAdvancedSettings) {
|
||||||
ListItem(
|
PreferenceCategory(title = stringResource(id = CommonStrings.common_advanced_settings)) {
|
||||||
headlineContent = {
|
ListItem(
|
||||||
Text(text = stringResource(id = R.string.screen_advanced_settings_push_provider_android))
|
headlineContent = {
|
||||||
},
|
Text(text = stringResource(id = R.string.screen_advanced_settings_push_provider_android))
|
||||||
trailingContent = when (state.currentPushDistributor) {
|
},
|
||||||
AsyncAction.Uninitialized,
|
trailingContent = when (state.currentPushDistributor) {
|
||||||
AsyncAction.Confirming,
|
AsyncAction.Uninitialized,
|
||||||
AsyncAction.Loading -> ListItemContent.Custom {
|
AsyncAction.Confirming,
|
||||||
CircularProgressIndicator(
|
AsyncAction.Loading -> ListItemContent.Custom {
|
||||||
modifier = Modifier
|
CircularProgressIndicator(
|
||||||
.progressSemantics()
|
modifier = Modifier
|
||||||
.size(20.dp),
|
.progressSemantics()
|
||||||
strokeWidth = 2.dp
|
.size(20.dp),
|
||||||
|
strokeWidth = 2.dp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is AsyncAction.Failure -> ListItemContent.Text(
|
||||||
|
stringResource(id = CommonStrings.common_error)
|
||||||
)
|
)
|
||||||
|
is AsyncAction.Success -> ListItemContent.Text(
|
||||||
|
state.currentPushDistributor.dataOrNull() ?: ""
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
if (state.currentPushDistributor.isReady()) {
|
||||||
|
state.eventSink(NotificationSettingsEvents.ChangePushProvider)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is AsyncAction.Failure -> ListItemContent.Text(
|
)
|
||||||
stringResource(id = CommonStrings.common_error)
|
}
|
||||||
)
|
if (state.showChangePushProviderDialog) {
|
||||||
is AsyncAction.Success -> ListItemContent.Text(
|
SingleSelectionDialog(
|
||||||
state.currentPushDistributor.dataOrNull() ?: ""
|
title = stringResource(id = R.string.screen_advanced_settings_choose_distributor_dialog_title_android),
|
||||||
)
|
options = state.availablePushDistributors.map {
|
||||||
},
|
ListOption(title = it)
|
||||||
onClick = {
|
}.toImmutableList(),
|
||||||
if (state.currentPushDistributor.isReady()) {
|
initialSelection = state.availablePushDistributors.indexOf(state.currentPushDistributor.dataOrNull()),
|
||||||
state.eventSink(NotificationSettingsEvents.ChangePushProvider)
|
onOptionSelected = { index ->
|
||||||
}
|
state.eventSink(
|
||||||
}
|
NotificationSettingsEvents.SetPushProvider(index)
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
if (state.showChangePushProviderDialog) {
|
onDismissRequest = { state.eventSink(NotificationSettingsEvents.CancelChangePushProvider) },
|
||||||
SingleSelectionDialog(
|
)
|
||||||
title = stringResource(id = R.string.screen_advanced_settings_choose_distributor_dialog_title_android),
|
}
|
||||||
options = state.availablePushDistributors.map {
|
|
||||||
ListOption(title = it)
|
|
||||||
}.toImmutableList(),
|
|
||||||
initialSelection = state.availablePushDistributors.indexOf(state.currentPushDistributor.dataOrNull()),
|
|
||||||
onOptionSelected = { index ->
|
|
||||||
state.eventSink(
|
|
||||||
NotificationSettingsEvents.SetPushProvider(index)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onDismissRequest = { state.eventSink(NotificationSettingsEvents.CancelChangePushProvider) },
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue