Show a progress indicator while checking for updates in the about screen (#9641)

* Show a progress indicator while checking for updates.

* Remove a unused import.

* Remove the initial toast.
This commit is contained in:
Alessandro Jean 2023-06-27 23:14:31 -03:00 committed by GitHub
parent 6ed2748846
commit 2a7cca6ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 11 deletions

View File

@ -1,14 +1,21 @@
package eu.kanade.presentation.more.settings.screen package eu.kanade.presentation.more.settings.screen
import android.content.Context import android.content.Context
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Public import androidx.compose.material.icons.outlined.Public
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
@ -62,6 +69,7 @@ object AboutScreen : Screen() {
val uriHandler = LocalUriHandler.current val uriHandler = LocalUriHandler.current
val handleBack = LocalBackPress.current val handleBack = LocalBackPress.current
val navigator = LocalNavigator.currentOrThrow val navigator = LocalNavigator.currentOrThrow
var isCheckingUpdates by remember { mutableStateOf(false) }
Scaffold( Scaffold(
topBar = { scrollBehavior -> topBar = { scrollBehavior ->
@ -94,22 +102,41 @@ object AboutScreen : Screen() {
item { item {
TextPreferenceWidget( TextPreferenceWidget(
title = stringResource(R.string.check_for_updates), title = stringResource(R.string.check_for_updates),
widget = {
AnimatedVisibility(visible = isCheckingUpdates) {
CircularProgressIndicator(
modifier = Modifier.size(28.dp),
strokeWidth = 3.dp,
)
}
},
onPreferenceClick = { onPreferenceClick = {
scope.launch { if (!isCheckingUpdates) {
checkVersion(context) { result -> scope.launch {
val updateScreen = NewUpdateScreen( isCheckingUpdates = true
versionName = result.release.version,
changelogInfo = result.release.info, checkVersion(
releaseLink = result.release.releaseLink, context = context,
downloadLink = result.release.getDownloadLink(), onAvailableUpdate = { result ->
val updateScreen = NewUpdateScreen(
versionName = result.release.version,
changelogInfo = result.release.info,
releaseLink = result.release.releaseLink,
downloadLink = result.release.getDownloadLink(),
)
navigator.push(updateScreen)
},
onFinish = {
isCheckingUpdates = false
},
) )
navigator.push(updateScreen)
} }
} }
}, },
) )
} }
} }
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
item { item {
TextPreferenceWidget( TextPreferenceWidget(
@ -186,10 +213,13 @@ object AboutScreen : Screen() {
/** /**
* Checks version and shows a user prompt if an update is available. * Checks version and shows a user prompt if an update is available.
*/ */
private suspend fun checkVersion(context: Context, onAvailableUpdate: (GetApplicationRelease.Result.NewUpdate) -> Unit) { private suspend fun checkVersion(
context: Context,
onAvailableUpdate: (GetApplicationRelease.Result.NewUpdate) -> Unit,
onFinish: () -> Unit,
) {
val updateChecker = AppUpdateChecker() val updateChecker = AppUpdateChecker()
withUIContext { withUIContext {
context.toast(R.string.update_check_look_for_updates)
try { try {
when (val result = withIOContext { updateChecker.checkForUpdate(context, forceCheck = true) }) { when (val result = withIOContext { updateChecker.checkForUpdate(context, forceCheck = true) }) {
is GetApplicationRelease.Result.NewUpdate -> { is GetApplicationRelease.Result.NewUpdate -> {
@ -203,6 +233,8 @@ object AboutScreen : Screen() {
} catch (e: Exception) { } catch (e: Exception) {
context.toast(e.message) context.toast(e.message)
logcat(LogPriority.ERROR, e) logcat(LogPriority.ERROR, e)
} finally {
onFinish()
} }
} }
} }

View File

@ -899,7 +899,6 @@
<!-- reserved for future use --> <!-- reserved for future use -->
<string name="update_check_eol">This Android version is no longer supported</string> <string name="update_check_eol">This Android version is no longer supported</string>
<string name="update_check_no_new_updates">No new updates available</string> <string name="update_check_no_new_updates">No new updates available</string>
<string name="update_check_look_for_updates">Searching for updates…</string>
<!--UpdateCheck Notifications--> <!--UpdateCheck Notifications-->
<string name="update_check_notification_download_in_progress">Downloading…</string> <string name="update_check_notification_download_in_progress">Downloading…</string>