From b454fdceb975983d6670662fdec2c08d4a6a7e38 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Sun, 28 Jan 2024 20:13:39 +0100 Subject: [PATCH] fix: Allow users to retry errors when fetching server info (#391) Previous code would show errors when fetching server info but with no mechanism to retry the operation, so it would "stick" until the user restarted the app. Fix this with a retry action. While I'm here use styles to ensure that all snackbars are 5 lines max length and remove code that sets the length. --- app/lint-baseline.xml | 216 +++++++++--------- .../notifications/NotificationsFragment.kt | 2 +- .../components/timeline/TimelineFragment.kt | 3 +- .../java/app/pachli/fragment/SFragment.kt | 2 +- .../app/pachli/fragment/ViewVideoFragment.kt | 1 - .../app/pachli/network/ServerRepository.kt | 4 + app/src/main/res/values/styles.xml | 7 + 7 files changed, 122 insertions(+), 113 deletions(-) diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index 8bdb7aaec..6083e9d39 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -1,5 +1,5 @@ - + @@ -2038,7 +2038,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~"> @@ -2940,7 +2940,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -2951,7 +2951,7 @@ errorLine2=" ~~~~~~~"> @@ -2962,7 +2962,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -2973,7 +2973,7 @@ errorLine2=" ~~~~~~~"> @@ -2984,7 +2984,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -2995,7 +2995,7 @@ errorLine2=" ~~~~~~~"> @@ -3006,7 +3006,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -3015,20 +3015,86 @@ message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor" errorLine1=" onClick = {" errorLine2=" ~~~~~~~"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - @@ -3039,73 +3105,7 @@ errorLine2=" ~~~~~~~"> - - - - - - - - - - - - - - - - - - - - - - - - @@ -3116,7 +3116,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -3127,7 +3127,7 @@ errorLine2=" ~~~~~~~"> @@ -3138,7 +3138,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -3149,7 +3149,7 @@ errorLine2=" ~~~~~~~"> @@ -3160,7 +3160,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -3171,7 +3171,7 @@ errorLine2=" ~~~~~~~"> @@ -3182,7 +3182,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -3193,7 +3193,7 @@ errorLine2=" ~~~~~~~"> @@ -3204,7 +3204,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -3215,7 +3215,7 @@ errorLine2=" ~~~~~~~"> @@ -3226,7 +3226,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -3237,7 +3237,7 @@ errorLine2=" ~~~~~~~"> @@ -3248,7 +3248,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> @@ -3259,7 +3259,7 @@ errorLine2=" ~~~~~~~"> @@ -3270,7 +3270,7 @@ errorLine2=" ~~~~~~~"> @@ -3281,7 +3281,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -3292,7 +3292,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -3545,7 +3545,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -3556,7 +3556,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~"> @@ -3567,7 +3567,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> diff --git a/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt b/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt index b1331179c..87faa7d25 100644 --- a/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt +++ b/app/src/main/java/app/pachli/components/notifications/NotificationsFragment.kt @@ -228,7 +228,7 @@ class NotificationsFragment : (activity as ActionButtonActivity).actionButton ?: binding.root, message, Snackbar.LENGTH_INDEFINITE, - ).setTextMaxLines(5) + ) error.action?.let { action -> snackbar.setAction(R.string.action_retry) { viewModel.accept(action) diff --git a/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt b/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt index 04014c72b..9f7b303dd 100644 --- a/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt +++ b/app/src/main/java/app/pachli/components/timeline/TimelineFragment.kt @@ -247,7 +247,7 @@ class TimelineFragment : (activity as? ActionButtonActivity)?.actionButton ?: binding.root, message, Snackbar.LENGTH_INDEFINITE, - ).setTextMaxLines(5) + ) error.action?.let { action -> snackbar!!.setAction(R.string.action_retry) { viewModel.accept(action) @@ -434,7 +434,6 @@ class TimelineFragment : message, Snackbar.LENGTH_INDEFINITE, ) - .setTextMaxLines(5) .setAction(R.string.action_retry) { adapter.retry() } snackbar!!.show() } else { diff --git a/app/src/main/java/app/pachli/fragment/SFragment.kt b/app/src/main/java/app/pachli/fragment/SFragment.kt index 4a6a3e572..e921d742e 100644 --- a/app/src/main/java/app/pachli/fragment/SFragment.kt +++ b/app/src/main/java/app/pachli/fragment/SFragment.kt @@ -127,7 +127,7 @@ abstract class SFragment : Fragment(), StatusActionListener ) Timber.e(msg) Snackbar.make(requireView(), msg, Snackbar.LENGTH_INDEFINITE) - .setTextMaxLines(5) + .setAction(R.string.action_retry) { serverRepository.retry() } .show() serverCanTranslate = false } diff --git a/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt b/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt index f37bd10c7..df46cb260 100644 --- a/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt +++ b/app/src/main/java/app/pachli/fragment/ViewVideoFragment.kt @@ -244,7 +244,6 @@ class ViewVideoFragment : ViewMediaFragment() { error.cause?.message ?: error.message, ) Snackbar.make(binding.root, message, Snackbar.LENGTH_INDEFINITE) - .setTextMaxLines(10) .setAction(R.string.action_retry) { player?.prepare() } .show() } diff --git a/app/src/main/java/app/pachli/network/ServerRepository.kt b/app/src/main/java/app/pachli/network/ServerRepository.kt index 523fcb257..651b0bbf1 100644 --- a/app/src/main/java/app/pachli/network/ServerRepository.kt +++ b/app/src/main/java/app/pachli/network/ServerRepository.kt @@ -74,6 +74,10 @@ class ServerRepository @Inject constructor( } } + fun retry() = externalScope.launch { + _flow.emit(getServer()) + } + /** * @return the server info or a [Server.Error] if the server info can not * be determined. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5b7b48717..47cb93e78 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -82,6 +82,8 @@ ?attr/isLightTheme @style/Pachli.Widget.GraphView + + @style/snackbar_text + + +