diff --git a/app/src/main/java/org/xtimms/tokusho/core/screens/UpdateDialog.kt b/app/src/main/java/org/xtimms/tokusho/core/screens/UpdateDialog.kt index b617fcd..f49fbd5 100644 --- a/app/src/main/java/org/xtimms/tokusho/core/screens/UpdateDialog.kt +++ b/app/src/main/java/org/xtimms/tokusho/core/screens/UpdateDialog.kt @@ -39,11 +39,14 @@ fun UpdateDialog( onConfirmUpdate = { scope.launch(Dispatchers.IO) { runCatching { - Updater.downloadApk(latestRelease = latestRelease) + Updater.downloadApk( + context = context, + latestRelease = latestRelease + ) .collect { downloadStatus -> currentDownloadStatus = downloadStatus if (downloadStatus is Updater.DownloadStatus.Finished) { - Updater.installLatestApk() + Updater.installLatestApk(context) } } }.onFailure { diff --git a/app/src/main/java/org/xtimms/tokusho/core/updates/Updater.kt b/app/src/main/java/org/xtimms/tokusho/core/updates/Updater.kt index decc66a..11dd6ba 100644 --- a/app/src/main/java/org/xtimms/tokusho/core/updates/Updater.kt +++ b/app/src/main/java/org/xtimms/tokusho/core/updates/Updater.kt @@ -58,7 +58,7 @@ object Updater { latestRelease } - suspend fun checkForUpdate(context: Context = App.context): LatestRelease? { + suspend fun checkForUpdate(context: Context): LatestRelease? { val currentVersion = context.getCurrentVersion() val latestRelease = getLatestRelease() val latestVersion = latestRelease.name.toVersion() @@ -80,7 +80,7 @@ object Updater { private fun Context.getLatestApk() = File(getExternalFilesDir("apk"), "latest.apk") - fun installLatestApk(context: Context = App.context) = context.run { + fun installLatestApk(context: Context) = context.run { kotlin.runCatching { val contentUri = FileProvider.getUriForFile(this, getFileProvider(), getLatestApk()) val intent = Intent(Intent.ACTION_VIEW).apply { @@ -96,7 +96,7 @@ object Updater { } suspend fun deleteOutdatedApk( - context: Context = App.context, + context: Context, ) = context.runCatching { val apkFile = getLatestApk() if (apkFile.exists()) { @@ -110,7 +110,7 @@ object Updater { } suspend fun downloadApk( - context: Context = App.context, + context: Context, latestRelease: LatestRelease ): Flow = withContext(Dispatchers.IO) { val apkVersion = context.packageManager.getPackageArchiveInfo( diff --git a/app/src/main/java/org/xtimms/tokusho/sections/settings/about/AboutView.kt b/app/src/main/java/org/xtimms/tokusho/sections/settings/about/AboutView.kt index 33716f9..6b2deeb 100644 --- a/app/src/main/java/org/xtimms/tokusho/sections/settings/about/AboutView.kt +++ b/app/src/main/java/org/xtimms/tokusho/sections/settings/about/AboutView.kt @@ -3,8 +3,10 @@ package org.xtimms.tokusho.sections.settings.about import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Description import androidx.compose.material.icons.outlined.Info import androidx.compose.material.icons.outlined.Update +import androidx.compose.material.icons.outlined.UpdateDisabled import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -13,6 +15,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import org.xtimms.tokusho.App @@ -27,6 +30,7 @@ import org.xtimms.tokusho.utils.system.toast const val ABOUT_DESTINATION = "about" +private const val repoUrl = "https://git.kotatsu.app/Xtimms/Tokusho" const val weblate = "https://hosted.weblate.org/engage/tokusho/" @Composable @@ -42,6 +46,11 @@ fun AboutView( val info = App.getVersionReport() val versionName = packageInfo.versionName + val uriHandler = LocalUriHandler.current + fun openUrl(url: String) { + uriHandler.openUri(url) + } + ScaffoldWithTopAppBar( title = stringResource(R.string.about), navigateBack = navigateBack @@ -50,13 +59,19 @@ fun AboutView( modifier = Modifier .padding(padding) ) { + item { + PreferenceItem( + title = stringResource(R.string.readme), + description = stringResource(R.string.readme_desc), + icon = Icons.Outlined.Description, + ) { openUrl(repoUrl) } + } item { PreferenceSwitchWithDivider( title = stringResource(R.string.auto_update), description = stringResource(R.string.check_for_updates_desc), - icon = Icons.Outlined.Update, + icon = if (isAutoUpdateEnabled) Icons.Outlined.Update else Icons.Outlined.UpdateDisabled, isChecked = isAutoUpdateEnabled, - isSwitchEnabled = true, onClick = navigateToUpdatePage, onChecked = { isAutoUpdateEnabled = !isAutoUpdateEnabled diff --git a/app/src/main/java/org/xtimms/tokusho/sections/settings/about/UpdateView.kt b/app/src/main/java/org/xtimms/tokusho/sections/settings/about/UpdateView.kt index 37f4251..149ca7c 100644 --- a/app/src/main/java/org/xtimms/tokusho/sections/settings/about/UpdateView.kt +++ b/app/src/main/java/org/xtimms/tokusho/sections/settings/about/UpdateView.kt @@ -131,7 +131,7 @@ fun UpdateView( runCatching { isLoading = true withContext(Dispatchers.IO) { - Updater.checkForUpdate()?.let { + Updater.checkForUpdate(context)?.let { latestRelease = it showUpdateDialog = true } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b8484d..9a26e25 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,7 @@ Off Open settings Automatic updates - Automatically check for the latest version on GitHub + Automatically check for the latest version on Gitea Version Info copied to clipboard Enable auto update @@ -57,4 +57,6 @@ No results found No matches No manga in this category + README + Check the Gitea repository and the README \ No newline at end of file