Add a few source helper functions
This commit is contained in:
parent
81af5a5654
commit
e40fbbecbb
@ -180,8 +180,8 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
|
||||
}
|
||||
}
|
||||
|
||||
val source = sourceManager.get(manga.source)?.getMainSource()
|
||||
if (source is MetadataSource<*, *>) {
|
||||
val source = sourceManager.get(manga.source)?.getMainSource<MetadataSource<*, *>>()
|
||||
if (source != null) {
|
||||
manga.id?.let { mangaId ->
|
||||
databaseHelper.getFlatMetadataForManga(mangaId).executeAsBlocking()?.let { flatMetadata ->
|
||||
mangaObject.flatMetadata = BackupFlatMetadata.copyFrom(flatMetadata)
|
||||
|
@ -57,6 +57,7 @@ import eu.kanade.tachiyomi.widget.EmptyView
|
||||
import eu.kanade.tachiyomi.widget.materialdialogs.setTextInput
|
||||
import exh.log.xLogW
|
||||
import exh.savedsearches.EXHSavedSearch
|
||||
import exh.source.anyIs
|
||||
import exh.source.getMainSource
|
||||
import exh.source.isEhBasedSource
|
||||
import exh.widget.preference.MangadexLoginDialog
|
||||
@ -169,8 +170,8 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
binding.progress.isVisible = true
|
||||
|
||||
// SY -->
|
||||
val mainSource = presenter.source.getMainSource()
|
||||
if (mainSource is LoginSource && mainSource.requiresLogin && !mainSource.isLogged()) {
|
||||
val mainSource = presenter.source.getMainSource<LoginSource>()
|
||||
if (mainSource != null && mainSource.requiresLogin && !mainSource.isLogged()) {
|
||||
val dialog = MangadexLoginDialog(mainSource)
|
||||
dialog.showDialog(router)
|
||||
}
|
||||
@ -438,7 +439,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
menu.findItem(R.id.action_local_source_help)?.isVisible = isLocalSource
|
||||
|
||||
// SY -->
|
||||
menu.findItem(R.id.action_settings)?.isVisible = presenter.source is ConfigurableSource
|
||||
menu.findItem(R.id.action_settings)?.isVisible = presenter.source.anyIs<ConfigurableSource>()
|
||||
// SY <--
|
||||
}
|
||||
|
||||
|
@ -118,8 +118,8 @@ class SourceFilterSheet(
|
||||
|
||||
init {
|
||||
// SY -->
|
||||
val mainSource = source?.getMainSource()
|
||||
if (mainSource is BrowseSourceFilterHeader && controller != null) {
|
||||
val mainSource = source?.getMainSource<BrowseSourceFilterHeader>()
|
||||
if (mainSource != null && controller != null) {
|
||||
adapters += mainSource.getFilterHeader(controller) { dismissSheet?.invoke() }
|
||||
}
|
||||
adapters += savedSearchesAdapter
|
||||
|
@ -302,8 +302,8 @@ class MangaController :
|
||||
chaptersHeaderAdapter = MangaChaptersHeaderAdapter(this)
|
||||
chaptersAdapter = ChaptersAdapter(this, view.context)
|
||||
// SY -->
|
||||
val mainSource = presenter.source.getMainSource()
|
||||
if (mainSource is MetadataSource<*, *>) {
|
||||
val mainSource = presenter.source.getMainSource<MetadataSource<*, *>>()
|
||||
if (mainSource != null) {
|
||||
mangaMetaInfoAdapter = mainSource.getDescriptionAdapter(this)
|
||||
}
|
||||
if (!preferences.recommendsInOverflow().get() || smartSearchConfig != null) {
|
||||
@ -556,8 +556,8 @@ class MangaController :
|
||||
|
||||
// SY -->
|
||||
fun onNextMetaInfo(flatMetadata: FlatMetadata) {
|
||||
val mainSource = presenter.source.getMainSource()
|
||||
if (mainSource is MetadataSource<*, *>) {
|
||||
val mainSource = presenter.source.getMainSource<MetadataSource<*, *>>()
|
||||
if (mainSource != null) {
|
||||
presenter.meta = flatMetadata.raise(mainSource.metaClass)
|
||||
mangaMetaInfoAdapter?.notifyDataSetChanged()
|
||||
updateFilterIconState()
|
||||
|
@ -247,8 +247,8 @@ class ReaderPresenter(
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
// SY -->
|
||||
.flatMap { manga ->
|
||||
val source = sourceManager.get(manga.source)?.getMainSource()
|
||||
if (manga.initialized && source is MetadataSource<*, *>) {
|
||||
val source = sourceManager.get(manga.source)?.getMainSource<MetadataSource<*, *>>()
|
||||
if (manga.initialized && source != null) {
|
||||
db.getFlatMetadataForManga(mangaId).asRxSingle().map {
|
||||
manga to it?.raise(source.metaClass)
|
||||
}.toObservable()
|
||||
|
@ -37,8 +37,7 @@ class GalleryAdder {
|
||||
fun pickSource(url: String): List<UrlImportableSource> {
|
||||
val uri = url.toUri()
|
||||
return sourceManager.getVisibleCatalogueSources()
|
||||
.map { it.getMainSource() }
|
||||
.filterIsInstance<UrlImportableSource>()
|
||||
.mapNotNull { it.getMainSource<UrlImportableSource>() }
|
||||
.filter {
|
||||
it.lang in filters.first && it.id !in filters.second && try {
|
||||
it.matchesUri(uri)
|
||||
@ -71,8 +70,7 @@ class GalleryAdder {
|
||||
}
|
||||
} else {
|
||||
sourceManager.getVisibleCatalogueSources()
|
||||
.map { it.getMainSource() }
|
||||
.filterIsInstance<UrlImportableSource>()
|
||||
.mapNotNull { it.getMainSource<UrlImportableSource>() }
|
||||
.find {
|
||||
it.lang in filters.first && it.id !in filters.second && try {
|
||||
it.matchesUri(uri)
|
||||
|
@ -318,8 +318,7 @@ class MdUtil {
|
||||
|
||||
return sourceManager.getVisibleOnlineSources()
|
||||
.asSequence()
|
||||
.map { it.getMainSource() }
|
||||
.filterIsInstance<MangaDex>()
|
||||
.mapNotNull { it.getMainSource<MangaDex>() }
|
||||
.filter { it.lang in languages }
|
||||
.filterNot { it.id.toString() in disabledSourceIds }
|
||||
.toList()
|
||||
|
@ -107,6 +107,13 @@ fun Source.getMainSource(): Source = if (this is EnhancedHttpSource) {
|
||||
this
|
||||
}
|
||||
|
||||
@JvmName("getMainSourceInline")
|
||||
inline fun <reified T : Source> Source.getMainSource(): T? = if (this is EnhancedHttpSource) {
|
||||
this.source() as? T
|
||||
} else {
|
||||
this as? T
|
||||
}
|
||||
|
||||
fun Source.getOriginalSource(): Source = if (this is EnhancedHttpSource) {
|
||||
this.originalSource
|
||||
} else {
|
||||
@ -118,3 +125,11 @@ fun Source.getEnhancedSource(): Source = if (this is EnhancedHttpSource) {
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
inline fun <reified T> Source.anyIs(): Boolean {
|
||||
return if (this is EnhancedHttpSource) {
|
||||
originalSource is T || enhancedSource is T
|
||||
} else {
|
||||
this is T
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ class MetadataViewPresenter(
|
||||
|
||||
launchIO {
|
||||
val flatMetadata = db.getFlatMetadataForManga(manga.id!!).executeOnIO() ?: return@launchIO
|
||||
val mainSource = source.getMainSource()
|
||||
if (mainSource is MetadataSource<*, *>) {
|
||||
val mainSource = source.getMainSource<MetadataSource<*, *>>()
|
||||
if (mainSource != null) {
|
||||
meta.value = flatMetadata.raise(mainSource.metaClass)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user