Move some interactors to domain module

This commit is contained in:
arkon
2023-01-27 22:37:17 -05:00
parent 1730dd6af1
commit f2c48480b6
23 changed files with 30 additions and 29 deletions

View File

@@ -0,0 +1,26 @@
package tachiyomi.domain.category.interactor
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.category.model.Category
import tachiyomi.domain.category.repository.CategoryRepository
class GetCategories(
private val categoryRepository: CategoryRepository,
) {
fun subscribe(): Flow<List<Category>> {
return categoryRepository.getAllAsFlow()
}
fun subscribe(mangaId: Long): Flow<List<Category>> {
return categoryRepository.getCategoriesByMangaIdAsFlow(mangaId)
}
suspend fun await(): List<Category> {
return categoryRepository.getAll()
}
suspend fun await(mangaId: Long): List<Category> {
return categoryRepository.getCategoriesByMangaId(mangaId)
}
}

View File

@@ -0,0 +1,13 @@
package tachiyomi.domain.chapter.interactor
import tachiyomi.domain.chapter.model.Chapter
class ShouldUpdateDbChapter {
fun await(dbChapter: Chapter, sourceChapter: Chapter): Boolean {
return dbChapter.scanlator != sourceChapter.scanlator || dbChapter.name != sourceChapter.name ||
dbChapter.dateUpload != sourceChapter.dateUpload ||
dbChapter.chapterNumber != sourceChapter.chapterNumber ||
dbChapter.sourceOrder != sourceChapter.sourceOrder
}
}

View File

@@ -0,0 +1,14 @@
package tachiyomi.domain.history.interactor
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.history.model.HistoryWithRelations
import tachiyomi.domain.history.repository.HistoryRepository
class GetHistory(
private val repository: HistoryRepository,
) {
fun subscribe(query: String): Flow<List<HistoryWithRelations>> {
return repository.getHistory(query)
}
}

View File

@@ -0,0 +1,12 @@
package tachiyomi.domain.history.interactor
import tachiyomi.domain.history.repository.HistoryRepository
class GetTotalReadDuration(
private val repository: HistoryRepository,
) {
suspend fun await(): Long {
return repository.getTotalReadDuration()
}
}

View File

@@ -0,0 +1,21 @@
package tachiyomi.domain.history.interactor
import tachiyomi.domain.history.model.HistoryWithRelations
import tachiyomi.domain.history.repository.HistoryRepository
class RemoveHistory(
private val repository: HistoryRepository,
) {
suspend fun awaitAll(): Boolean {
return repository.deleteAllHistory()
}
suspend fun await(history: HistoryWithRelations) {
repository.resetHistory(history.id)
}
suspend fun await(mangaId: Long) {
repository.resetHistoryByMangaId(mangaId)
}
}

View File

@@ -0,0 +1,13 @@
package tachiyomi.domain.history.interactor
import tachiyomi.domain.history.model.HistoryUpdate
import tachiyomi.domain.history.repository.HistoryRepository
class UpsertHistory(
private val historyRepository: HistoryRepository,
) {
suspend fun await(historyUpdate: HistoryUpdate) {
historyRepository.upsertHistory(historyUpdate)
}
}

View File

@@ -0,0 +1,17 @@
package tachiyomi.domain.updates.interactor
import kotlinx.coroutines.flow.Flow
import tachiyomi.domain.updates.model.UpdatesWithRelations
import tachiyomi.domain.updates.repository.UpdatesRepository
import java.util.Calendar
class GetUpdates(
private val repository: UpdatesRepository,
) {
fun subscribe(calendar: Calendar): Flow<List<UpdatesWithRelations>> = subscribe(calendar.time.time)
fun subscribe(after: Long): Flow<List<UpdatesWithRelations>> {
return repository.subscribeAll(after)
}
}