This commit is contained in:
Syer10
2025-10-03 21:04:05 -04:00
parent 331acb966a
commit a7cc5e664b
41 changed files with 406 additions and 538 deletions

View File

@@ -99,7 +99,7 @@ class ServerListeners
.startWith(Unit)
.combine(
_mangaChapterIdsListener.filter { mangaIdPredate?.invoke(it) ?: false }
.startWith(Unit)
.startWith(Unit),
) { _, _ -> }
return idsListener
@@ -107,17 +107,13 @@ class ServerListeners
.flatMapLatest { flow }
}
fun updateChapters(
chapterIds: List<Long>,
) {
fun updateChapters(chapterIds: List<Long>) {
scope.launch {
_chapterIdsListener.emit(chapterIds)
}
}
fun updateChapters(
vararg chapterIds: Long,
) {
fun updateChapters(vararg chapterIds: Long) {
scope.launch {
_chapterIdsListener.emit(chapterIds.toList())
}

View File

@@ -30,9 +30,7 @@ class ImportBackupFile
}
.singleOrNull()
fun asFlow(
file: Path,
) = backupRepository.restoreBackup(FileSystem.SYSTEM.source(file))
fun asFlow(file: Path) = backupRepository.restoreBackup(FileSystem.SYSTEM.source(file))
companion object {
private val log = logging()

View File

@@ -30,9 +30,7 @@ class ValidateBackupFile
}
.singleOrNull()
fun asFlow(
file: Path,
) = backupRepository.validateBackup(FileSystem.SYSTEM.source(file))
fun asFlow(file: Path) = backupRepository.validateBackup(FileSystem.SYSTEM.source(file))
companion object {
private val log = logging()

View File

@@ -8,8 +8,11 @@ import okio.Source
interface BackupRepository {
fun validateBackup(source: Source): Flow<BackupValidationResult>
fun restoreBackup(source: Source): Flow<Pair<String, RestoreStatus>>
fun restoreStatus(id: String): Flow<RestoreStatus>
fun createBackup(
includeCategories: Boolean,
includeChapters: Boolean,

View File

@@ -11,10 +11,7 @@ import ca.gosyer.jui.domain.manga.model.Manga
import kotlinx.coroutines.flow.Flow
interface CategoryRepository {
fun getMangaCategories(
mangaId: Long,
): Flow<List<Category>>
fun getMangaCategories(mangaId: Long): Flow<List<Category>>
fun addMangaToCategory(
mangaId: Long,
@@ -28,9 +25,7 @@ interface CategoryRepository {
fun getCategories(): Flow<List<Category>>
fun createCategory(
name: String,
): Flow<Unit>
fun createCategory(name: String): Flow<Unit>
fun modifyCategory(
categoryId: Long,
@@ -42,13 +37,9 @@ interface CategoryRepository {
position: Int,
): Flow<Unit>
fun deleteCategory(
categoryId: Long,
): Flow<Unit>
fun deleteCategory(categoryId: Long): Flow<Unit>
fun getMangaFromCategory(
categoryId: Long,
): Flow<List<Manga>>
fun getMangaFromCategory(categoryId: Long): Flow<List<Manga>>
fun updateCategoryMeta(
categoryId: Long,

View File

@@ -64,20 +64,18 @@ class DeleteChapterDownload
}
.collect()
fun asFlow(
chapterId: Long,
) = chapterRepository.deleteDownloadedChapter(chapterId)
.onEach { serverListeners.updateChapters(chapterId) }
fun asFlow(chapterId: Long) =
chapterRepository.deleteDownloadedChapter(chapterId)
.onEach { serverListeners.updateChapters(chapterId) }
@JvmName("asFlowChapter")
fun asFlow(chapter: Chapter) =
chapterRepository.deleteDownloadedChapter(chapter.id)
.onEach { serverListeners.updateChapters(chapter.id) }
fun asFlow(
chapterIds: List<Long>,
) = chapterRepository.deleteDownloadedChapters(chapterIds)
.onEach { serverListeners.updateChapters(chapterIds) }
fun asFlow(chapterIds: List<Long>) =
chapterRepository.deleteDownloadedChapters(chapterIds)
.onEach { serverListeners.updateChapters(chapterIds) }
@JvmName("asFlowChapters")
fun asFlow(chapter: List<Chapter>) =

View File

@@ -43,12 +43,11 @@ class GetChapter
}
.singleOrNull()
fun asFlow(
chapterId: Long,
) = serverListeners.combineChapters(
chapterRepository.getChapter(chapterId),
chapterIdPredate = { ids -> chapterId in ids },
)
fun asFlow(chapterId: Long) =
serverListeners.combineChapters(
chapterRepository.getChapter(chapterId),
chapterIdPredate = { ids -> chapterId in ids },
)
fun asFlow(chapter: Chapter) =
serverListeners.combineChapters(

View File

@@ -39,9 +39,7 @@ class GetChapterPages
}
.singleOrNull()
fun asFlow(
chapterId: Long,
) = chapterRepository.getPages(chapterId)
fun asFlow(chapterId: Long) = chapterRepository.getPages(chapterId)
fun asFlow(
url: String,

View File

@@ -48,32 +48,32 @@ class UpdateChapter
}
.collect()
suspend fun await(
chapterIds: List<Long>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
onError: suspend (Throwable) -> Unit = {},
) = asFlow(chapterIds, bookmarked, read, lastPageRead)
.catch {
onError(it)
log.warn(it) { "Failed to update chapter bookmark for chapters $chapterIds" }
}
.collect()
suspend fun await(
chapterIds: List<Long>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
onError: suspend (Throwable) -> Unit = {},
) = asFlow(chapterIds, bookmarked, read, lastPageRead)
.catch {
onError(it)
log.warn(it) { "Failed to update chapter bookmark for chapters $chapterIds" }
}
.collect()
@JvmName("awaitChapters")
suspend fun await(
chapters: List<Chapter>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
onError: suspend (Throwable) -> Unit = {},
) = asFlow(chapters, bookmarked, read, lastPageRead)
.catch {
onError(it)
log.warn(it) { "Failed to update chapter bookmark for chapters ${chapters.joinToString { it.id.toString() }}" }
}
.collect()
@JvmName("awaitChapters")
suspend fun await(
chapters: List<Chapter>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
onError: suspend (Throwable) -> Unit = {},
) = asFlow(chapters, bookmarked, read, lastPageRead)
.catch {
onError(it)
log.warn(it) { "Failed to update chapter bookmark for chapters ${chapters.joinToString { it.id.toString() }}" }
}
.collect()
fun asFlow(
chapterId: Long,
@@ -91,7 +91,7 @@ class UpdateChapter
chapter: Chapter,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null
lastPageRead: Int? = null,
) = chapterRepository.updateChapter(
chapterId = chapter.id,
bookmarked = bookmarked,
@@ -99,30 +99,30 @@ class UpdateChapter
lastPageRead = lastPageRead,
).onEach { serverListeners.updateChapters(chapter.id) }
fun asFlow(
chapterIds: List<Long>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
) = chapterRepository.updateChapters(
chapterIds = chapterIds,
bookmarked = bookmarked,
read = read,
lastPageRead = lastPageRead,
).onEach { serverListeners.updateChapters(chapterIds) }
fun asFlow(
chapterIds: List<Long>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
) = chapterRepository.updateChapters(
chapterIds = chapterIds,
bookmarked = bookmarked,
read = read,
lastPageRead = lastPageRead,
).onEach { serverListeners.updateChapters(chapterIds) }
@JvmName("asFlowChapters")
fun asFlow(
chapters: List<Chapter>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null
) = chapterRepository.updateChapters(
chapterIds = chapters.map { it.id },
bookmarked = bookmarked,
read = read,
lastPageRead = lastPageRead,
).onEach { serverListeners.updateChapters(chapters.map { it.id }) }
@JvmName("asFlowChapters")
fun asFlow(
chapters: List<Chapter>,
bookmarked: Boolean? = null,
read: Boolean? = null,
lastPageRead: Int? = null,
) = chapterRepository.updateChapters(
chapterIds = chapters.map { it.id },
bookmarked = bookmarked,
read = read,
lastPageRead = lastPageRead,
).onEach { serverListeners.updateChapters(chapters.map { it.id }) }
companion object {
private val log = logging()

View File

@@ -5,13 +5,9 @@ import io.ktor.client.request.HttpRequestBuilder
import kotlinx.coroutines.flow.Flow
interface ChapterRepository {
fun getChapter(
chapterId: Long,
): Flow<Chapter>
fun getChapter(chapterId: Long): Flow<Chapter>
fun getChapters(
mangaId: Long,
): Flow<List<Chapter>>
fun getChapters(mangaId: Long): Flow<List<Chapter>>
fun updateChapter(
chapterId: Long,
@@ -27,13 +23,9 @@ interface ChapterRepository {
lastPageRead: Int? = null,
): Flow<Unit>
fun deleteDownloadedChapter(
chapterId: Long,
): Flow<Unit>
fun deleteDownloadedChapter(chapterId: Long): Flow<Unit>
fun deleteDownloadedChapters(
chapterIds: List<Long>,
): Flow<Unit>
fun deleteDownloadedChapters(chapterIds: List<Long>): Flow<Unit>
fun updateChapterMeta(
chapterId: Long,
@@ -41,13 +33,9 @@ interface ChapterRepository {
value: String,
): Flow<Unit>
fun fetchChapters(
mangaId: Long,
): Flow<List<Chapter>>
fun fetchChapters(mangaId: Long): Flow<List<Chapter>>
fun getPages(
chapterId: Long,
): Flow<List<String>>
fun getPages(chapterId: Long): Flow<List<String>>
fun getPage(
url: String,

View File

@@ -23,13 +23,11 @@ class QueueChapterDownload
) = asFlow(chapterId)
.catch {
onError(it)
log.warn(it) { "Failed to queue chapter ${chapterId} for a download" }
log.warn(it) { "Failed to queue chapter $chapterId for a download" }
}
.collect()
fun asFlow(
chapterId: Long,
) = downloadRepository.queueChapterDownload(chapterId)
fun asFlow(chapterId: Long) = downloadRepository.queueChapterDownload(chapterId)
companion object {
private val log = logging()

View File

@@ -9,27 +9,20 @@ package ca.gosyer.jui.domain.download.service
import kotlinx.coroutines.flow.Flow
interface DownloadRepository {
fun startDownloading(): Flow<Unit>
fun stopDownloading(): Flow<Unit>
fun clearDownloadQueue(): Flow<Unit>
fun queueChapterDownload(
chapterId: Long,
): Flow<Unit>
fun queueChapterDownload(chapterId: Long): Flow<Unit>
fun stopChapterDownload(
chapterId: Long,
): Flow<Unit>
fun stopChapterDownload(chapterId: Long): Flow<Unit>
fun reorderChapterDownload(
chapterId: Long,
to: Int,
): Flow<Unit>
fun batchDownload(
chapterIds: List<Long>,
): Flow<Unit>
fun batchDownload(chapterIds: List<Long>): Flow<Unit>
}

View File

@@ -11,22 +11,13 @@ import kotlinx.coroutines.flow.Flow
import okio.Source
interface ExtensionRepository {
fun getExtensionList(): Flow<List<Extension>>
fun installExtension(
source: Source,
): Flow<Unit>
fun installExtension(source: Source): Flow<Unit>
fun installExtension(
pkgName: String,
): Flow<Unit>
fun installExtension(pkgName: String): Flow<Unit>
fun updateExtension(
pkgName: String,
): Flow<Unit>
fun updateExtension(pkgName: String): Flow<Unit>
fun uninstallExtension(
pkgName: String,
): Flow<Unit>
fun uninstallExtension(pkgName: String): Flow<Unit>
}

View File

@@ -9,11 +9,7 @@ package ca.gosyer.jui.domain.library.service
import kotlinx.coroutines.flow.Flow
interface LibraryRepository {
fun addMangaToLibrary(
mangaId: Long,
): Flow<Unit>
fun addMangaToLibrary(mangaId: Long): Flow<Unit>
fun removeMangaFromLibrary(
mangaId: Long,
): Flow<Unit>
fun removeMangaFromLibrary(mangaId: Long): Flow<Unit>
}

View File

@@ -12,18 +12,11 @@ import io.ktor.utils.io.ByteReadChannel
import kotlinx.coroutines.flow.Flow
interface MangaRepository {
fun getManga(mangaId: Long): Flow<Manga>
fun getManga(
mangaId: Long,
): Flow<Manga>
fun refreshManga(mangaId: Long): Flow<Manga>
fun refreshManga(
mangaId: Long,
): Flow<Manga>
fun getMangaLibrary(
mangaId: Long,
): Flow<Manga>
fun getMangaLibrary(mangaId: Long): Flow<Manga>
fun getMangaThumbnail(
mangaId: Long,

View File

@@ -1,9 +1,9 @@
package ca.gosyer.jui.domain.settings.model
enum class AuthMode {
NONE,
BASIC_AUTH,
SIMPLE_LOGIN,
UI_LOGIN,
UNKNOWN__,
NONE,
BASIC_AUTH,
SIMPLE_LOGIN,
UI_LOGIN,
UNKNOWN__,
}

View File

@@ -1,8 +1,7 @@
package ca.gosyer.jui.domain.settings.model
enum class DatabaseType {
H2,
POSTGRESQL,
UNKNOWN__,
;
H2,
POSTGRESQL,
UNKNOWN__,
}

View File

@@ -1,7 +1,7 @@
package ca.gosyer.jui.domain.settings.model
enum class KoreaderSyncChecksumMethod {
BINARY,
FILENAME,
UNKNOWN__,
BINARY,
FILENAME,
UNKNOWN__,
}

View File

@@ -1,9 +1,9 @@
package ca.gosyer.jui.domain.settings.model
enum class KoreaderSyncConflictStrategy {
PROMPT,
KEEP_LOCAL,
KEEP_REMOTE,
DISABLED,
UNKNOWN__,
PROMPT,
KEEP_LOCAL,
KEEP_REMOTE,
DISABLED,
UNKNOWN__,
}

View File

@@ -1,11 +1,11 @@
package ca.gosyer.jui.domain.settings.model
enum class SortOrder {
ASC,
DESC,
ASC_NULLS_FIRST,
DESC_NULLS_FIRST,
ASC_NULLS_LAST,
DESC_NULLS_LAST,
UNKNOWN__,
ASC,
DESC,
ASC_NULLS_FIRST,
DESC_NULLS_FIRST,
ASC_NULLS_LAST,
DESC_NULLS_LAST,
UNKNOWN__,
}

View File

@@ -38,13 +38,9 @@ class GetFilterList
}
.singleOrNull()
fun asFlow(
source: Source,
) = sourceRepository.getFilterList(source.id)
fun asFlow(source: Source) = sourceRepository.getFilterList(source.id)
fun asFlow(
sourceId: Long,
) = sourceRepository.getFilterList(sourceId)
fun asFlow(sourceId: Long) = sourceRepository.getFilterList(sourceId)
companion object {
private val log = logging()

View File

@@ -25,31 +25,31 @@ data class SourceFilterChangeOld(
)
}
sealed interface SourceFilter {
val position: Int
data class Checkbox(
override val position: Int,
val name: String,
val default: Boolean,
val value: Boolean = default,
): SourceFilter
) : SourceFilter
data class Header(
override val position: Int,
val name: String,
): SourceFilter
) : SourceFilter
data class Separator(
override val position: Int,
val name: String,
): SourceFilter
) : SourceFilter
data class Group(
override val position: Int,
val name: String,
val value: List<SourceFilter>,
): SourceFilter
) : SourceFilter
data class Select(
override val position: Int,
@@ -57,7 +57,7 @@ sealed interface SourceFilter {
val values: List<String>,
val default: Int,
val value: Int = default,
): SourceFilter
) : SourceFilter
data class Sort(
override val position: Int,
@@ -65,10 +65,10 @@ sealed interface SourceFilter {
val values: List<String>,
val default: SelectionChange?,
val value: SelectionChange? = default,
): SourceFilter {
) : SourceFilter {
data class SelectionChange(
val ascending: Boolean,
val index: Int
val index: Int,
)
}
@@ -77,18 +77,18 @@ sealed interface SourceFilter {
val name: String,
val default: String,
val value: String = default,
): SourceFilter
) : SourceFilter
data class TriState(
override val position: Int,
val name: String,
val default: TriStateValue,
val value: TriStateValue = default,
): SourceFilter {
) : SourceFilter {
enum class TriStateValue {
IGNORE,
INCLUDE,
EXCLUDE
EXCLUDE,
}
}
}

View File

@@ -13,12 +13,9 @@ import ca.gosyer.jui.domain.source.model.sourcepreference.SourcePreference
import kotlinx.coroutines.flow.Flow
interface SourceRepository {
fun getSourceList(): Flow<List<Source>>
fun getSourceInfo(
sourceId: Long,
): Flow<Source>
fun getSourceInfo(sourceId: Long): Flow<Source>
fun getPopularManga(
sourceId: Long,
@@ -30,9 +27,7 @@ interface SourceRepository {
pageNum: Int,
): Flow<MangaPage>
fun getFilterList(
sourceId: Long,
): Flow<List<SourceFilter>>
fun getFilterList(sourceId: Long): Flow<List<SourceFilter>>
fun getSearchResults(
sourceId: Long,
@@ -41,9 +36,7 @@ interface SourceRepository {
filters: List<SourceFilter>?,
): Flow<MangaPage>
fun getSourceSettings(
sourceId: Long,
): Flow<List<SourcePreference>>
fun getSourceSettings(sourceId: Long): Flow<List<SourcePreference>>
fun setSourceSetting(
sourceId: Long,

View File

@@ -10,13 +10,9 @@ import ca.gosyer.jui.domain.updates.model.Updates
import kotlinx.coroutines.flow.Flow
interface UpdatesRepository {
fun getRecentUpdates(
pageNum: Int,
): Flow<Updates>
fun getRecentUpdates(pageNum: Int): Flow<Updates>
fun updateLibrary(): Flow<Unit>
fun updateCategory(
categoryId: Long,
): Flow<Unit>
fun updateCategory(categoryId: Long): Flow<Unit>
}

View File

@@ -67,10 +67,10 @@ sealed class ServerHostPreference<T : Any> {
class RootPath(
preferenceStore: PreferenceStore,
) : StringServerHostPreference(
preferenceStore,
"rootDir",
"",
)
preferenceStore,
"rootDir",
"",
)
class IP(
preferenceStore: PreferenceStore,