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.
This commit is contained in:
Nik Clayton 2024-01-28 20:13:39 +01:00 committed by GitHub
parent 9242c7d98d
commit b454fdceb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 122 additions and 113 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.2.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.2.1)" variant="all" version="8.2.1">
<issues format="6" by="lint 8.2.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.2.2)" variant="all" version="8.2.2">
<issue
id="InvalidPackage"
@ -2027,7 +2027,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/styles.xml"
line="129"
line="131"
column="12"/>
</issue>
@ -2038,7 +2038,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/styles.xml"
line="173"
line="175"
column="12"/>
</issue>
@ -2940,7 +2940,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="646"
line="619"
column="17"/>
</issue>
@ -2951,7 +2951,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="649"
line="622"
column="21"/>
</issue>
@ -2962,7 +2962,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="654"
line="627"
column="17"/>
</issue>
@ -2973,7 +2973,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="658"
line="631"
column="21"/>
</issue>
@ -2984,7 +2984,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="663"
line="636"
column="17"/>
</issue>
@ -2995,7 +2995,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="666"
line="639"
column="21"/>
</issue>
@ -3006,7 +3006,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="671"
line="644"
column="17"/>
</issue>
@ -3015,20 +3015,86 @@
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="647"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="652"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="655"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="659"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="662"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="667"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="670"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="674"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="679"
column="17"/>
</issue>
@ -3039,73 +3105,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="682"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="686"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="689"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="694"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="697"
column="21"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `primaryDrawerItem` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" primaryDrawerItem {"
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="701"
column="17"/>
</issue>
<issue
id="SyntheticAccessor"
message="Access to `private` method `setOnClick` of class `MainActivityKt` requires synthetic accessor"
errorLine1=" onClick = {"
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="705"
line="678"
column="21"/>
</issue>
@ -3116,7 +3116,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="714"
line="687"
column="17"/>
</issue>
@ -3127,7 +3127,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="717"
line="690"
column="21"/>
</issue>
@ -3138,7 +3138,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="722"
line="695"
column="17"/>
</issue>
@ -3149,7 +3149,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="725"
line="698"
column="21"/>
</issue>
@ -3160,7 +3160,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="730"
line="703"
column="17"/>
</issue>
@ -3171,7 +3171,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="733"
line="706"
column="21"/>
</issue>
@ -3182,7 +3182,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="738"
line="711"
column="17"/>
</issue>
@ -3193,7 +3193,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="741"
line="714"
column="21"/>
</issue>
@ -3204,7 +3204,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="748"
line="721"
column="21"/>
</issue>
@ -3215,7 +3215,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="751"
line="724"
column="25"/>
</issue>
@ -3226,7 +3226,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="760"
line="733"
column="17"/>
</issue>
@ -3237,7 +3237,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="763"
line="736"
column="21"/>
</issue>
@ -3248,7 +3248,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="776"
line="749"
column="17"/>
</issue>
@ -3259,7 +3259,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="780"
line="753"
column="21"/>
</issue>
@ -3270,7 +3270,7 @@
errorLine2=" ~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="905"
line="878"
column="17"/>
</issue>
@ -3281,7 +3281,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="907"
line="880"
column="17"/>
</issue>
@ -3292,7 +3292,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/MainActivity.kt"
line="918"
line="891"
column="17"/>
</issue>
@ -3545,7 +3545,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt"
line="808"
line="800"
column="13"/>
</issue>
@ -3556,7 +3556,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt"
line="812"
line="804"
column="13"/>
</issue>
@ -3567,7 +3567,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/app/pachli/adapter/StatusBaseViewHolder.kt"
line="817"
line="809"
column="13"/>
</issue>

View File

@ -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)

View File

@ -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 {

View File

@ -127,7 +127,7 @@ abstract class SFragment<T : IStatusViewData> : Fragment(), StatusActionListener
)
Timber.e(msg)
Snackbar.make(requireView(), msg, Snackbar.LENGTH_INDEFINITE)
.setTextMaxLines(5)
.setAction(R.string.action_retry) { serverRepository.retry() }
.show()
serverCanTranslate = false
}

View File

@ -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()
}

View File

@ -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.

View File

@ -82,6 +82,8 @@
<item name="android:windowLightStatusBar">?attr/isLightTheme</item>
<item name="graphViewStyle">@style/Pachli.Widget.GraphView</item>
<item name="snackbarTextViewStyle">@style/snackbar_text</item>
</style>
<style name="AppTheme" parent="Theme.Pachli" />
@ -174,4 +176,9 @@
<item name="materialDrawerMaskDrawable">@drawable/materialdrawer_shape_small</item>
<item name="materialDrawerDrawCircularShadow">false</item>
</style>
<!-- Customize all snackbars -->
<style name="snackbar_text" parent="@style/Widget.MaterialComponents.Snackbar.TextView">
<item name="android:maxLines">5</item>
</style>
</resources>