Update page loading ui
This commit is contained in:
@@ -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\"")
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,8 +152,7 @@ abstract class BasePageHolder<B : ViewBinding>(
|
||||
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -5,34 +5,42 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:parentTag="android.widget.FrameLayout">
|
||||
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
app:hideAnimationBehavior="escape"
|
||||
app:trackCornerRadius="0dp"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_status"
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginHorizontal="60dp"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?textAppearanceBodyLarge"
|
||||
tools:text="72%" />
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/badge_offset"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:textAppearance="?textAppearanceBodyLarge"
|
||||
tools:text="72%" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_error"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="60dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginStart="56dp"
|
||||
android:layout_marginEnd="56dp"
|
||||
android:background="@drawable/bg_card"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
|
||||
@@ -825,4 +825,5 @@
|
||||
<string name="suggestions_disabled_sources_summary">Show suggestions from all manga sources, including disabled ones</string>
|
||||
<string name="tags_warnings">Highlight dangerous genres</string>
|
||||
<string name="tags_warnings_summary">Highlight genres that may be inappropriate for most users</string>
|
||||
<string name="error_non_file_uri">The selected path cannot be used because it does not denote a file or directory</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user