diff --git a/app/build.gradle b/app/build.gradle index f74ad33c4..3775f1ee4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,8 +14,8 @@ android { applicationId 'org.koitharu.kotatsu' minSdkVersion 21 targetSdkVersion 32 - versionCode 413 - versionName '3.4.1' + versionCode 414 + versionName '3.4.2' generatedDensities = [] testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -76,8 +76,7 @@ afterEvaluate { } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) - implementation('com.github.nv95:kotatsu-parsers:8c26f3c790') { + implementation('com.github.nv95:kotatsu-parsers:26d951bc20') { exclude group: 'org.json', module: 'json' } diff --git a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 8cc58f47b..e1552900f 100644 --- a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -25,7 +25,6 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import kotlinx.coroutines.launch -import org.acra.ktx.sendWithAcra import org.koin.android.ext.android.get import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf @@ -39,7 +38,6 @@ import org.koitharu.kotatsu.core.os.ShortcutsRepository import org.koitharu.kotatsu.databinding.ActivityDetailsBinding import org.koitharu.kotatsu.details.ui.adapter.BranchesAdapter import org.koitharu.kotatsu.download.ui.service.DownloadService -import org.koitharu.kotatsu.parsers.exception.ParseException import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.util.mapNotNullToSet @@ -48,6 +46,8 @@ import org.koitharu.kotatsu.reader.ui.ReaderState import org.koitharu.kotatsu.scrobbling.ui.selector.ScrobblingSelectorBottomSheet import org.koitharu.kotatsu.search.ui.multi.MultiSearchActivity import org.koitharu.kotatsu.utils.ext.getDisplayMessage +import org.koitharu.kotatsu.utils.ext.isReportable +import org.koitharu.kotatsu.utils.ext.report class DetailsActivity : BaseActivity(), @@ -118,7 +118,7 @@ class DetailsActivity : Toast.makeText(this, e.getDisplayMessage(resources), Toast.LENGTH_LONG).show() finishAfterTransition() } - e is ParseException || e is IllegalArgumentException || e is IllegalStateException -> { + e.isReportable() -> { binding.snackbar.show( messageText = e.getDisplayMessage(resources), actionId = R.string.report, @@ -128,7 +128,7 @@ class DetailsActivity : Snackbar.LENGTH_LONG }, onActionClick = { - e.sendWithAcra() + e.report("DetailsActivity::onError") dismiss() } ) diff --git a/app/src/main/java/org/koitharu/kotatsu/settings/SourceSettingsFragment.kt b/app/src/main/java/org/koitharu/kotatsu/settings/SourceSettingsFragment.kt index 233260be9..3db0bb810 100644 --- a/app/src/main/java/org/koitharu/kotatsu/settings/SourceSettingsFragment.kt +++ b/app/src/main/java/org/koitharu/kotatsu/settings/SourceSettingsFragment.kt @@ -5,6 +5,7 @@ import android.view.View import androidx.preference.Preference import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ensureActive import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koitharu.kotatsu.R @@ -74,11 +75,15 @@ class SourceSettingsFragment : BasePreferenceFragment(0) { when { error is AuthRequiredException -> Unit ExceptionResolver.canResolve(error) -> { - Snackbar.make(listView, error.getDisplayMessage(resources), Snackbar.LENGTH_INDEFINITE) - .setAction(ExceptionResolver.getResolveStringId(error)) { resolveError(error) } + ensureActive() + Snackbar.make( + listView ?: return@onFailure, + error.getDisplayMessage(preference.context.resources), + Snackbar.LENGTH_INDEFINITE, + ).setAction(ExceptionResolver.getResolveStringId(error)) { resolveError(error) } .show() } - else -> preference.summary = error.getDisplayMessage(resources) + else -> preference.summary = error.getDisplayMessage(preference.context.resources) } error.printStackTraceDebug() } diff --git a/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt b/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt index 6dac10c3b..7b7f76408 100644 --- a/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt +++ b/app/src/main/java/org/koitharu/kotatsu/utils/ext/ThrowableExt.kt @@ -4,12 +4,14 @@ import android.content.ActivityNotFoundException import android.content.res.Resources import okio.FileNotFoundException import org.acra.ACRA +import org.acra.ktx.sendWithAcra import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.CloudFlareProtectedException import org.koitharu.kotatsu.core.exceptions.EmptyHistoryException import org.koitharu.kotatsu.core.exceptions.UnsupportedFileException import org.koitharu.kotatsu.core.exceptions.WrongPasswordException import org.koitharu.kotatsu.parsers.exception.AuthRequiredException +import org.koitharu.kotatsu.parsers.exception.ParseException import org.koitharu.kotatsu.parsers.model.Manga import java.net.SocketTimeoutException @@ -26,4 +28,17 @@ fun Throwable.getDisplayMessage(resources: Resources) = when (this) { else -> localizedMessage ?: resources.getString(R.string.error_occurred) } -fun ACRA.setCurrentManga(manga: Manga?) = errorReporter.putCustomData("manga", manga?.publicUrl.toString()) \ No newline at end of file +fun Throwable.isReportable(): Boolean { + if (this !is Exception) { + return true + } + return this is ParseException || this is IllegalArgumentException || this is IllegalStateException +} + +fun Throwable.report(message: String?) { + CaughtException(this, message).sendWithAcra() +} + +fun ACRA.setCurrentManga(manga: Manga?) = errorReporter.putCustomData("manga", manga?.publicUrl.toString()) + +private class CaughtException(cause: Throwable, override val message: String?) : RuntimeException(cause) \ No newline at end of file