extension settings
This commit is contained in:
parent
9c0ef7a788
commit
3368a1bc8d
76 changed files with 2320 additions and 131 deletions
|
@ -0,0 +1,85 @@
|
|||
package eu.kanade.tachiyomi.source.anime
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
|
||||
import eu.kanade.tachiyomi.animesource.AnimeSource
|
||||
import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource
|
||||
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import tachiyomi.domain.source.anime.model.AnimeSourceData
|
||||
import tachiyomi.domain.source.anime.model.StubAnimeSource
|
||||
import tachiyomi.domain.source.anime.service.AnimeSourceManager
|
||||
import tachiyomi.source.local.entries.anime.LocalAnimeSource
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class AndroidAnimeSourceManager(
|
||||
private val context: Context,
|
||||
private val extensionManager: AnimeExtensionManager,
|
||||
) : AnimeSourceManager {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap<Long, AnimeSource>())
|
||||
|
||||
private val stubSourcesMap = ConcurrentHashMap<Long, StubAnimeSource>()
|
||||
|
||||
override val catalogueSources: Flow<List<AnimeCatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<AnimeCatalogueSource>() }
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
extensionManager.installedExtensionsFlow
|
||||
.collectLatest { extensions ->
|
||||
val mutableMap = ConcurrentHashMap<Long, AnimeSource>(
|
||||
mapOf(
|
||||
LocalAnimeSource.ID to LocalAnimeSource(
|
||||
context,
|
||||
),
|
||||
),
|
||||
)
|
||||
extensions.forEach { extension ->
|
||||
extension.sources.forEach {
|
||||
mutableMap[it.id] = it
|
||||
registerStubSource(it.toSourceData())
|
||||
}
|
||||
}
|
||||
sourcesMapFlow.value = mutableMap
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun get(sourceKey: Long): AnimeSource? {
|
||||
return sourcesMapFlow.value[sourceKey]
|
||||
}
|
||||
|
||||
override fun getOrStub(sourceKey: Long): AnimeSource {
|
||||
return sourcesMapFlow.value[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) {
|
||||
runBlocking { createStubSource(sourceKey) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getOnlineSources() = sourcesMapFlow.value.values.filterIsInstance<AnimeHttpSource>()
|
||||
|
||||
override fun getCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance<AnimeCatalogueSource>()
|
||||
|
||||
override fun getStubSources(): List<StubAnimeSource> {
|
||||
val onlineSourceIds = getOnlineSources().map { it.id }
|
||||
return stubSourcesMap.values.filterNot { it.id in onlineSourceIds }
|
||||
}
|
||||
|
||||
private fun registerStubSource(sourceData: AnimeSourceData) {
|
||||
|
||||
}
|
||||
|
||||
private suspend fun createStubSource(id: Long): StubAnimeSource {
|
||||
return StubAnimeSource(AnimeSourceData(id, "", ""))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.kanade.tachiyomi.source.anime
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.tachiyomi.animesource.AnimeSource
|
||||
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
|
||||
import tachiyomi.domain.source.anime.model.AnimeSourceData
|
||||
import tachiyomi.domain.source.anime.model.StubAnimeSource
|
||||
import tachiyomi.source.local.entries.anime.isLocal
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
fun AnimeSource.icon(): Drawable? = Injekt.get<AnimeExtensionManager>().getAppIconForSource(this.id)
|
||||
|
||||
fun AnimeSource.getPreferenceKey(): String = "source_$id"
|
||||
|
||||
fun AnimeSource.toSourceData(): AnimeSourceData = AnimeSourceData(id = id, lang = lang, name = name)
|
||||
|
||||
fun AnimeSource.getNameForAnimeInfo(): String {
|
||||
val preferences = Injekt.get<SourcePreferences>()
|
||||
val enabledLanguages = preferences.enabledLanguages().get()
|
||||
.filterNot { it in listOf("all", "other") }
|
||||
val hasOneActiveLanguages = enabledLanguages.size == 1
|
||||
val isInEnabledLanguages = lang in enabledLanguages
|
||||
return when {
|
||||
// For edge cases where user disables a source they got manga of in their library.
|
||||
hasOneActiveLanguages && !isInEnabledLanguages -> toString()
|
||||
// Hide the language tag when only one language is used.
|
||||
hasOneActiveLanguages && isInEnabledLanguages -> name
|
||||
else -> toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun AnimeSource.isLocalOrStub(): Boolean = isLocal() || this is StubAnimeSource
|
|
@ -0,0 +1,84 @@
|
|||
package eu.kanade.tachiyomi.source.manga
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.MangaSource
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import tachiyomi.domain.source.manga.model.MangaSourceData
|
||||
import tachiyomi.domain.source.manga.model.StubMangaSource
|
||||
import tachiyomi.domain.source.manga.service.MangaSourceManager
|
||||
import tachiyomi.source.local.entries.manga.LocalMangaSource
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class AndroidMangaSourceManager(
|
||||
private val context: Context,
|
||||
private val extensionManager: MangaExtensionManager,
|
||||
) : MangaSourceManager {
|
||||
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||
|
||||
private val sourcesMapFlow = MutableStateFlow(ConcurrentHashMap<Long, MangaSource>())
|
||||
|
||||
private val stubSourcesMap = ConcurrentHashMap<Long, StubMangaSource>()
|
||||
|
||||
override val catalogueSources: Flow<List<CatalogueSource>> = sourcesMapFlow.map { it.values.filterIsInstance<CatalogueSource>() }
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
extensionManager.installedExtensionsFlow
|
||||
.collectLatest { extensions ->
|
||||
val mutableMap = ConcurrentHashMap<Long, MangaSource>(
|
||||
mapOf(
|
||||
LocalMangaSource.ID to LocalMangaSource(
|
||||
context,
|
||||
),
|
||||
),
|
||||
)
|
||||
extensions.forEach { extension ->
|
||||
extension.sources.forEach {
|
||||
mutableMap[it.id] = it
|
||||
registerStubSource(it.toSourceData())
|
||||
}
|
||||
}
|
||||
sourcesMapFlow.value = mutableMap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(sourceKey: Long): MangaSource? {
|
||||
return sourcesMapFlow.value[sourceKey]
|
||||
}
|
||||
|
||||
override fun getOrStub(sourceKey: Long): MangaSource {
|
||||
return sourcesMapFlow.value[sourceKey] ?: stubSourcesMap.getOrPut(sourceKey) {
|
||||
runBlocking { createStubSource(sourceKey) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun getOnlineSources() = sourcesMapFlow.value.values.filterIsInstance<HttpSource>()
|
||||
|
||||
override fun getCatalogueSources() = sourcesMapFlow.value.values.filterIsInstance<CatalogueSource>()
|
||||
|
||||
override fun getStubSources(): List<StubMangaSource> {
|
||||
val onlineSourceIds = getOnlineSources().map { it.id }
|
||||
return stubSourcesMap.values.filterNot { it.id in onlineSourceIds }
|
||||
}
|
||||
|
||||
private fun registerStubSource(sourceData: MangaSourceData) {
|
||||
|
||||
}
|
||||
|
||||
private suspend fun createStubSource(id: Long): StubMangaSource {
|
||||
return StubMangaSource(MangaSourceData(id, "", ""))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package eu.kanade.tachiyomi.source.manga
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
|
||||
import eu.kanade.tachiyomi.source.MangaSource
|
||||
import tachiyomi.domain.source.manga.model.MangaSourceData
|
||||
import tachiyomi.domain.source.manga.model.StubMangaSource
|
||||
import tachiyomi.source.local.entries.manga.isLocal
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
fun MangaSource.icon(): Drawable? = Injekt.get<MangaExtensionManager>().getAppIconForSource(this.id)
|
||||
|
||||
fun MangaSource.getPreferenceKey(): String = "source_$id"
|
||||
|
||||
fun MangaSource.toSourceData(): MangaSourceData = MangaSourceData(id = id, lang = lang, name = name)
|
||||
|
||||
fun MangaSource.getNameForMangaInfo(): String {
|
||||
val preferences = Injekt.get<SourcePreferences>()
|
||||
val enabledLanguages = preferences.enabledLanguages().get()
|
||||
.filterNot { it in listOf("all", "other") }
|
||||
val hasOneActiveLanguages = enabledLanguages.size == 1
|
||||
val isInEnabledLanguages = lang in enabledLanguages
|
||||
return when {
|
||||
// For edge cases where user disables a source they got manga of in their library.
|
||||
hasOneActiveLanguages && !isInEnabledLanguages -> toString()
|
||||
// Hide the language tag when only one language is used.
|
||||
hasOneActiveLanguages && isInEnabledLanguages -> name
|
||||
else -> toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun MangaSource.isLocalOrStub(): Boolean = isLocal() || this is StubMangaSource
|
Loading…
Add table
Add a link
Reference in a new issue