Minor cleanup

(cherry picked from commit bc1fbfac9d3bd6a13b755acb5ac0a2ed702ba1a2)

# Conflicts:
#	app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt
#	app/src/main/java/eu/kanade/domain/manga/repository/MangaRepository.kt
#	app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt
#	app/src/main/java/eu/kanade/tachiyomi/source/SourceExtensions.kt
This commit is contained in:
arkon 2022-10-14 16:13:50 -04:00 committed by Jobobby04
parent 7da8484d81
commit a82b86bec8
22 changed files with 65 additions and 82 deletions

View File

@ -121,9 +121,9 @@ class MangaRepositoryImpl(
}
}
override suspend fun updateAll(values: List<MangaUpdate>): Boolean {
override suspend fun updateAll(mangaUpdates: List<MangaUpdate>): Boolean {
return try {
partialUpdate(*values.toTypedArray())
partialUpdate(*mangaUpdates.toTypedArray())
true
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
@ -131,9 +131,9 @@ class MangaRepositoryImpl(
}
}
private suspend fun partialUpdate(vararg values: MangaUpdate) {
private suspend fun partialUpdate(vararg mangaUpdates: MangaUpdate) {
handler.await(inTransaction = true) {
values.forEach { value ->
mangaUpdates.forEach { value ->
mangasQueries.update(
source = value.source,
url = value.url,

View File

@ -58,9 +58,9 @@ class TrackRepositoryImpl(
insertValues(*tracks.toTypedArray())
}
private suspend fun insertValues(vararg values: Track) {
private suspend fun insertValues(vararg tracks: Track) {
handler.await(inTransaction = true) {
values.forEach { mangaTrack ->
tracks.forEach { mangaTrack ->
manga_syncQueries.insert(
mangaId = mangaTrack.mangaId,
syncId = mangaTrack.syncId,

View File

@ -32,7 +32,7 @@ import eu.kanade.domain.download.interactor.DeleteDownload
import eu.kanade.domain.extension.interactor.GetExtensionLanguages
import eu.kanade.domain.extension.interactor.GetExtensionSources
import eu.kanade.domain.extension.interactor.GetExtensionsByType
import eu.kanade.domain.history.interactor.DeleteHistoryTable
import eu.kanade.domain.history.interactor.DeleteAllHistory
import eu.kanade.domain.history.interactor.GetHistory
import eu.kanade.domain.history.interactor.GetNextChapter
import eu.kanade.domain.history.interactor.RemoveHistoryById
@ -117,7 +117,7 @@ class DomainModule : InjektModule {
addFactory { SyncChaptersWithTrackServiceTwoWay(get(), get()) }
addSingletonFactory<HistoryRepository> { HistoryRepositoryImpl(get()) }
addFactory { DeleteHistoryTable(get()) }
addFactory { DeleteAllHistory(get()) }
addFactory { GetHistory(get()) }
addFactory { UpsertHistory(get()) }
addFactory { RemoveHistoryById(get()) }

View File

@ -4,9 +4,8 @@ import eu.kanade.domain.category.model.Category
import eu.kanade.domain.category.model.anyWithName
import eu.kanade.domain.category.repository.CategoryRepository
import eu.kanade.domain.library.service.LibraryPreferences
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import logcat.LogPriority
class CreateCategoryWithName(
@ -22,10 +21,10 @@ class CreateCategoryWithName(
sort.direction.flag
}
suspend fun await(name: String): Result = withContext(NonCancellable) {
suspend fun await(name: String): Result = withNonCancellableContext {
val categories = categoryRepository.getAll()
if (categories.anyWithName(name)) {
return@withContext Result.NameAlreadyExistsError
return@withNonCancellableContext Result.NameAlreadyExistsError
}
val nextOrder = categories.maxOfOrNull { it.order }?.plus(1) ?: 0

View File

@ -2,21 +2,20 @@ package eu.kanade.domain.category.interactor
import eu.kanade.domain.category.model.CategoryUpdate
import eu.kanade.domain.category.repository.CategoryRepository
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import logcat.LogPriority
class DeleteCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(categoryId: Long) = withContext(NonCancellable) {
suspend fun await(categoryId: Long) = withNonCancellableContext {
try {
categoryRepository.delete(categoryId)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
return@withContext Result.InternalError(e)
return@withNonCancellableContext Result.InternalError(e)
}
val categories = categoryRepository.getAll()

View File

@ -4,19 +4,18 @@ import eu.kanade.domain.category.model.Category
import eu.kanade.domain.category.model.CategoryUpdate
import eu.kanade.domain.category.model.anyWithName
import eu.kanade.domain.category.repository.CategoryRepository
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import logcat.LogPriority
class RenameCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(categoryId: Long, name: String) = withContext(NonCancellable) {
suspend fun await(categoryId: Long, name: String) = withNonCancellableContext {
val categories = categoryRepository.getAll()
if (categories.anyWithName(name)) {
return@withContext Result.NameAlreadyExistsError
return@withNonCancellableContext Result.NameAlreadyExistsError
}
val update = CategoryUpdate(

View File

@ -3,21 +3,20 @@ package eu.kanade.domain.category.interactor
import eu.kanade.domain.category.model.Category
import eu.kanade.domain.category.model.CategoryUpdate
import eu.kanade.domain.category.repository.CategoryRepository
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import logcat.LogPriority
class ReorderCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(categoryId: Long, newPosition: Int) = withContext(NonCancellable) {
suspend fun await(categoryId: Long, newPosition: Int) = withNonCancellableContext {
val categories = categoryRepository.getAll().filterNot(Category::isSystemCategory)
val currentIndex = categories.indexOfFirst { it.id == categoryId }
if (currentIndex == newPosition) {
return@withContext Result.Unchanged
return@withNonCancellableContext Result.Unchanged
}
val reorderedCategories = categories.toMutableList()

View File

@ -2,14 +2,13 @@ package eu.kanade.domain.category.interactor
import eu.kanade.domain.category.model.CategoryUpdate
import eu.kanade.domain.category.repository.CategoryRepository
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
class UpdateCategory(
private val categoryRepository: CategoryRepository,
) {
suspend fun await(payload: CategoryUpdate): Result = withContext(NonCancellable) {
suspend fun await(payload: CategoryUpdate): Result = withNonCancellableContext {
try {
categoryRepository.updatePartial(payload)
Result.Success

View File

@ -9,10 +9,9 @@ import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.repository.MangaRepository
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.online.all.MergedSource
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
import eu.kanade.tachiyomi.util.system.logcat
import exh.source.MERGED_SOURCE_ID
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import logcat.LogPriority
class SetReadStatus(
@ -31,38 +30,28 @@ class SetReadStatus(
)
}
suspend fun await(read: Boolean, vararg values: Chapter): Result = withContext(NonCancellable) {
val chapters = values.filterNot { it.read == read }
if (chapters.isEmpty()) {
return@withContext Result.NoChapters
}
val manga = chapters.fold(mutableSetOf<Manga>()) { acc, chapter ->
if (acc.all { it.id != chapter.mangaId }) {
acc += mangaRepository.getMangaById(chapter.mangaId)
}
acc
suspend fun await(read: Boolean, vararg chapters: Chapter): Result = withNonCancellableContext {
val chaptersToUpdate = chapters.filterNot { it.read == read }
if (chaptersToUpdate.isEmpty()) {
return@withNonCancellableContext Result.NoChapters
}
try {
chapterRepository.updateAll(
chapters.map { chapter ->
mapper(chapter, read)
},
chaptersToUpdate.map { mapper(it, read) },
)
} catch (e: Exception) {
logcat(LogPriority.ERROR, e)
return@withContext Result.InternalError(e)
return@withNonCancellableContext Result.InternalError(e)
}
if (read && downloadPreferences.removeAfterMarkedAsRead().get()) {
manga.forEach {
chaptersToUpdate
.groupBy { it.mangaId }
.forEach { (mangaId, chapters) ->
deleteDownload.awaitAll(
manga = it,
values = chapters
.filter { chapter -> it.id == chapter.mangaId }
.toTypedArray(),
manga = mangaRepository.getMangaById(mangaId),
chapters = chapters.toTypedArray(),
)
}
}
@ -70,21 +59,21 @@ class SetReadStatus(
Result.Success
}
suspend fun await(mangaId: Long, read: Boolean): Result = withContext(NonCancellable) {
suspend fun await(mangaId: Long, read: Boolean): Result = withNonCancellableContext {
await(
read = read,
values = chapterRepository
chapters = chapterRepository
.getChapterByMangaId(mangaId)
.toTypedArray(),
)
}
// SY -->
private suspend fun awaitMerged(mangaId: Long, read: Boolean) = withContext(NonCancellable) f@{
private suspend fun awaitMerged(mangaId: Long, read: Boolean) = withNonCancellableContext f@{
val mergedSource = sourceManager.get(MERGED_SOURCE_ID) as MergedSource
return@f await(
read = read,
values = mergedSource
chapters = mergedSource
.getChapters(mangaId, dedupe = false)
.toTypedArray(),
)

View File

@ -9,8 +9,8 @@ import eu.kanade.domain.chapter.repository.ChapterRepository
import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.isLocal
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
@ -43,7 +43,7 @@ class SyncChaptersWithSource(
manga: Manga,
source: Source,
): List<Chapter> {
if (rawSourceChapters.isEmpty() && source.id != LocalSource.ID) {
if (rawSourceChapters.isEmpty() && !source.isLocal()) {
throw NoChaptersException()
}

View File

@ -5,17 +5,16 @@ import eu.kanade.domain.chapter.model.toDbChapter
import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.source.SourceManager
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import eu.kanade.tachiyomi.util.lang.withNonCancellableContext
class DeleteDownload(
private val sourceManager: SourceManager,
private val downloadManager: DownloadManager,
) {
suspend fun awaitAll(manga: Manga, vararg values: Chapter) = withContext(NonCancellable) {
suspend fun awaitAll(manga: Manga, vararg chapters: Chapter) = withNonCancellableContext {
sourceManager.get(manga.source)?.let { source ->
downloadManager.deleteChapters(values.map { it.toDbChapter() }, manga, source)
downloadManager.deleteChapters(chapters.map { it.toDbChapter() }, manga, source)
}
}
}

View File

@ -2,7 +2,7 @@ package eu.kanade.domain.history.interactor
import eu.kanade.domain.history.repository.HistoryRepository
class DeleteHistoryTable(
class DeleteAllHistory(
private val repository: HistoryRepository,
) {

View File

@ -21,8 +21,8 @@ class UpdateManga(
return mangaRepository.update(mangaUpdate)
}
suspend fun awaitAll(values: List<MangaUpdate>): Boolean {
return mangaRepository.updateAll(values)
suspend fun awaitAll(mangaUpdates: List<MangaUpdate>): Boolean {
return mangaRepository.updateAll(mangaUpdates)
}
suspend fun awaitUpdateFromSource(

View File

@ -33,7 +33,7 @@ interface MangaRepository {
suspend fun update(update: MangaUpdate): Boolean
suspend fun updateAll(values: List<MangaUpdate>): Boolean
suspend fun updateAll(mangaUpdates: List<MangaUpdate>): Boolean
suspend fun getMangaBySourceId(sourceId: Long): List<Manga>

View File

@ -18,7 +18,7 @@ class GetUpdates(
return repository.subscribeAll(after)
.onEach { updates ->
// Set unread chapter count for bottom bar badge
preferences.unreadUpdatesCount().set(updates.count { it.read.not() })
preferences.unreadUpdatesCount().set(updates.count { !it.read })
}
}
}

View File

@ -10,6 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import eu.kanade.domain.category.model.Category
import eu.kanade.domain.library.model.LibraryManga
import eu.kanade.domain.manga.model.isLocal
import eu.kanade.presentation.components.EmptyScreen
import eu.kanade.presentation.components.EmptyScreenAction
import eu.kanade.presentation.components.LibraryBottomActionMenu
@ -18,7 +19,6 @@ import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.library.components.LibraryContent
import eu.kanade.presentation.library.components.LibraryToolbar
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.ui.library.LibraryPresenter
import eu.kanade.tachiyomi.widget.TachiyomiBottomNavigationView
@ -74,7 +74,7 @@ fun LibraryScreen(
onChangeCategoryClicked = onChangeCategoryClicked,
onMarkAsReadClicked = onMarkAsReadClicked,
onMarkAsUnreadClicked = onMarkAsUnreadClicked,
onDownloadClicked = onDownloadClicked.takeIf { presenter.selection.none { it.manga.source == LocalSource.ID } },
onDownloadClicked = onDownloadClicked.takeIf { presenter.selection.none { it.manga.isLocal() } },
onDeleteClicked = onDeleteClicked,
// SY -->
onClickCleanTitles = onClickCleanTitles.takeIf { presenter.showCleanTitles },

View File

@ -407,7 +407,7 @@ class Downloader(
// When the page is ready, set page path, progress (just in case) and status
.doOnNext { file ->
val success = splitTallImageIfNeeded(page, tmpDir)
if (success.not()) {
if (!success) {
notifier.onError(context.getString(R.string.download_notifier_split_failed), download.chapter.name, download.manga.title)
}
page.uri = file.uri

View File

@ -55,4 +55,6 @@ private fun getMergedSourcesString(
}
// SY <--
fun Source.isLocalOrStub(): Boolean = id == LocalSource.ID || this is SourceManager.StubSource
fun Source.isLocal(): Boolean = id == LocalSource.ID
fun Source.isLocalOrStub(): Boolean = isLocal() || this is SourceManager.StubSource

View File

@ -15,9 +15,9 @@ import com.google.android.material.chip.ChipGroup
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.domain.manga.interactor.GetManga
import eu.kanade.domain.manga.model.Manga
import eu.kanade.domain.manga.model.isLocal
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.EditMangaDialogBinding
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.chop
@ -71,8 +71,6 @@ class EditMangaDialog : DialogController {
fun onViewCreated() {
loadCover()
val isLocal = manga.source == LocalSource.ID
val statusAdapter: ArrayAdapter<String> = ArrayAdapter(
context,
android.R.layout.simple_spinner_dropdown_item,
@ -103,7 +101,7 @@ class EditMangaDialog : DialogController {
)
}
if (isLocal) {
if (manga.isLocal()) {
if (manga.title != manga.url) {
binding.title.setText(manga.title)
}
@ -151,7 +149,7 @@ class EditMangaDialog : DialogController {
}
private fun resetTags() {
if (manga.genre.isNullOrEmpty() || manga.source == LocalSource.ID) {
if (manga.genre.isNullOrEmpty() || manga.isLocal()) {
binding.mangaGenresTags.setChips(emptyList())
} else {
binding.mangaGenresTags.setChips(manga.ogGenre.orEmpty())

View File

@ -1125,7 +1125,7 @@ class MangaPresenter(
presenterScope.launchIO {
setReadStatus.await(
read = read,
values = chapters.toTypedArray(),
chapters = chapters.toTypedArray(),
)
}
toggleAllSelection(false)

View File

@ -9,7 +9,7 @@ import androidx.compose.runtime.setValue
import eu.kanade.core.util.insertSeparators
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.history.interactor.DeleteHistoryTable
import eu.kanade.domain.history.interactor.DeleteAllHistory
import eu.kanade.domain.history.interactor.GetHistory
import eu.kanade.domain.history.interactor.GetNextChapter
import eu.kanade.domain.history.interactor.RemoveHistoryById
@ -38,7 +38,7 @@ class HistoryPresenter(
private val state: HistoryStateImpl = HistoryState() as HistoryStateImpl,
private val getHistory: GetHistory = Injekt.get(),
private val getNextChapter: GetNextChapter = Injekt.get(),
private val deleteHistoryTable: DeleteHistoryTable = Injekt.get(),
private val deleteAllHistory: DeleteAllHistory = Injekt.get(),
private val removeHistoryById: RemoveHistoryById = Injekt.get(),
private val removeHistoryByMangaId: RemoveHistoryByMangaId = Injekt.get(),
preferences: BasePreferences = Injekt.get(),
@ -101,7 +101,7 @@ class HistoryPresenter(
fun deleteAllHistory() {
presenterScope.launchIO {
val result = deleteHistoryTable.await()
val result = deleteAllHistory.await()
if (!result) return@launchIO
withUIContext {
view?.activity?.toast(R.string.clear_history_completed)

View File

@ -217,7 +217,7 @@ class UpdatesPresenter(
presenterScope.launchIO {
setReadStatus.await(
read = read,
values = updates
chapters = updates
.mapNotNull { getChapter.await(it.update.chapterId) }
.toTypedArray(),
)