mihon/app/src/main/java/eu/kanade/tachiyomi/source/SourceManager.kt

51 lines
1.5 KiB
Kotlin
Raw Normal View History

2017-01-20 21:24:31 +01:00
package eu.kanade.tachiyomi.source
import android.content.Context
2017-01-20 21:27:53 +01:00
import eu.kanade.tachiyomi.source.online.HttpSource
2017-01-20 21:24:31 +01:00
import eu.kanade.tachiyomi.source.online.english.*
import eu.kanade.tachiyomi.source.online.german.WieManga
import eu.kanade.tachiyomi.source.online.russian.Mangachan
import eu.kanade.tachiyomi.source.online.russian.Mintmanga
import eu.kanade.tachiyomi.source.online.russian.Readmanga
open class SourceManager(private val context: Context) {
private val sourcesMap = mutableMapOf<Long, Source>()
init {
createInternalSources().forEach { registerSource(it) }
2017-01-20 21:24:31 +01:00
}
open fun get(sourceKey: Long): Source? {
return sourcesMap[sourceKey]
}
2017-01-20 21:27:53 +01:00
fun getOnlineSources() = sourcesMap.values.filterIsInstance<HttpSource>()
2017-01-20 21:24:31 +01:00
fun getCatalogueSources() = sourcesMap.values.filterIsInstance<CatalogueSource>()
internal fun registerSource(source: Source, overwrite: Boolean = false) {
2017-01-20 21:24:31 +01:00
if (overwrite || !sourcesMap.containsKey(source.id)) {
sourcesMap.put(source.id, source)
}
}
internal fun unregisterSource(source: Source) {
sourcesMap.remove(source.id)
}
2017-01-20 21:24:31 +01:00
private fun createInternalSources(): List<Source> = listOf(
LocalSource(context),
2017-01-20 21:24:31 +01:00
Batoto(),
Mangahere(),
Mangafox(),
Kissmanga(),
Readmanga(),
Mintmanga(),
Mangachan(),
Readmangatoday(),
Mangasee(),
WieManga()
)
}