From 3725a6e58fbbbec5ec0a69f8e804e9c17b817509 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sun, 13 Apr 2025 10:01:24 +0300 Subject: [PATCH] Update page loading ui --- .../core/exceptions/NonFileUriException.kt | 7 +++ .../kotatsu/core/util/ext/Throwable.kt | 2 + .../kotatsu/local/data/LocalStorageManager.kt | 5 +- .../kotatsu/reader/ui/pager/BasePageHolder.kt | 3 +- .../storage/MangaDirectorySelectViewModel.kt | 4 +- .../directories/MangaDirectoriesViewModel.kt | 4 +- app/src/main/res/layout/layout_page_info.xml | 46 +++++++++++-------- app/src/main/res/values/strings.xml | 1 + gradle/libs.versions.toml | 6 +-- 9 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NonFileUriException.kt diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NonFileUriException.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NonFileUriException.kt new file mode 100644 index 000000000..5e0bb4710 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/exceptions/NonFileUriException.kt @@ -0,0 +1,7 @@ +package org.koitharu.kotatsu.core.exceptions + +import android.net.Uri + +class NonFileUriException( + val uri: Uri, +) : IllegalArgumentException("Cannot resolve file name of \"$uri\"") diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt index ef927b1a8..43fee30d8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt @@ -22,6 +22,7 @@ import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException import org.koitharu.kotatsu.core.exceptions.IncompatiblePluginException import org.koitharu.kotatsu.core.exceptions.NoDataReceivedException +import org.koitharu.kotatsu.core.exceptions.NonFileUriException import org.koitharu.kotatsu.core.exceptions.ProxyConfigException import org.koitharu.kotatsu.core.exceptions.SyncApiException import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException @@ -91,6 +92,7 @@ private fun Throwable.getDisplayMessageOrNull(resources: Resources): String? = w is BadBackupFormatException -> resources.getString(R.string.unsupported_backup_message) is FileNotFoundException -> parseMessage(resources) ?: message is AccessDeniedException -> resources.getString(R.string.no_access_to_file) + is NonFileUriException -> resources.getString(R.string.error_non_file_uri) is EmptyHistoryException -> resources.getString(R.string.history_is_empty) is ProxyConfigException -> resources.getString(R.string.invalid_proxy_configuration) is SyncApiException, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt index 626772f43..e11b9b616 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalStorageManager.kt @@ -18,6 +18,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runInterruptible import kotlinx.coroutines.withContext import okhttp3.Cache +import org.koitharu.kotatsu.core.exceptions.NonFileUriException import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.ext.computeSize import org.koitharu.kotatsu.core.util.ext.getStorageName @@ -92,11 +93,11 @@ class LocalStorageManager @Inject constructor( getAvailableStorageDirs() } - suspend fun resolveUri(uri: Uri): File? = runInterruptible(Dispatchers.IO) { + suspend fun resolveUri(uri: Uri): File = runInterruptible(Dispatchers.IO) { if (uri.isFileUri()) { uri.toFile() } else { - uri.resolveFile(context) + uri.resolveFile(context) ?: throw NonFileUriException(uri) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BasePageHolder.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BasePageHolder.kt index 63ef98914..ec5e93bfa 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BasePageHolder.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/BasePageHolder.kt @@ -152,8 +152,7 @@ abstract class BasePageHolder( protected open fun onStateChanged(state: PageState) { bindingInfo.layoutError.isVisible = state is PageState.Error - bindingInfo.progressBar.isGone = state.isFinalState() - bindingInfo.textViewStatus.isGone = state.isFinalState() + bindingInfo.layoutProgress.isGone = state.isFinalState() val progress = (state as? PageState.Loading)?.progress ?: -1 if (progress in 0..100) { bindingInfo.progressBar.isIndeterminate = false diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/MangaDirectorySelectViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/MangaDirectorySelectViewModel.kt index 053c222d1..29f2793f7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/MangaDirectorySelectViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/MangaDirectorySelectViewModel.kt @@ -39,9 +39,7 @@ class MangaDirectorySelectViewModel @Inject constructor( fun onCustomDirectoryPicked(uri: Uri) { launchJob(Dispatchers.Default) { storageManager.takePermissions(uri) - val dir = requireNotNull(storageManager.resolveUri(uri)) { - "Cannot resolve file name of \"$uri\"" - } + val dir = storageManager.resolveUri(uri) if (!dir.isWriteable()) { throw AccessDeniedException(dir) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/MangaDirectoriesViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/MangaDirectoriesViewModel.kt index a3d8bf8a9..da71c261d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/MangaDirectoriesViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/MangaDirectoriesViewModel.kt @@ -36,9 +36,7 @@ class MangaDirectoriesViewModel @Inject constructor( launchLoadingJob(Dispatchers.Default) { loadingJob?.cancelAndJoin() storageManager.takePermissions(uri) - val dir = requireNotNull(storageManager.resolveUri(uri)) { - "Cannot resolve file name of \"$uri\"" - } + val dir = storageManager.resolveUri(uri) if (!dir.canRead()) { throw AccessDeniedException(dir) } diff --git a/app/src/main/res/layout/layout_page_info.xml b/app/src/main/res/layout/layout_page_info.xml index cf1393cdc..8d258a048 100644 --- a/app/src/main/res/layout/layout_page_info.xml +++ b/app/src/main/res/layout/layout_page_info.xml @@ -5,34 +5,42 @@ xmlns:tools="http://schemas.android.com/tools" tools:parentTag="android.widget.FrameLayout"> - - - + android:gravity="center_horizontal" + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> + + + + + Show suggestions from all manga sources, including disabled ones Highlight dangerous genres Highlight genres that may be inappropriate for most users + The selected path cannot be used because it does not denote a file or directory diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9d2e39e27..59115d12b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ collections = "1.5.0" conscrypt = "2.5.2" constraintlayout = "2.2.1" coreKtx = "1.15.0" -coroutines = "1.10.1" +coroutines = "1.10.2" desugar = "2.1.5" diskLruCache = "1.5" fragment = "1.8.6" @@ -30,8 +30,8 @@ markwon = "4.6.2" material = "1.13.0-alpha12" moshi = "1.15.2" okhttp = "4.12.0" -okio = "3.10.2" -parsers = "20a24db949" +okio = "3.11.0" +parsers = "e874837efb" preference = "1.2.1" recyclerview = "1.4.0" room = "2.6.1"