mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Properly relink custom manga info
This commit is contained in:
parent
dabb2c622a
commit
9967647217
7 changed files with 43 additions and 8 deletions
|
@ -15,6 +15,7 @@ import dev.yokai.domain.library.custom.CustomMangaRepository
|
|||
import dev.yokai.domain.library.custom.interactor.CreateCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.DeleteCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.GetCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.RelinkCustomManga
|
||||
import dev.yokai.domain.manga.MangaRepository
|
||||
import dev.yokai.domain.manga.interactor.GetLibraryManga
|
||||
import uy.kohesive.injekt.api.InjektModule
|
||||
|
@ -39,6 +40,7 @@ class DomainModule : InjektModule {
|
|||
addFactory { CreateCustomManga(get()) }
|
||||
addFactory { DeleteCustomManga(get()) }
|
||||
addFactory { GetCustomManga(get()) }
|
||||
addFactory { RelinkCustomManga(get()) }
|
||||
|
||||
addSingletonFactory<MangaRepository> { MangaRepositoryImpl(get()) }
|
||||
addFactory { GetLibraryManga(get()) }
|
||||
|
|
|
@ -63,6 +63,9 @@ class CustomMangaRepositoryImpl(private val handler: DatabaseHandler) : CustomMa
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun relinkCustomManga(oldId: Long, newId: Long) =
|
||||
handler.await { custom_manga_infoQueries.relink(newId, oldId) }
|
||||
|
||||
private fun mapCustomMangaInfo(
|
||||
mangaId: Long,
|
||||
title: String?,
|
||||
|
|
|
@ -28,4 +28,5 @@ interface CustomMangaRepository {
|
|||
suspend fun insertBulkCustomManga(mangaList: List<CustomMangaInfo>)
|
||||
suspend fun deleteCustomManga(mangaId: Long)
|
||||
suspend fun deleteBulkCustomManga(mangaIds: List<Long>)
|
||||
suspend fun relinkCustomManga(oldId: Long, newId: Long)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package dev.yokai.domain.library.custom.interactor
|
||||
|
||||
import dev.yokai.domain.library.custom.CustomMangaRepository
|
||||
|
||||
class RelinkCustomManga(
|
||||
private val customMangaRepository: CustomMangaRepository,
|
||||
) {
|
||||
suspend fun await(oldId: Long, newId: Long) = customMangaRepository.relinkCustomManga(oldId, newId)
|
||||
}
|
|
@ -9,6 +9,7 @@ import dev.yokai.core.metadata.copyFromComicInfo
|
|||
import dev.yokai.domain.library.custom.interactor.CreateCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.DeleteCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.GetCustomManga
|
||||
import dev.yokai.domain.library.custom.interactor.RelinkCustomManga
|
||||
import dev.yokai.domain.library.custom.model.CustomMangaInfo
|
||||
import dev.yokai.domain.library.custom.model.CustomMangaInfo.Companion.getMangaInfo
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
|
@ -39,6 +40,7 @@ class CustomMangaManager(val context: Context) {
|
|||
private val createCustomManga: CreateCustomManga by injectLazy()
|
||||
private val deleteCustomManga: DeleteCustomManga by injectLazy()
|
||||
private val getCustomManga: GetCustomManga by injectLazy()
|
||||
private val relinkCustomManga: RelinkCustomManga by injectLazy()
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
|
@ -112,15 +114,28 @@ class CustomMangaManager(val context: Context) {
|
|||
saveCustomInfo { jsonFile.delete() }
|
||||
}
|
||||
|
||||
private val CustomMangaInfo.shouldDelete
|
||||
get() = (
|
||||
title == null &&
|
||||
author == null &&
|
||||
artist == null &&
|
||||
description == null &&
|
||||
genre == null &&
|
||||
(status ?: -1) == -1
|
||||
)
|
||||
|
||||
suspend fun updateMangaInfo(oldId: Long?, newId: Long?, manga: CustomMangaInfo) {
|
||||
if (oldId == null || newId == null) return
|
||||
if (manga.shouldDelete) {
|
||||
deleteCustomInfo(manga.mangaId)
|
||||
} else {
|
||||
relinkCustomManga.await(oldId, newId)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveMangaInfo(manga: CustomMangaInfo) {
|
||||
val mangaId = manga.mangaId
|
||||
if (manga.title == null &&
|
||||
manga.author == null &&
|
||||
manga.artist == null &&
|
||||
manga.description == null &&
|
||||
manga.genre == null &&
|
||||
(manga.status ?: -1) == -1
|
||||
) {
|
||||
if (manga.shouldDelete) {
|
||||
deleteCustomInfo(mangaId)
|
||||
} else {
|
||||
addCustomInfo(manga)
|
||||
|
|
|
@ -231,7 +231,7 @@ class MigrationProcessAdapter(
|
|||
customMangaManager.getManga(prevManga)?.let { customManga ->
|
||||
customManga.id = manga.id!!
|
||||
launchNow {
|
||||
customMangaManager.saveMangaInfo(customManga.getMangaInfo())
|
||||
customMangaManager.updateMangaInfo(prevManga.id, manga.id, customManga.getMangaInfo())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,3 +32,8 @@ WHERE manga_id = :manga_id;
|
|||
delete:
|
||||
DELETE FROM custom_manga_info
|
||||
WHERE manga_id = :manga_id;
|
||||
|
||||
relink:
|
||||
UPDATE custom_manga_info
|
||||
SET manga_id = :new_id
|
||||
WHERE manga_id = :old_id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue