Add a few source helper functions
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user