Improve alternatives search
parent
83bd390c2a
commit
7c2829226d
@ -0,0 +1,8 @@
|
||||
package org.koitharu.kotatsu.core.exceptions
|
||||
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
|
||||
class UnsupportedSourceException(
|
||||
message: String?,
|
||||
val manga: Manga?,
|
||||
) : IllegalArgumentException(message)
|
||||
@ -0,0 +1,56 @@
|
||||
package org.koitharu.kotatsu.details.ui
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.exceptions.UnsupportedSourceException
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ErrorObserver
|
||||
import org.koitharu.kotatsu.core.exceptions.resolve.ExceptionResolver
|
||||
import org.koitharu.kotatsu.core.ui.dialog.ErrorDetailsDialog
|
||||
import org.koitharu.kotatsu.core.util.ext.getDisplayMessage
|
||||
import org.koitharu.kotatsu.core.util.ext.isNetworkError
|
||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||
import org.koitharu.kotatsu.parsers.exception.ParseException
|
||||
|
||||
class DetailsErrorObserver(
|
||||
override val activity: DetailsActivity,
|
||||
private val viewModel: DetailsViewModel,
|
||||
resolver: ExceptionResolver?,
|
||||
) : ErrorObserver(
|
||||
activity.viewBinding.containerDetails, null, resolver,
|
||||
{ isResolved ->
|
||||
if (isResolved) {
|
||||
viewModel.reload()
|
||||
}
|
||||
},
|
||||
) {
|
||||
|
||||
override suspend fun emit(value: Throwable) {
|
||||
val snackbar = Snackbar.make(host, value.getDisplayMessage(host.context.resources), Snackbar.LENGTH_SHORT)
|
||||
if (value is NotFoundException || value is UnsupportedSourceException) {
|
||||
snackbar.duration = Snackbar.LENGTH_INDEFINITE
|
||||
}
|
||||
when {
|
||||
canResolve(value) -> {
|
||||
snackbar.setAction(ExceptionResolver.getResolveStringId(value)) {
|
||||
resolve(value)
|
||||
}
|
||||
}
|
||||
|
||||
value is ParseException -> {
|
||||
val fm = fragmentManager
|
||||
if (fm != null) {
|
||||
snackbar.setAction(R.string.details) {
|
||||
ErrorDetailsDialog.show(fm, value, value.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value.isNetworkError() -> {
|
||||
snackbar.setAction(R.string.try_again) {
|
||||
viewModel.reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
snackbar.show()
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package org.koitharu.kotatsu.core.parser
|
||||
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.MangaParser
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.exception.NotFoundException
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.parsers.model.MangaChapter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaListFilter
|
||||
import org.koitharu.kotatsu.parsers.model.MangaPage
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaTag
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import java.util.EnumSet
|
||||
|
||||
class DummyParser(context: MangaLoaderContext) : MangaParser(context, MangaSource.DUMMY) {
|
||||
|
||||
override val configKeyDomain: ConfigKey.Domain
|
||||
get() = ConfigKey.Domain("localhost")
|
||||
|
||||
override val availableSortOrders: Set<SortOrder>
|
||||
get() = EnumSet.allOf(SortOrder::class.java)
|
||||
|
||||
override suspend fun getDetails(manga: Manga): Manga = stub()
|
||||
|
||||
override suspend fun getList(offset: Int, filter: MangaListFilter?): List<Manga> = stub()
|
||||
|
||||
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> = stub()
|
||||
|
||||
override suspend fun getAvailableTags(): Set<MangaTag> = stub()
|
||||
|
||||
private fun stub(): Nothing {
|
||||
throw NotFoundException("Usage of Dummy parser in release build", "")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue