Add a shortcut to navigate to the notification settings in case of error.

This commit is contained in:
Benoit Marty
2024-06-17 16:20:23 +02:00
parent 2533dff00c
commit 2e8b63c006
6 changed files with 37 additions and 3 deletions

View File

@@ -238,7 +238,12 @@ class LoggedInFlowNode @AssistedInject constructor(
return when (navTarget) {
NavTarget.Placeholder -> createNode<PlaceholderNode>(buildContext)
NavTarget.LoggedInPermanent -> {
createNode<LoggedInNode>(buildContext)
val callback = object : LoggedInNode.Callback {
override fun navigateToNotificationTroubleshoot() {
backstack.push(NavTarget.Settings(PreferencesEntryPoint.InitialTarget.NotificationTroubleshoot))
}
}
createNode<LoggedInNode>(buildContext, listOf(callback))
}
NavTarget.RoomList -> {
val callback = object : RoomListEntryPoint.Callback {

View File

@@ -21,6 +21,7 @@ import androidx.compose.ui.Modifier
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.node.Node
import com.bumble.appyx.core.plugin.Plugin
import com.bumble.appyx.core.plugin.plugins
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import io.element.android.anvilannotations.ContributesNode
@@ -35,11 +36,22 @@ class LoggedInNode @AssistedInject constructor(
buildContext = buildContext,
plugins = plugins
) {
interface Callback : Plugin {
fun navigateToNotificationTroubleshoot()
}
private fun navigateToNotificationTroubleshoot() {
plugins<Callback>().forEach {
it.navigateToNotificationTroubleshoot()
}
}
@Composable
override fun View(modifier: Modifier) {
val loggedInState = loggedInPresenter.present()
LoggedInView(
state = loggedInState,
navigateToNotificationTroubleshoot = ::navigateToNotificationTroubleshoot,
modifier = modifier
)
}

View File

@@ -34,6 +34,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
@Composable
fun LoggedInView(
state: LoggedInState,
navigateToNotificationTroubleshoot: () -> Unit,
modifier: Modifier = Modifier
) {
Box(
@@ -57,7 +58,14 @@ fun LoggedInView(
?.let { reason ->
ErrorDialogWithDoNotShowAgain(
content = stringResource(id = CommonStrings.common_error_registering_pusher_android, reason),
onDismiss = { state.eventSink(LoggedInEvents.CloseErrorDialog(it)) },
cancelText = stringResource(id = CommonStrings.common_settings),
onDismiss = {
state.eventSink(LoggedInEvents.CloseErrorDialog(it))
},
onCancel = {
state.eventSink(LoggedInEvents.CloseErrorDialog(false))
navigateToNotificationTroubleshoot()
}
)
}
}
@@ -85,6 +93,7 @@ private fun Throwable.getReason(): String? {
@Composable
internal fun LoggedInViewPreview(@PreviewParameter(LoggedInStateProvider::class) state: LoggedInState) = ElementPreview {
LoggedInView(
state = state
state = state,
navigateToNotificationTroubleshoot = {},
)
}

View File

@@ -32,6 +32,9 @@ interface PreferencesEntryPoint : FeatureEntryPoint {
@Parcelize
data object NotificationSettings : InitialTarget
@Parcelize
data object NotificationTroubleshoot : InitialTarget
}
data class Params(val initialElement: InitialTarget) : NodeInputs

View File

@@ -51,4 +51,5 @@ class DefaultPreferencesEntryPoint @Inject constructor() : PreferencesEntryPoint
internal fun PreferencesEntryPoint.InitialTarget.toNavTarget() = when (this) {
is PreferencesEntryPoint.InitialTarget.Root -> PreferencesFlowNode.NavTarget.Root
is PreferencesEntryPoint.InitialTarget.NotificationSettings -> PreferencesFlowNode.NavTarget.NotificationSettings
PreferencesEntryPoint.InitialTarget.NotificationTroubleshoot -> PreferencesFlowNode.NavTarget.TroubleshootNotifications
}

View File

@@ -47,6 +47,8 @@ fun ErrorDialogWithDoNotShowAgain(
modifier: Modifier = Modifier,
title: String = ErrorDialogDefaults.title,
submitText: String = ErrorDialogDefaults.submitText,
cancelText: String? = null,
onCancel: () -> Unit = {},
) {
var doNotShowAgain by remember { mutableStateOf(false) }
BasicAlertDialog(
@@ -56,7 +58,9 @@ fun ErrorDialogWithDoNotShowAgain(
SimpleAlertDialogContent(
title = title,
submitText = submitText,
cancelText = cancelText,
onSubmitClick = { onDismiss(doNotShowAgain) },
onCancelClick = onCancel,
) {
Column {
Text(