mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Rename chapter interactors to use singular instead of plural
This commit is contained in:
parent
9879004157
commit
7341e10822
13 changed files with 65 additions and 65 deletions
|
@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.util.system.launchNow
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.library.custom.model.CustomMangaInfo
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.domain.manga.interactor.InsertManga
|
||||
|
@ -29,7 +29,7 @@ class MangaBackupRestorer(
|
|||
private val db: DatabaseHelper = Injekt.get(),
|
||||
private val customMangaManager: CustomMangaManager = Injekt.get(),
|
||||
private val getCategories: GetCategories = Injekt.get(),
|
||||
private val getChapters: GetChapters = Injekt.get(),
|
||||
private val getChapter: GetChapter = Injekt.get(),
|
||||
private val getManga: GetManga = Injekt.get(),
|
||||
private val insertManga: InsertManga = Injekt.get(),
|
||||
private val updateManga: UpdateManga = Injekt.get(),
|
||||
|
@ -114,7 +114,7 @@ class MangaBackupRestorer(
|
|||
}
|
||||
|
||||
private suspend fun restoreChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
val dbChapters = getChapters.await(manga)
|
||||
val dbChapters = getChapter.awaitAll(manga)
|
||||
|
||||
chapters.forEach { chapter ->
|
||||
val dbChapter = dbChapters.find { it.url == chapter.url }
|
||||
|
|
|
@ -59,8 +59,8 @@ import uy.kohesive.injekt.Injekt
|
|||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.UpdateChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.chapter.interactor.UpdateChapter
|
||||
import yokai.domain.chapter.models.ChapterUpdate
|
||||
import yokai.domain.manga.interactor.GetLibraryManga
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
|
@ -91,8 +91,8 @@ class LibraryPresenter(
|
|||
) : BaseCoroutinePresenter<LibraryController>(), DownloadQueue.DownloadListener {
|
||||
private val getCategories: GetCategories by injectLazy()
|
||||
private val getLibraryManga: GetLibraryManga by injectLazy()
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
private val updateChapter: UpdateChapters by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
private val updateChapter: UpdateChapter by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
|
||||
private var loadedManga: LibraryMap = mapOf()
|
||||
|
@ -1187,7 +1187,7 @@ class LibraryPresenter(
|
|||
|
||||
/** Returns first unread chapter of a manga */
|
||||
fun getFirstUnread(manga: Manga): Chapter? {
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
val chapters = runBlocking { getChapter.awaitAll(manga) }
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextUnreadChapter(chapters, false)
|
||||
}
|
||||
|
||||
|
@ -1350,7 +1350,7 @@ class LibraryPresenter(
|
|||
presenterScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
mangaList.forEach { list ->
|
||||
val chapters = getChapters.await(list).filter { !it.read }
|
||||
val chapters = getChapter.awaitAll(list).filter { !it.read }
|
||||
downloadManager.downloadChapters(list, chapters)
|
||||
}
|
||||
}
|
||||
|
@ -1367,7 +1367,7 @@ class LibraryPresenter(
|
|||
val mapMangaChapters = HashMap<Manga, List<Chapter>>()
|
||||
presenterScope.launchNonCancellableIO {
|
||||
mangaList.forEach { manga ->
|
||||
val chapters = getChapters.await(manga)
|
||||
val chapters = getChapter.awaitAll(manga)
|
||||
val updates = chapters.copy().mapNotNull {
|
||||
if (it.id == null) return@mapNotNull null
|
||||
ChapterUpdate(it.id!!, read = markRead, lastPageRead = 0)
|
||||
|
@ -1512,7 +1512,7 @@ class LibraryPresenter(
|
|||
|
||||
/** Give library manga to a date added based on min chapter fetch */
|
||||
suspend fun updateDB(
|
||||
getChapters: GetChapters = Injekt.get(),
|
||||
getChapter: GetChapter = Injekt.get(),
|
||||
getLibraryManga: GetLibraryManga = Injekt.get(),
|
||||
updateManga: UpdateManga = Injekt.get(),
|
||||
) {
|
||||
|
@ -1520,7 +1520,7 @@ class LibraryPresenter(
|
|||
libraryManga.forEach { manga ->
|
||||
if (manga.id == null) return@forEach
|
||||
if (manga.date_added == 0L) {
|
||||
val chapters = getChapters.await(manga)
|
||||
val chapters = getChapter.awaitAll(manga)
|
||||
manga.date_added = chapters.minByOrNull { it.date_fetch }?.date_fetch ?: 0L
|
||||
updateManga.await(MangaUpdate(manga.id!!, dateAdded = manga.date_added))
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@ import kotlinx.coroutines.runBlocking
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.presentation.core.util.IntentCommon
|
||||
|
||||
class SearchActivity : MainActivity() {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
|
||||
private var backToMain = false
|
||||
|
||||
|
@ -157,7 +157,7 @@ class SearchActivity : MainActivity() {
|
|||
if (mangaId != 0L) {
|
||||
val db = Injekt.get<DatabaseHelper>()
|
||||
db.getManga(mangaId).executeAsBlocking()?.let { manga ->
|
||||
val chapters = runBlocking { getChapters.await(manga) }
|
||||
val chapters = runBlocking { getChapter.awaitAll(manga) }
|
||||
val nextUnreadChapter = ChapterSort(manga).getNextUnreadChapter(chapters, false)
|
||||
if (nextUnreadChapter != null) {
|
||||
val activity =
|
||||
|
|
|
@ -72,7 +72,7 @@ import uy.kohesive.injekt.Injekt
|
|||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetAvailableScanlators
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.library.custom.model.CustomMangaInfo
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.domain.manga.models.MangaUpdate
|
||||
|
@ -93,7 +93,7 @@ class MangaDetailsPresenter(
|
|||
internal val storageManager: StorageManager = Injekt.get(),
|
||||
) : BaseCoroutinePresenter<MangaDetailsController>(), DownloadQueue.DownloadListener {
|
||||
private val getAvailableScanlators: GetAvailableScanlators by injectLazy()
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
|
||||
private val customMangaManager: CustomMangaManager by injectLazy()
|
||||
|
@ -178,7 +178,7 @@ class MangaDetailsPresenter(
|
|||
}
|
||||
|
||||
private suspend fun getChapters() {
|
||||
val chapters = getChapters.await(manga.id!!, isScanlatorFiltered()).map { it.toModel() }
|
||||
val chapters = getChapter.awaitAll(manga.id!!, isScanlatorFiltered()).map { it.toModel() }
|
||||
|
||||
// Find downloaded chapters
|
||||
setDownloadedChapters(chapters)
|
||||
|
@ -189,7 +189,7 @@ class MangaDetailsPresenter(
|
|||
getAvailableScanlators.await(manga.id!!)
|
||||
}.toSet()
|
||||
// Store the last emission
|
||||
allChapters = if (!isScanlatorFiltered()) chapters else getChapters.await(manga.id!!, false).map { it.toModel() }
|
||||
allChapters = if (!isScanlatorFiltered()) chapters else getChapter.awaitAll(manga.id!!, false).map { it.toModel() }
|
||||
this.chapters = applyChapterFilters(chapters)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ import rx.schedulers.Schedulers
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.download.DownloadPreferences
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.domain.manga.models.MangaUpdate
|
||||
|
@ -95,7 +95,7 @@ class ReaderViewModel(
|
|||
private val storageManager: StorageManager = Injekt.get(),
|
||||
private val downloadPreferences: DownloadPreferences = Injekt.get(),
|
||||
) : ViewModel() {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
private val updateManga: UpdateManga by injectLazy()
|
||||
|
||||
private val mutableState = MutableStateFlow(State())
|
||||
|
@ -146,7 +146,7 @@ class ReaderViewModel(
|
|||
*/
|
||||
private val chapterList by lazy {
|
||||
val manga = manga!!
|
||||
val dbChapters = runBlocking { getChapters.await(manga) }
|
||||
val dbChapters = runBlocking { getChapter.awaitAll(manga) }
|
||||
|
||||
val selectedChapter = dbChapters.find { it.id == chapterId }
|
||||
?: error("Requested chapter of id $chapterId not found in chapter list")
|
||||
|
@ -264,7 +264,7 @@ class ReaderViewModel(
|
|||
val manga = manga ?: return emptyList()
|
||||
chapterItems = withContext(Dispatchers.IO) {
|
||||
val chapterSort = ChapterSort(manga, chapterFilter, preferences)
|
||||
val dbChapters = runBlocking { getChapters.await(manga) }
|
||||
val dbChapters = runBlocking { getChapter.awaitAll(manga) }
|
||||
chapterSort.getChaptersSorted(
|
||||
dbChapters,
|
||||
filterForReader = true,
|
||||
|
|
|
@ -34,7 +34,7 @@ import kotlinx.coroutines.withContext
|
|||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.recents.RecentsPreferences
|
||||
import yokai.domain.ui.UiPreferences
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -51,7 +51,7 @@ class RecentsPresenter(
|
|||
val db: DatabaseHelper = Injekt.get(),
|
||||
private val chapterFilter: ChapterFilter = Injekt.get(),
|
||||
) : BaseCoroutinePresenter<RecentsController>(), DownloadQueue.DownloadListener {
|
||||
private val getChapters: GetChapters by injectLazy()
|
||||
private val getChapter: GetChapter by injectLazy()
|
||||
|
||||
private var recentsJob: Job? = null
|
||||
var recentItems = listOf<RecentMangaItem>()
|
||||
|
@ -452,12 +452,12 @@ class RecentsPresenter(
|
|||
}
|
||||
|
||||
private suspend fun getNextChapter(manga: Manga): Chapter? {
|
||||
val chapters = getChapters.await(manga)
|
||||
val chapters = getChapter.awaitAll(manga)
|
||||
return ChapterSort(manga, chapterFilter, preferences).getNextUnreadChapter(chapters, false)
|
||||
}
|
||||
|
||||
private suspend fun getFirstUpdatedChapter(manga: Manga, chapter: Chapter): Chapter? {
|
||||
val chapters = getChapters.await(manga)
|
||||
val chapters = getChapter.awaitAll(manga)
|
||||
return chapters
|
||||
.sortedWith(ChapterSort(manga, chapterFilter, preferences).sortComparator(true)).find {
|
||||
!it.read && abs(it.date_fetch - chapter.date_fetch) <= TimeUnit.HOURS.toMillis(12)
|
||||
|
|
|
@ -11,10 +11,10 @@ import uy.kohesive.injekt.Injekt
|
|||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.data.DatabaseHandler
|
||||
import yokai.domain.chapter.interactor.DeleteChapters
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.InsertChapters
|
||||
import yokai.domain.chapter.interactor.UpdateChapters
|
||||
import yokai.domain.chapter.interactor.DeleteChapter
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.chapter.interactor.InsertChapter
|
||||
import yokai.domain.chapter.interactor.UpdateChapter
|
||||
import yokai.domain.chapter.models.ChapterUpdate
|
||||
import yokai.domain.manga.interactor.UpdateManga
|
||||
import yokai.domain.manga.models.MangaUpdate
|
||||
|
@ -33,10 +33,10 @@ suspend fun syncChaptersWithSource(
|
|||
rawSourceChapters: List<SChapter>,
|
||||
manga: Manga,
|
||||
source: Source,
|
||||
deleteChapters: DeleteChapters = Injekt.get(),
|
||||
getChapters: GetChapters = Injekt.get(),
|
||||
insertChapters: InsertChapters = Injekt.get(),
|
||||
updateChapters: UpdateChapters = Injekt.get(),
|
||||
deleteChapter: DeleteChapter = Injekt.get(),
|
||||
getChapter: GetChapter = Injekt.get(),
|
||||
insertChapter: InsertChapter = Injekt.get(),
|
||||
updateChapter: UpdateChapter = Injekt.get(),
|
||||
updateManga: UpdateManga = Injekt.get(),
|
||||
handler: DatabaseHandler = Injekt.get(),
|
||||
): Pair<List<Chapter>, List<Chapter>> {
|
||||
|
@ -46,7 +46,7 @@ suspend fun syncChaptersWithSource(
|
|||
|
||||
val downloadManager: DownloadManager by injectLazy()
|
||||
// Chapters from db.
|
||||
val dbChapters = getChapters.await(manga, false)
|
||||
val dbChapters = getChapter.awaitAll(manga, false)
|
||||
|
||||
val sourceChapters = rawSourceChapters
|
||||
.distinctBy { it.url }
|
||||
|
@ -135,7 +135,7 @@ suspend fun syncChaptersWithSource(
|
|||
}
|
||||
deletedChapterNumbers.add(c.chapter_number)
|
||||
}
|
||||
deleteChapters.awaitAll(toDelete)
|
||||
deleteChapter.awaitAll(toDelete)
|
||||
}
|
||||
|
||||
if (toAdd.isNotEmpty()) {
|
||||
|
@ -161,12 +161,12 @@ suspend fun syncChaptersWithSource(
|
|||
}
|
||||
}
|
||||
toAdd.forEach { chapter ->
|
||||
chapter.id = insertChapters.await(chapter)
|
||||
chapter.id = insertChapter.await(chapter)
|
||||
}
|
||||
}
|
||||
|
||||
if (toChange.isNotEmpty()) {
|
||||
updateChapters.awaitAll(toChange)
|
||||
updateChapter.awaitAll(toChange)
|
||||
}
|
||||
|
||||
// Fix order in source.
|
||||
|
@ -183,7 +183,7 @@ suspend fun syncChaptersWithSource(
|
|||
|
||||
var mangaUpdate: MangaUpdate? = null
|
||||
// Set this manga as updated since chapters were changed
|
||||
val newestChapterDate = getChapters.await(manga, false)
|
||||
val newestChapterDate = getChapter.awaitAll(manga, false)
|
||||
.maxOfOrNull { it.date_upload } ?: 0L
|
||||
if (newestChapterDate == 0L) {
|
||||
if (toAdd.isNotEmpty()) {
|
||||
|
|
|
@ -13,11 +13,11 @@ import yokai.data.manga.MangaRepositoryImpl
|
|||
import yokai.domain.category.CategoryRepository
|
||||
import yokai.domain.category.interactor.GetCategories
|
||||
import yokai.domain.chapter.ChapterRepository
|
||||
import yokai.domain.chapter.interactor.DeleteChapters
|
||||
import yokai.domain.chapter.interactor.DeleteChapter
|
||||
import yokai.domain.chapter.interactor.GetAvailableScanlators
|
||||
import yokai.domain.chapter.interactor.GetChapters
|
||||
import yokai.domain.chapter.interactor.InsertChapters
|
||||
import yokai.domain.chapter.interactor.UpdateChapters
|
||||
import yokai.domain.chapter.interactor.GetChapter
|
||||
import yokai.domain.chapter.interactor.InsertChapter
|
||||
import yokai.domain.chapter.interactor.UpdateChapter
|
||||
import yokai.domain.extension.interactor.TrustExtension
|
||||
import yokai.domain.extension.repo.ExtensionRepoRepository
|
||||
import yokai.domain.extension.repo.interactor.CreateExtensionRepo
|
||||
|
@ -62,11 +62,11 @@ class DomainModule : InjektModule {
|
|||
addFactory { UpdateManga(get()) }
|
||||
|
||||
addSingletonFactory<ChapterRepository> { ChapterRepositoryImpl(get()) }
|
||||
addFactory { DeleteChapters(get()) }
|
||||
addFactory { DeleteChapter(get()) }
|
||||
addFactory { GetAvailableScanlators(get()) }
|
||||
addFactory { GetChapters(get()) }
|
||||
addFactory { InsertChapters(get()) }
|
||||
addFactory { UpdateChapters(get()) }
|
||||
addFactory { GetChapter(get()) }
|
||||
addFactory { InsertChapter(get()) }
|
||||
addFactory { UpdateChapter(get()) }
|
||||
|
||||
addSingletonFactory<CategoryRepository> { CategoryRepositoryImpl(get()) }
|
||||
addFactory { GetCategories(get()) }
|
||||
|
|
|
@ -3,7 +3,7 @@ package yokai.domain.chapter.interactor
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import yokai.domain.chapter.ChapterRepository
|
||||
|
||||
class DeleteChapters(
|
||||
class DeleteChapter(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun await(chapter: Chapter) = chapterRepository.delete(chapter)
|
|
@ -0,0 +1,14 @@
|
|||
package yokai.domain.chapter.interactor
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import yokai.domain.chapter.ChapterRepository
|
||||
|
||||
class GetChapter(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun awaitAll(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChapters(mangaId, filterScanlators)
|
||||
suspend fun awaitAll(manga: Manga, filterScanlators: Boolean? = null) =
|
||||
awaitAll(manga.id!!, filterScanlators ?: (manga.filtered_scanlators?.isNotEmpty() == true))
|
||||
|
||||
fun subscribeAll(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChaptersAsFlow(mangaId, filterScanlators)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package yokai.domain.chapter.interactor
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import yokai.domain.chapter.ChapterRepository
|
||||
|
||||
class GetChapters(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun await(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChapters(mangaId, filterScanlators)
|
||||
suspend fun await(manga: Manga, filterScanlators: Boolean? = null) =
|
||||
await(manga.id!!, filterScanlators ?: (manga.filtered_scanlators?.isNotEmpty() == true))
|
||||
|
||||
fun subscribe(mangaId: Long, filterScanlators: Boolean) = chapterRepository.getChaptersAsFlow(mangaId, filterScanlators)
|
||||
}
|
|
@ -3,7 +3,7 @@ package yokai.domain.chapter.interactor
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import yokai.domain.chapter.ChapterRepository
|
||||
|
||||
class InsertChapters(
|
||||
class InsertChapter(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun await(chapter: Chapter) = chapterRepository.insert(chapter)
|
|
@ -3,7 +3,7 @@ package yokai.domain.chapter.interactor
|
|||
import yokai.domain.chapter.ChapterRepository
|
||||
import yokai.domain.chapter.models.ChapterUpdate
|
||||
|
||||
class UpdateChapters(
|
||||
class UpdateChapter(
|
||||
private val chapterRepository: ChapterRepository,
|
||||
) {
|
||||
suspend fun await(chapter: ChapterUpdate) = chapterRepository.update(chapter)
|
Loading…
Add table
Add a link
Reference in a new issue