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