From bffd75f4d94bbcd3622ca4e5ec9d085830e4e208 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 12 Dec 2023 18:42:32 +0200 Subject: [PATCH] Fix crashes --- .../org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt | 7 ++++--- .../org/koitharu/kotatsu/core/util/ext/ContentResolver.kt | 2 +- .../koitharu/kotatsu/local/data/input/LocalMangaInput.kt | 4 +++- .../kotatsu/local/data/output/LocalMangaOutput.kt | 8 +++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt index f8a8eb6f6..822e2f688 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/widgets/ChipsView.kt @@ -41,9 +41,10 @@ class ChipsView @JvmOverloads constructor( } init { - chipStyle = context.obtainStyledAttributes(attrs, R.styleable.ChipsView, defStyleAttr, 0).use { - it.getResourceId(R.styleable.ChipsView_chipStyle, R.style.Widget_Kotatsu_Chip) - } + val ta = context.obtainStyledAttributes(attrs, R.styleable.ChipsView, defStyleAttr, 0) + chipStyle = ta.getResourceId(R.styleable.ChipsView_chipStyle, R.style.Widget_Kotatsu_Chip) + ta.recycle() + if (isInEditMode) { setChips( List(5) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/ContentResolver.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/ContentResolver.kt index 4a0085b17..3f273a060 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/ContentResolver.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/ContentResolver.kt @@ -50,7 +50,7 @@ private fun getVolumePathBeforeAndroid11(volumeId: String, context: Context): St val length = ArrayReflect.getLength(checkNotNull(result)) (0 until length).firstNotNullOfOrNull { i -> val storageVolumeElement = ArrayReflect.get(result, i) - val uuid = getUuid.invoke(storageVolumeElement) as String + val uuid = getUuid.invoke(storageVolumeElement) as String? val primary = isPrimary.invoke(storageVolumeElement) as Boolean when { primary && volumeId == PRIMARY_VOLUME_NAME -> getPath.invoke(storageVolumeElement) as String diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt index 851ae7b04..45454631a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt @@ -13,6 +13,7 @@ import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter import org.koitharu.kotatsu.parsers.model.MangaPage import org.koitharu.kotatsu.parsers.model.MangaSource +import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.parsers.util.toFileNameSafe import java.io.File @@ -54,7 +55,8 @@ sealed class LocalMangaInput( zip.isFile -> LocalMangaZipInput(zip) else -> null } - if (input?.getMangaInfo()?.id == manga.id) { + val info = runCatchingCancellable { input?.getMangaInfo() }.getOrNull() + if (info?.id == manga.id) { send(input) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/output/LocalMangaOutput.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/output/LocalMangaOutput.kt index 30c161037..ded98e4f7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/output/LocalMangaOutput.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/output/LocalMangaOutput.kt @@ -5,9 +5,11 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import okio.Closeable +import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.local.data.input.LocalMangaInput import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter +import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.parsers.util.toFileNameSafe import java.io.File @@ -86,7 +88,11 @@ sealed class LocalMangaOutput( } private suspend fun canWriteTo(file: File, manga: Manga): Boolean { - val info = LocalMangaInput.of(file).getMangaInfo() ?: return false + val info = runCatchingCancellable { + LocalMangaInput.of(file).getMangaInfo() + }.onFailure { + it.printStackTraceDebug() + }.getOrNull() ?: return false return info.id == manga.id } }