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

@@ -22,16 +22,16 @@ actual suspend fun ByteReadChannel.toSource(context: CoroutineContext): Source {
channel.cancel()
}
override fun read(sink: Buffer, byteCount: Long): Long {
override fun read(
sink: Buffer,
byteCount: Long,
): Long {
val buffer = ByteArray(byteCount.toInt())
val read = runBlocking(context) { channel.readAvailable(buffer) }
sink.write(buffer.reversedArray())
return read.toLong()
}
override fun timeout(): Timeout {
return Timeout()
}
override fun timeout(): Timeout = Timeout()
}
}

View File

@@ -1,4 +1,3 @@
package ca.gosyer.jui.data
actual interface SharedDataComponent {
}
actual interface SharedDataComponent

View File

@@ -28,9 +28,8 @@ class BackupRepositoryImpl(
private val http: Http,
private val serverUrl: Url,
) : BackupRepository {
override fun validateBackup(source: Source): Flow<BackupValidationResult> {
return apolloClient.query(
override fun validateBackup(source: Source): Flow<BackupValidationResult> =
apolloClient.query(
ValidateBackupQuery(
DefaultUpload.Builder()
.content {
@@ -38,21 +37,20 @@ class BackupRepositoryImpl(
}
.fileName("backup.tachibk")
.contentType("application/octet-stream")
.build()
)
.build(),
),
).toFlow()
.map {
BackupValidationResult(
missingSources = it.dataAssertNoErrors.validateBackup.missingSources.map { source ->
"${source.name} (${source.id})"
},
missingTrackers = emptyList()
missingTrackers = emptyList(),
)
}
}
override fun restoreBackup(source: Source): Flow<Pair<String, RestoreStatus>> {
return apolloClient.mutation(
override fun restoreBackup(source: Source): Flow<Pair<String, RestoreStatus>> =
apolloClient.mutation(
RestoreBackupMutation(
DefaultUpload.Builder()
.content {
@@ -60,8 +58,8 @@ class BackupRepositoryImpl(
}
.fileName("backup.tachibk")
.contentType("application/octet-stream")
.build()
)
.build(),
),
).toFlow()
.map {
val data = it.dataAssertNoErrors
@@ -69,54 +67,52 @@ class BackupRepositoryImpl(
.restoreStatusFragment
.toRestoreStatus()
}
}
override fun restoreStatus(id: String): Flow<RestoreStatus> {
return apolloClient.query(
RestoreStatusQuery(id)
override fun restoreStatus(id: String): Flow<RestoreStatus> =
apolloClient.query(
RestoreStatusQuery(id),
).toFlow()
.map {
val data = it.dataAssertNoErrors
data.restoreStatus!!.restoreStatusFragment.toRestoreStatus()
}
}
override fun createBackup(
includeCategories: Boolean,
includeChapters: Boolean,
block: HttpRequestBuilder.() -> Unit,
): Flow<Pair<String, Source>> {
return apolloClient
): Flow<Pair<String, Source>> =
apolloClient
.mutation(
CreateBackupMutation(includeCategories, includeChapters)
CreateBackupMutation(includeCategories, includeChapters),
)
.toFlow()
.map {
val url = it.dataAssertNoErrors.createBackup.url
val response = http.get(
Url("$serverUrl${url}")
Url("$serverUrl$url"),
)
val fileName = response.headers["content-disposition"]!!
.substringAfter("filename=")
.trim('"')
fileName to response.bodyAsChannel().toSource()
}
}
companion object {
private fun RestoreStatusFragment.toRestoreStatus() = RestoreStatus(
when (state) {
BackupRestoreState.IDLE -> RestoreState.IDLE
BackupRestoreState.SUCCESS -> RestoreState.SUCCESS
BackupRestoreState.FAILURE -> RestoreState.FAILURE
BackupRestoreState.RESTORING_CATEGORIES -> RestoreState.RESTORING_CATEGORIES
BackupRestoreState.RESTORING_MANGA -> RestoreState.RESTORING_MANGA
BackupRestoreState.RESTORING_META -> RestoreState.RESTORING_META
BackupRestoreState.RESTORING_SETTINGS -> RestoreState.RESTORING_SETTINGS
BackupRestoreState.UNKNOWN__ -> RestoreState.UNKNOWN
},
mangaProgress,
totalManga,
)
private fun RestoreStatusFragment.toRestoreStatus() =
RestoreStatus(
when (state) {
BackupRestoreState.IDLE -> RestoreState.IDLE
BackupRestoreState.SUCCESS -> RestoreState.SUCCESS
BackupRestoreState.FAILURE -> RestoreState.FAILURE
BackupRestoreState.RESTORING_CATEGORIES -> RestoreState.RESTORING_CATEGORIES
BackupRestoreState.RESTORING_MANGA -> RestoreState.RESTORING_MANGA
BackupRestoreState.RESTORING_META -> RestoreState.RESTORING_META
BackupRestoreState.RESTORING_SETTINGS -> RestoreState.RESTORING_SETTINGS
BackupRestoreState.UNKNOWN__ -> RestoreState.UNKNOWN
},
mangaProgress,
totalManga,
)
}
}

View File

@@ -32,142 +32,131 @@ class CategoryRepositoryImpl(
private val apolloClient: ApolloClient,
private val http: Http,
private val serverUrl: Url,
): CategoryRepository {
override fun getMangaCategories(mangaId: Long): Flow<List<Category>> {
return apolloClient.query(
GetMangaCategoriesQuery(mangaId.toInt())
) : CategoryRepository {
override fun getMangaCategories(mangaId: Long): Flow<List<Category>> =
apolloClient.query(
GetMangaCategoriesQuery(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.manga.categories.nodes.map { it.categoryFragment.toCategory() }
}
}
override fun addMangaToCategory(
mangaId: Long,
categoryId: Long,
): Flow<Unit> {
return apolloClient.mutation(
AddMangaToCategoriesMutation(mangaId.toInt(), listOf(categoryId.toInt()))
): Flow<Unit> =
apolloClient.mutation(
AddMangaToCategoriesMutation(mangaId.toInt(), listOf(categoryId.toInt())),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateMangaCategories!!.clientMutationId
}
}
override fun removeMangaFromCategory(
mangaId: Long,
categoryId: Long,
): Flow<Unit> {
return apolloClient.mutation(
RemoveMangaFromCategoriesMutation(mangaId.toInt(), listOf(categoryId.toInt()))
): Flow<Unit> =
apolloClient.mutation(
RemoveMangaFromCategoriesMutation(mangaId.toInt(), listOf(categoryId.toInt())),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateMangaCategories!!.clientMutationId
}
}
override fun getCategories(): Flow<List<Category>> {
return apolloClient.query(
GetCategoriesQuery()
override fun getCategories(): Flow<List<Category>> =
apolloClient.query(
GetCategoriesQuery(),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.categories.nodes.map { it.categoryFragment.toCategory() }
}
}
override fun createCategory(name: String): Flow<Unit> {
return apolloClient.mutation(
CreateCategoryMutation(name)
override fun createCategory(name: String): Flow<Unit> =
apolloClient.mutation(
CreateCategoryMutation(name),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.createCategory!!.clientMutationId
}
}
override fun modifyCategory(
categoryId: Long,
name: String,
): Flow<Unit> {
return apolloClient.mutation(
ModifyCategoryMutation(categoryId.toInt(), name)
): Flow<Unit> =
apolloClient.mutation(
ModifyCategoryMutation(categoryId.toInt(), name),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateCategory!!.clientMutationId
}
}
override fun reorderCategory(
categoryId: Long,
position: Int,
): Flow<Unit> {
return apolloClient.mutation(
ReorderCategoryMutation(categoryId.toInt(), position)
): Flow<Unit> =
apolloClient.mutation(
ReorderCategoryMutation(categoryId.toInt(), position),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateCategoryOrder!!.clientMutationId
}
}
override fun deleteCategory(categoryId: Long): Flow<Unit> {
return apolloClient.mutation(
DeleteCategoryMutation(categoryId.toInt())
override fun deleteCategory(categoryId: Long): Flow<Unit> =
apolloClient.mutation(
DeleteCategoryMutation(categoryId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.deleteCategory!!.clientMutationId
}
}
override fun getMangaFromCategory(categoryId: Long): Flow<List<Manga>> {
return apolloClient.query(
GetCategoryMangaQuery(listOf(categoryId.toInt()))
override fun getMangaFromCategory(categoryId: Long): Flow<List<Manga>> =
apolloClient.query(
GetCategoryMangaQuery(listOf(categoryId.toInt())),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.mangas.nodes.map { it.mangaFragment.toManga() }
}
}
override fun updateCategoryMeta(
categoryId: Long,
key: String,
value: String,
): Flow<Unit> {
return apolloClient.mutation(
SetCategoryMetaMutation(categoryId.toInt(), key, value)
): Flow<Unit> =
apolloClient.mutation(
SetCategoryMetaMutation(categoryId.toInt(), key, value),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.setCategoryMeta!!.clientMutationId
}
}
companion object {
internal fun CategoryFragment.toCategory(): Category {
return Category(
internal fun CategoryFragment.toCategory(): Category =
Category(
id = id.toLong(),
order = order,
name = name,
default = default,
meta = CategoryMeta()
meta = CategoryMeta(),
)
}
}
}

View File

@@ -33,145 +33,130 @@ class ChapterRepositoryImpl(
private val http: Http,
private val serverUrl: Url,
) : ChapterRepository {
override fun getChapter(chapterId: Long): Flow<Chapter> {
return apolloClient.query(
GetChapterQuery(chapterId.toInt())
override fun getChapter(chapterId: Long): Flow<Chapter> =
apolloClient.query(
GetChapterQuery(chapterId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.chapter.chapterFragment.toChapter()
}
}
override fun getChapters(mangaId: Long): Flow<List<Chapter>> {
return apolloClient.query(
GetMangaChaptersQuery(mangaId.toInt())
override fun getChapters(mangaId: Long): Flow<List<Chapter>> =
apolloClient.query(
GetMangaChaptersQuery(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.chapters.nodes.map { it.chapterFragment.toChapter() }
}
}
override fun updateChapter(
chapterId: Long,
bookmarked: Boolean?,
read: Boolean?,
lastPageRead: Int?,
): Flow<Unit> {
return apolloClient.mutation(
): Flow<Unit> =
apolloClient.mutation(
UpdateChapterMutation(
chapterId.toInt(),
UpdateChapterPatchInput(
isBookmarked = Optional.presentIfNotNull(bookmarked),
isRead = Optional.presentIfNotNull(read),
lastPageRead = Optional.presentIfNotNull(lastPageRead)
lastPageRead = Optional.presentIfNotNull(lastPageRead),
),
)
),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun updateChapters(
chapterIds: List<Long>,
bookmarked: Boolean?,
read: Boolean?,
lastPageRead: Int?,
): Flow<Unit> {
return apolloClient.mutation(
): Flow<Unit> =
apolloClient.mutation(
UpdateChaptersMutation(
chapterIds.map { it.toInt() },
UpdateChapterPatchInput(
isBookmarked = Optional.presentIfNotNull(bookmarked),
isRead = Optional.presentIfNotNull(read),
lastPageRead = Optional.presentIfNotNull(lastPageRead)
lastPageRead = Optional.presentIfNotNull(lastPageRead),
),
)
),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun deleteDownloadedChapter(
chapterId: Long,
): Flow<Unit> {
return apolloClient.mutation(
override fun deleteDownloadedChapter(chapterId: Long): Flow<Unit> =
apolloClient.mutation(
DeleteDownloadedChapterMutation(
chapterId.toInt(),
)
),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun deleteDownloadedChapters(
chapterIds: List<Long>,
): Flow<Unit> {
return apolloClient.mutation(
override fun deleteDownloadedChapters(chapterIds: List<Long>): Flow<Unit> =
apolloClient.mutation(
DeleteDownloadedChaptersMutation(
chapterIds.map { it.toInt() },
)
),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun updateChapterMeta(
chapterId: Long,
key: String,
value: String,
): Flow<Unit> {
return apolloClient.mutation(
): Flow<Unit> =
apolloClient.mutation(
UpdateChapterMetaMutation(
chapterId.toInt(),
key,
value,
)
),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun fetchChapters(
mangaId: Long,
): Flow<List<Chapter>> {
return apolloClient.mutation(
override fun fetchChapters(mangaId: Long): Flow<List<Chapter>> =
apolloClient.mutation(
FetchChaptersMutation(
mangaId.toInt(),
)
),
)
.toFlow()
.map {
val chapters = it.dataAssertNoErrors
chapters.fetchChapters!!.chapters.map { it.chapterFragment.toChapter() }
}
}
override fun getPages(chapterId: Long): Flow<List<String>> {
return apolloClient.mutation(
override fun getPages(chapterId: Long): Flow<List<String>> =
apolloClient.mutation(
FetchChapterPagesMutation(
chapterId.toInt(),
)
),
)
.toFlow()
.map {
val chapters = it.dataAssertNoErrors
chapters.fetchChapterPages!!.pages
}
}
override fun getPage(
url: String,
@@ -182,10 +167,9 @@ class ChapterRepositoryImpl(
return flow { http.get(realUrl, block).readBytes() }
}
companion object {
internal fun ChapterFragment.toChapter(): Chapter {
return Chapter(
internal fun ChapterFragment.toChapter(): Chapter =
Chapter(
id = id.toLong(),
url = url,
name = name,
@@ -203,16 +187,14 @@ class ChapterRepositoryImpl(
lastReadAt = lastPageRead,
downloaded = isDownloaded,
meta = ChapterMeta(
juiPageOffset = meta.find { it.key == "juiPageOffset" }?.value?.toIntOrNull() ?: 0
)
juiPageOffset = meta.find { it.key == "juiPageOffset" }?.value?.toIntOrNull() ?: 0,
),
)
}
internal fun ChapterWithMangaFragment.toMangaAndChapter(): MangaAndChapter {
return MangaAndChapter(
internal fun ChapterWithMangaFragment.toMangaAndChapter(): MangaAndChapter =
MangaAndChapter(
manga.mangaFragment.toManga(),
chapterFragment.toChapter(),
)
}
}
}

View File

@@ -24,79 +24,70 @@ class DownloadRepositoryImpl(
private val apolloClient: ApolloClient,
private val http: Http,
private val serverUrl: Url,
): DownloadRepository {
override fun startDownloading(): Flow<Unit> {
return apolloClient.mutation(
StartDownloaderMutation()
) : DownloadRepository {
override fun startDownloading(): Flow<Unit> =
apolloClient.mutation(
StartDownloaderMutation(),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun stopDownloading(): Flow<Unit> {
return apolloClient.mutation(
StopDownloaderMutation()
override fun stopDownloading(): Flow<Unit> =
apolloClient.mutation(
StopDownloaderMutation(),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun clearDownloadQueue(): Flow<Unit> {
return apolloClient.mutation(
ClearDownloaderMutation()
override fun clearDownloadQueue(): Flow<Unit> =
apolloClient.mutation(
ClearDownloaderMutation(),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun queueChapterDownload(chapterId: Long): Flow<Unit> {
return apolloClient.mutation(
EnqueueChapterDownloadMutation(chapterId.toInt())
override fun queueChapterDownload(chapterId: Long): Flow<Unit> =
apolloClient.mutation(
EnqueueChapterDownloadMutation(chapterId.toInt()),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun stopChapterDownload(chapterId: Long): Flow<Unit> {
return apolloClient.mutation(
DequeueChapterDownloadMutation(chapterId.toInt())
override fun stopChapterDownload(chapterId: Long): Flow<Unit> =
apolloClient.mutation(
DequeueChapterDownloadMutation(chapterId.toInt()),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun reorderChapterDownload(
chapterId: Long,
to: Int,
): Flow<Unit> {
return apolloClient.mutation(
ReorderChapterDownloadMutation(chapterId.toInt(), to)
): Flow<Unit> =
apolloClient.mutation(
ReorderChapterDownloadMutation(chapterId.toInt(), to),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
override fun batchDownload(chapterIds: List<Long>): Flow<Unit> {
return apolloClient.mutation(
EnqueueChapterDownloadsMutation(chapterIds.map { it.toInt() })
override fun batchDownload(chapterIds: List<Long>): Flow<Unit> =
apolloClient.mutation(
EnqueueChapterDownloadsMutation(chapterIds.map { it.toInt() }),
)
.toFlow()
.map {
it.dataAssertNoErrors
}
}
}

View File

@@ -26,19 +26,18 @@ class ExtensionRepositoryImpl(
private val apolloClient: ApolloClient,
private val http: Http,
private val serverUrl: Url,
): ExtensionRepository {
override fun getExtensionList(): Flow<List<Extension>> {
return apolloClient.mutation(
FetchExtensionsMutation()
) : ExtensionRepository {
override fun getExtensionList(): Flow<List<Extension>> =
apolloClient.mutation(
FetchExtensionsMutation(),
)
.toFlow()
.map {
it.dataAssertNoErrors.fetchExtensions!!.extensions.map { it.extensionFragment.toExtension() }
}
}
override fun installExtension(source: Source): Flow<Unit> {
return apolloClient.mutation(
override fun installExtension(source: Source): Flow<Unit> =
apolloClient.mutation(
InstallExternalExtensionMutation(
DefaultUpload.Builder()
.content {
@@ -46,48 +45,44 @@ class ExtensionRepositoryImpl(
}
.fileName("extension.apk")
.contentType("application/octet-stream")
.build()
)
.build(),
),
)
.toFlow()
.map {
it.dataAssertNoErrors.installExternalExtension!!
}
}
override fun installExtension(pkgName: String): Flow<Unit> {
return apolloClient.mutation(
InstallExtensionMutation(pkgName)
override fun installExtension(pkgName: String): Flow<Unit> =
apolloClient.mutation(
InstallExtensionMutation(pkgName),
)
.toFlow()
.map {
it.dataAssertNoErrors.updateExtension
}
}
override fun updateExtension(pkgName: String): Flow<Unit> {
return apolloClient.mutation(
UpdateExtensionMutation(pkgName)
override fun updateExtension(pkgName: String): Flow<Unit> =
apolloClient.mutation(
UpdateExtensionMutation(pkgName),
)
.toFlow()
.map {
it.dataAssertNoErrors.updateExtension
}
}
override fun uninstallExtension(pkgName: String): Flow<Unit> {
return apolloClient.mutation(
UninstallExtensionMutation(pkgName)
override fun uninstallExtension(pkgName: String): Flow<Unit> =
apolloClient.mutation(
UninstallExtensionMutation(pkgName),
)
.toFlow()
.map {
it.dataAssertNoErrors.updateExtension
}
}
companion object {
internal fun ExtensionFragment.toExtension(): Extension {
return Extension(
internal fun ExtensionFragment.toExtension(): Extension =
Extension(
name = name,
pkgName = pkgName,
versionName = versionName,
@@ -100,6 +95,5 @@ class ExtensionRepositoryImpl(
obsolete = isObsolete,
isNsfw = isNsfw,
)
}
}
}

View File

@@ -20,28 +20,27 @@ class GlobalRepositoryImpl(
private val apolloClient: ApolloClient,
private val http: Http,
private val serverUrl: Url,
): GlobalRepository {
override fun getGlobalMeta(): Flow<GlobalMeta> {
return apolloClient.query(
GetGlobalMetaQuery()
) : GlobalRepository {
override fun getGlobalMeta(): Flow<GlobalMeta> =
apolloClient.query(
GetGlobalMetaQuery(),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
GlobalMeta(data.metas.nodes.find { it.key == "example" }?.value?.toIntOrNull() ?: 0)
}
}
override fun updateGlobalMeta(key: String, value: String): Flow<Unit> {
return apolloClient.mutation(
SetGlobalMetaMutation(key, value)
override fun updateGlobalMeta(
key: String,
value: String,
): Flow<Unit> =
apolloClient.mutation(
SetGlobalMetaMutation(key, value),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.setGlobalMeta!!.clientMutationId
}
}
}

View File

@@ -13,22 +13,20 @@ class LibraryRepositoryImpl(
private val http: Http,
private val serverUrl: Url,
) : LibraryRepository {
fun setMangaInLibrary(mangaId: Long, inLibrary: Boolean): Flow<Unit> {
return apolloClient.mutation(
SetMangaInLibraryMutation(mangaId.toInt(), inLibrary)
fun setMangaInLibrary(
mangaId: Long,
inLibrary: Boolean,
): Flow<Unit> =
apolloClient.mutation(
SetMangaInLibraryMutation(mangaId.toInt(), inLibrary),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateManga!!.clientMutationId
}
}
override fun addMangaToLibrary(mangaId: Long): Flow<Unit> {
return setMangaInLibrary(mangaId, true)
}
override fun addMangaToLibrary(mangaId: Long): Flow<Unit> = setMangaInLibrary(mangaId, true)
override fun removeMangaFromLibrary(mangaId: Long): Flow<Unit> {
return setMangaInLibrary(mangaId, false)
}
override fun removeMangaFromLibrary(mangaId: Long): Flow<Unit> = setMangaInLibrary(mangaId, false)
}

View File

@@ -30,71 +30,66 @@ class MangaRepositoryImpl(
private val http: Http,
private val serverUrl: Url,
) : MangaRepository {
override fun getManga(mangaId: Long): Flow<Manga> {
return apolloClient.query(
GetMangaQuery(mangaId.toInt())
override fun getManga(mangaId: Long): Flow<Manga> =
apolloClient.query(
GetMangaQuery(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.manga.mangaFragment.toManga()
}
}
override fun refreshManga(mangaId: Long): Flow<Manga> {
return apolloClient.mutation(
RefreshMangaMutation(mangaId.toInt())
override fun refreshManga(mangaId: Long): Flow<Manga> =
apolloClient.mutation(
RefreshMangaMutation(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.fetchManga!!.manga.mangaFragment.toManga()
}
}
override fun getMangaLibrary(mangaId: Long): Flow<Manga> {
return apolloClient.query(
GetMangaLibraryQuery(mangaId.toInt())
override fun getMangaLibrary(mangaId: Long): Flow<Manga> =
apolloClient.query(
GetMangaLibraryQuery(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.manga.libraryMangaFragment.toManga()
}
}
override fun getMangaThumbnail(
mangaId: Long,
block: HttpRequestBuilder.() -> Unit,
): Flow<ByteReadChannel> {
return apolloClient.query(
GetThumbnailUrlQuery(mangaId.toInt())
): Flow<ByteReadChannel> =
apolloClient.query(
GetThumbnailUrlQuery(mangaId.toInt()),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
http.get(data.manga.thumbnailUrl!!).bodyAsChannel()
}
}
override fun updateMangaMeta(
mangaId: Long,
key: String,
value: String,
): Flow<Unit> {
return apolloClient.mutation(
SetMangaMetaMutation(mangaId.toInt(), key, value)
): Flow<Unit> =
apolloClient.mutation(
SetMangaMetaMutation(mangaId.toInt(), key, value),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.setMangaMeta!!.clientMutationId
}
}
companion object {
internal fun MangaFragment.toManga(): Manga {
return Manga(
internal fun MangaFragment.toManga(): Manga =
Manga(
id = id.toLong(),
sourceId = sourceId,
url = url,
@@ -137,10 +132,9 @@ class MangaRepositoryImpl(
age = age,
chaptersAge = null,
)
}
internal fun LibraryMangaFragment.toManga(): Manga {
return Manga(
internal fun LibraryMangaFragment.toManga(): Manga =
Manga(
id = id.toLong(),
sourceId = sourceId,
url = url,
@@ -183,6 +177,5 @@ class MangaRepositoryImpl(
age = age,
chaptersAge = null,
)
}
}
}

View File

@@ -118,7 +118,6 @@ class SettingsRepositoryImpl(
webUIUpdateCheckInterval = webUIUpdateCheckInterval,
)
private fun AuthMode.toDomain() =
when (this) {
AuthMode.NONE -> DomainAuthMode.NONE
@@ -354,9 +353,9 @@ class SettingsRepositoryImpl(
}
.flowOn(Dispatchers.IO)
override fun aboutServer(): Flow<About> {
return apolloClient.query(
AboutServerQuery()
override fun aboutServer(): Flow<About> =
apolloClient.query(
AboutServerQuery(),
)
.toFlow()
.map {
@@ -370,9 +369,8 @@ class SettingsRepositoryImpl(
},
data.aboutServer.buildTime,
data.aboutServer.github,
data.aboutServer.discord
data.aboutServer.discord,
)
}
.flowOn(Dispatchers.IO)
}
}

View File

@@ -37,67 +37,61 @@ class SourceRepositoryImpl(
private val http: Http,
private val serverUrl: Url,
) : SourceRepository {
override fun getSourceList(): Flow<List<Source>> {
return apolloClient.query(
GetSourceListQuery()
override fun getSourceList(): Flow<List<Source>> =
apolloClient.query(
GetSourceListQuery(),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.sources.nodes.map { it.sourceFragment.toSource() }
}
}
override fun getSourceInfo(sourceId: Long): Flow<Source> {
return apolloClient.query(
GetSourceQuery(sourceId)
override fun getSourceInfo(sourceId: Long): Flow<Source> =
apolloClient.query(
GetSourceQuery(sourceId),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.source.sourceFragment.toSource()
}
}
override fun getPopularManga(
sourceId: Long,
pageNum: Int,
): Flow<MangaPage> {
return apolloClient.mutation(
FetchPopularMangaMutation(sourceId, pageNum)
): Flow<MangaPage> =
apolloClient.mutation(
FetchPopularMangaMutation(sourceId, pageNum),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
MangaPage(
data.fetchSourceManga!!.mangas.map { it.mangaFragment.toManga() },
data.fetchSourceManga.hasNextPage
data.fetchSourceManga.hasNextPage,
)
}
}
override fun getLatestManga(
sourceId: Long,
pageNum: Int,
): Flow<MangaPage> {
return apolloClient.mutation(
FetchLatestMangaMutation(sourceId, pageNum)
): Flow<MangaPage> =
apolloClient.mutation(
FetchLatestMangaMutation(sourceId, pageNum),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
MangaPage(
data.fetchSourceManga!!.mangas.map { it.mangaFragment.toManga() },
data.fetchSourceManga.hasNextPage
data.fetchSourceManga.hasNextPage,
)
}
}
override fun getFilterList(
sourceId: Long,
): Flow<List<SourceFilter>> {
return apolloClient.query(
GetSourceFiltersQuery(sourceId)
override fun getFilterList(sourceId: Long): Flow<List<SourceFilter>> =
apolloClient.query(
GetSourceFiltersQuery(sourceId),
)
.toFlow()
.map {
@@ -112,6 +106,7 @@ class SourceRepositoryImpl(
filter.checkBoxFilterDefault,
)
}
"HeaderFilter" -> {
val filter = filter.onHeaderFilter!!
SourceFilter.Header(
@@ -119,15 +114,17 @@ class SourceRepositoryImpl(
filter.name,
)
}
"SelectFilter" -> {
val filter = filter.onSelectFilter!!
SourceFilter.Select(
index,
filter.name,
filter.values,
filter.selectFilterDefault
filter.selectFilterDefault,
)
}
"TriStateFilter" -> {
val filter = filter.onTriStateFilter!!
SourceFilter.TriState(
@@ -141,6 +138,7 @@ class SourceRepositoryImpl(
},
)
}
"TextFilter" -> {
val filter = filter.onTextFilter!!
SourceFilter.Text(
@@ -149,6 +147,7 @@ class SourceRepositoryImpl(
filter.textFilterDefault,
)
}
"SortFilter" -> {
val filter = filter.onSortFilter!!
SourceFilter.Sort(
@@ -160,6 +159,7 @@ class SourceRepositoryImpl(
},
)
}
"SeparatorFilter" -> {
val filter = filter.onSeparatorFilter!!
SourceFilter.Separator(
@@ -167,6 +167,7 @@ class SourceRepositoryImpl(
filter.name,
)
}
"GroupFilter" -> {
SourceFilter.Group(
index,
@@ -181,6 +182,7 @@ class SourceRepositoryImpl(
filter.checkBoxFilterDefault,
)
}
"HeaderFilter" -> {
val filter = filter.onHeaderFilter!!
SourceFilter.Header(
@@ -188,15 +190,17 @@ class SourceRepositoryImpl(
filter.name,
)
}
"SelectFilter" -> {
val filter = filter.onSelectFilter!!
SourceFilter.Select(
index,
filter.name,
filter.values,
filter.selectFilterDefault
filter.selectFilterDefault,
)
}
"TriStateFilter" -> {
val filter = filter.onTriStateFilter!!
SourceFilter.TriState(
@@ -210,6 +214,7 @@ class SourceRepositoryImpl(
},
)
}
"TextFilter" -> {
val filter = filter.onTextFilter!!
SourceFilter.Text(
@@ -218,6 +223,7 @@ class SourceRepositoryImpl(
filter.textFilterDefault,
)
}
"SortFilter" -> {
val filter = filter.onSortFilter!!
SourceFilter.Sort(
@@ -229,6 +235,7 @@ class SourceRepositoryImpl(
},
)
}
"SeparatorFilter" -> {
val filter = filter.onSeparatorFilter!!
SourceFilter.Separator(
@@ -236,16 +243,17 @@ class SourceRepositoryImpl(
filter.name,
)
}
else -> SourceFilter.Header(index, "")
}
}
},
)
}
else -> SourceFilter.Header(index, "")
}
}
}
}
fun SourceFilter.toFilterChange(): List<FilterChangeInput>? {
return when (this) {
@@ -254,28 +262,34 @@ class SourceRepositoryImpl(
} else {
null
}
is SourceFilter.Header -> null
is SourceFilter.Select -> if (value != default) {
listOf(FilterChangeInput(position = position, selectState = value.toOptional()))
} else {
null
}
is SourceFilter.Separator -> null
is SourceFilter.Sort -> if (value != default) {
listOf(
FilterChangeInput(
position = position,
sortState = value?.let { SortSelectionInput(it.ascending, it.index) }.toOptional()
)
sortState = value?.let { SortSelectionInput(it.ascending, it.index) }.toOptional(),
),
)
} else {
null
}
is SourceFilter.Text -> if (value != default) {
listOf(FilterChangeInput(position = position, textState = value.toOptional()))
} else {
null
}
is SourceFilter.TriState -> if (value != default) {
listOf(
FilterChangeInput(
@@ -285,29 +299,31 @@ class SourceRepositoryImpl(
TriStateValue.INCLUDE -> TriState.INCLUDE
TriStateValue.EXCLUDE -> TriState.EXCLUDE
}.toOptional(),
)
),
)
} else {
null
}
is SourceFilter.Group -> value.mapNotNull {
FilterChangeInput(
position = position,
groupChange = it.toFilterChange()
?.firstOrNull()
?.toOptional()
?: return@mapNotNull null
?: return@mapNotNull null,
)
}
}
}
override fun getSearchResults(
sourceId: Long,
pageNum: Int,
searchTerm: String?,
filters: List<SourceFilter>?,
): Flow<MangaPage> {
return apolloClient.mutation(
): Flow<MangaPage> =
apolloClient.mutation(
FetchSearchMangaMutation(
sourceId,
pageNum,
@@ -322,14 +338,13 @@ class SourceRepositoryImpl(
val data = it.dataAssertNoErrors
MangaPage(
data.fetchSourceManga!!.mangas.map { it.mangaFragment.toManga() },
data.fetchSourceManga.hasNextPage
data.fetchSourceManga.hasNextPage,
)
}
}
override fun getSourceSettings(sourceId: Long): Flow<List<SourcePreference>> {
return apolloClient.query(
GetSourcePreferencesQuery(sourceId)
override fun getSourceSettings(sourceId: Long): Flow<List<SourcePreference>> =
apolloClient.query(
GetSourcePreferencesQuery(sourceId),
)
.toFlow()
.map {
@@ -349,6 +364,7 @@ class SourceRepositoryImpl(
default = it.checkBoxDefault,
)
}
"EditTextPreference" -> preference.onEditTextPreference!!.let {
EditTextSourcePreference(
position = index,
@@ -364,6 +380,7 @@ class SourceRepositoryImpl(
text = it.text,
)
}
"SwitchPreference" -> preference.onSwitchPreference!!.let {
SwitchSourcePreference(
position = index,
@@ -376,6 +393,7 @@ class SourceRepositoryImpl(
default = it.switchPreferenceDefault,
)
}
"MultiSelectListPreference" -> preference.onMultiSelectListPreference!!.let {
MultiSelectListSourcePreference(
position = index,
@@ -389,9 +407,10 @@ class SourceRepositoryImpl(
dialogTitle = it.dialogTitle,
dialogMessage = it.dialogMessage,
entries = it.entries,
entryValues = it.entryValues
entryValues = it.entryValues,
)
}
"ListPreference" -> preference.onListPreference!!.let {
ListSourcePreference(
position = index,
@@ -403,20 +422,20 @@ class SourceRepositoryImpl(
currentValue = it.listPreferenceCurrentValue,
default = it.listPreferenceDefault,
entries = it.entries,
entryValues = it.entryValues
entryValues = it.entryValues,
)
}
else -> null
}
}
}
}
override fun setSourceSetting(
sourceId: Long,
sourcePreference: SourcePreference,
): Flow<Unit> {
return apolloClient.mutation(
): Flow<Unit> =
apolloClient.mutation(
SetSourceSettingMutation(
sourceId,
SourcePreferenceChangeInput(
@@ -426,18 +445,17 @@ class SourceRepositoryImpl(
editTextState = (sourcePreference as? EditTextSourcePreference)?.currentValue.toOptional(),
multiSelectState = (sourcePreference as? MultiSelectListSourcePreference)?.currentValue.toOptional(),
listState = (sourcePreference as? ListSourcePreference)?.currentValue.toOptional(),
)
)
),
),
)
.toFlow()
.map {
it.dataAssertNoErrors.updateSourcePreference!!.clientMutationId
}
}
companion object {
internal fun SourceFragment.toSource(): Source {
return Source(
internal fun SourceFragment.toSource(): Source =
Source(
id,
name,
lang,
@@ -445,8 +463,7 @@ class SourceRepositoryImpl(
supportsLatest,
isConfigurable,
isNsfw,
displayName
displayName,
)
}
}
}

View File

@@ -22,42 +22,37 @@ class UpdatesRepositoryImpl(
private val apolloClient: ApolloClient,
private val http: Http,
private val serverUrl: Url,
): UpdatesRepository {
override fun getRecentUpdates(pageNum: Int): Flow<Updates> {
return apolloClient.query(
GetChapterUpdatesQuery(50, pageNum * 50)
) : UpdatesRepository {
override fun getRecentUpdates(pageNum: Int): Flow<Updates> =
apolloClient.query(
GetChapterUpdatesQuery(50, pageNum * 50),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
Updates(
data.chapters.nodes.map { it.chapterWithMangaFragment.toMangaAndChapter() },
data.chapters.pageInfo.hasNextPage
data.chapters.pageInfo.hasNextPage,
)
}
}
override fun updateLibrary(): Flow<Unit> {
return apolloClient.mutation(
UpdateLibraryMutation()
override fun updateLibrary(): Flow<Unit> =
apolloClient.mutation(
UpdateLibraryMutation(),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateLibraryManga!!.clientMutationId
}
}
override fun updateCategory(categoryId: Long): Flow<Unit> {
return apolloClient.mutation(
UpdateCategoryMutation(listOf(categoryId.toInt()))
override fun updateCategory(categoryId: Long): Flow<Unit> =
apolloClient.mutation(
UpdateCategoryMutation(listOf(categoryId.toInt())),
)
.toFlow()
.map {
val data = it.dataAssertNoErrors
data.updateCategoryManga!!.clientMutationId
}
}
}

View File

@@ -1,5 +1,3 @@
package ca.gosyer.jui.data
actual interface SharedDataComponent {
}
actual interface SharedDataComponent

View File

@@ -1,5 +1,3 @@
package ca.gosyer.jui.data
actual interface SharedDataComponent {
}
actual interface SharedDataComponent

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,

View File

@@ -25,7 +25,6 @@ import cafe.adriel.voyager.navigator.currentOrThrow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.merge
import org.lighthousegames.logging.logging
private fun SourceFiltersView<*, *>.toSourceFilter(): SourceFilter {
return when (this) {
@@ -40,8 +39,6 @@ private fun SourceFiltersView<*, *>.toSourceFilter(): SourceFilter {
}
}
val logs = logging()
class SourceScreen(
val source: Source,
private val initialQuery: String? = null,