mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Maintain source info in the database. (#6389)
* Maintain Source Info in database * Review changes and cleanups * Review changes 2 * Review Changes 3
This commit is contained in:
@@ -27,12 +27,14 @@ import eu.kanade.domain.manga.interactor.UpdateManga
|
||||
import eu.kanade.domain.manga.repository.MangaRepository
|
||||
import eu.kanade.domain.source.interactor.GetEnabledSources
|
||||
import eu.kanade.domain.source.interactor.GetLanguagesWithSources
|
||||
import eu.kanade.domain.source.interactor.GetSourceData
|
||||
import eu.kanade.domain.source.interactor.GetSourcesWithFavoriteCount
|
||||
import eu.kanade.domain.source.interactor.GetSourcesWithNonLibraryManga
|
||||
import eu.kanade.domain.source.interactor.SetMigrateSorting
|
||||
import eu.kanade.domain.source.interactor.ToggleLanguage
|
||||
import eu.kanade.domain.source.interactor.ToggleSource
|
||||
import eu.kanade.domain.source.interactor.ToggleSourcePin
|
||||
import eu.kanade.domain.source.interactor.UpsertSourceData
|
||||
import eu.kanade.domain.source.repository.SourceRepository
|
||||
import uy.kohesive.injekt.api.InjektModule
|
||||
import uy.kohesive.injekt.api.InjektRegistrar
|
||||
@@ -71,11 +73,13 @@ class DomainModule : InjektModule {
|
||||
addSingletonFactory<SourceRepository> { SourceRepositoryImpl(get(), get()) }
|
||||
addFactory { GetEnabledSources(get(), get()) }
|
||||
addFactory { GetLanguagesWithSources(get(), get()) }
|
||||
addFactory { GetSourceData(get()) }
|
||||
addFactory { GetSourcesWithFavoriteCount(get(), get()) }
|
||||
addFactory { GetSourcesWithNonLibraryManga(get()) }
|
||||
addFactory { SetMigrateSorting(get()) }
|
||||
addFactory { ToggleLanguage(get()) }
|
||||
addFactory { ToggleSource(get()) }
|
||||
addFactory { ToggleSourcePin(get()) }
|
||||
addFactory { UpsertSourceData(get()) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package eu.kanade.domain.source.interactor
|
||||
|
||||
import eu.kanade.domain.source.model.SourceData
|
||||
import eu.kanade.domain.source.repository.SourceRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import logcat.LogPriority
|
||||
|
||||
class GetSourceData(
|
||||
private val repository: SourceRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(id: Long): SourceData? {
|
||||
return try {
|
||||
repository.getSourceData(id)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,20 +33,18 @@ class GetSourcesWithFavoriteCount(
|
||||
strength = Collator.PRIMARY
|
||||
}
|
||||
val sortFn: (Pair<Source, Long>, Pair<Source, Long>) -> Int = { a, b ->
|
||||
val id1 = a.first.name.toLongOrNull()
|
||||
val id2 = b.first.name.toLongOrNull()
|
||||
when (sorting) {
|
||||
SetMigrateSorting.Mode.ALPHABETICAL -> {
|
||||
when {
|
||||
id1 != null && id2 == null -> -1
|
||||
id2 != null && id1 == null -> 1
|
||||
a.first.isStub && b.first.isStub.not() -> -1
|
||||
b.first.isStub && a.first.isStub.not() -> 1
|
||||
else -> collator.compare(a.first.name.lowercase(locale), b.first.name.lowercase(locale))
|
||||
}
|
||||
}
|
||||
SetMigrateSorting.Mode.TOTAL -> {
|
||||
when {
|
||||
id1 != null && id2 == null -> -1
|
||||
id2 != null && id1 == null -> 1
|
||||
a.first.isStub && b.first.isStub.not() -> -1
|
||||
b.first.isStub && a.first.isStub.not() -> 1
|
||||
else -> a.second.compareTo(b.second)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package eu.kanade.domain.source.interactor
|
||||
|
||||
import eu.kanade.domain.source.model.SourceData
|
||||
import eu.kanade.domain.source.repository.SourceRepository
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import logcat.LogPriority
|
||||
|
||||
class UpsertSourceData(
|
||||
private val repository: SourceRepository,
|
||||
) {
|
||||
|
||||
suspend fun await(sourceData: SourceData) {
|
||||
try {
|
||||
repository.upsertSourceData(sourceData.id, sourceData.lang, sourceData.name)
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ data class Source(
|
||||
val lang: String,
|
||||
val name: String,
|
||||
val supportsLatest: Boolean,
|
||||
val isStub: Boolean,
|
||||
val pin: Pins = Pins.unpinned,
|
||||
val isUsedLast: Boolean = false,
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package eu.kanade.domain.source.model
|
||||
|
||||
data class SourceData(
|
||||
val id: Long,
|
||||
val lang: String,
|
||||
val name: String,
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.kanade.domain.source.repository
|
||||
|
||||
import eu.kanade.domain.source.model.Source
|
||||
import eu.kanade.domain.source.model.SourceData
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import eu.kanade.tachiyomi.source.Source as LoadedSource
|
||||
|
||||
@@ -13,4 +14,8 @@ interface SourceRepository {
|
||||
fun getSourcesWithFavoriteCount(): Flow<List<Pair<Source, Long>>>
|
||||
|
||||
fun getSourcesWithNonLibraryManga(): Flow<List<Pair<LoadedSource, Long>>>
|
||||
|
||||
suspend fun getSourceData(id: Long): SourceData?
|
||||
|
||||
suspend fun upsertSourceData(id: Long, lang: String, name: String)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user