From 2e8b63c0062355678822e7f149cf0360aa40667c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jun 2024 16:20:23 +0200 Subject: [PATCH] Add a shortcut to navigate to the notification settings in case of error. --- .../io/element/android/appnav/LoggedInFlowNode.kt | 7 ++++++- .../element/android/appnav/loggedin/LoggedInNode.kt | 12 ++++++++++++ .../element/android/appnav/loggedin/LoggedInView.kt | 13 +++++++++++-- .../preferences/api/PreferencesEntryPoint.kt | 3 +++ .../impl/DefaultPreferencesEntryPoint.kt | 1 + .../dialogs/ErrorDialogWithDoNotShowAgain.kt | 4 ++++ 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt b/appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt index 219ec2167a..cc50e19895 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt @@ -238,7 +238,12 @@ class LoggedInFlowNode @AssistedInject constructor( return when (navTarget) { NavTarget.Placeholder -> createNode(buildContext) NavTarget.LoggedInPermanent -> { - createNode(buildContext) + val callback = object : LoggedInNode.Callback { + override fun navigateToNotificationTroubleshoot() { + backstack.push(NavTarget.Settings(PreferencesEntryPoint.InitialTarget.NotificationTroubleshoot)) + } + } + createNode(buildContext, listOf(callback)) } NavTarget.RoomList -> { val callback = object : RoomListEntryPoint.Callback { diff --git a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInNode.kt b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInNode.kt index a61e6b69b6..a54a189f69 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInNode.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInNode.kt @@ -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().forEach { + it.navigateToNotificationTroubleshoot() + } + } + @Composable override fun View(modifier: Modifier) { val loggedInState = loggedInPresenter.present() LoggedInView( state = loggedInState, + navigateToNotificationTroubleshoot = ::navigateToNotificationTroubleshoot, modifier = modifier ) } diff --git a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInView.kt b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInView.kt index 8be46d5743..b619d50501 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInView.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/loggedin/LoggedInView.kt @@ -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 = {}, ) } diff --git a/features/preferences/api/src/main/kotlin/io/element/android/features/preferences/api/PreferencesEntryPoint.kt b/features/preferences/api/src/main/kotlin/io/element/android/features/preferences/api/PreferencesEntryPoint.kt index 0453fa0ce2..ef905c5173 100644 --- a/features/preferences/api/src/main/kotlin/io/element/android/features/preferences/api/PreferencesEntryPoint.kt +++ b/features/preferences/api/src/main/kotlin/io/element/android/features/preferences/api/PreferencesEntryPoint.kt @@ -32,6 +32,9 @@ interface PreferencesEntryPoint : FeatureEntryPoint { @Parcelize data object NotificationSettings : InitialTarget + + @Parcelize + data object NotificationTroubleshoot : InitialTarget } data class Params(val initialElement: InitialTarget) : NodeInputs diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/DefaultPreferencesEntryPoint.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/DefaultPreferencesEntryPoint.kt index e551d9d8dc..fd417d4934 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/DefaultPreferencesEntryPoint.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/DefaultPreferencesEntryPoint.kt @@ -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 } diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialogWithDoNotShowAgain.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialogWithDoNotShowAgain.kt index 671e35c926..928124b08d 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialogWithDoNotShowAgain.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/dialogs/ErrorDialogWithDoNotShowAgain.kt @@ -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(