From 331acb966abe865ea518657edc87c1c825ad2e4a Mon Sep 17 00:00:00 2001 From: Syer10 Date: Fri, 3 Oct 2025 21:00:20 -0400 Subject: [PATCH] Fixes for Manga page with GraphQL --- .../ca/gosyer/jui/data/SharedDataComponent.kt | 46 ---------- data/src/commonMain/graphql/Setting.graphql | 11 +++ .../data/settings/SettingsRepositoryImpl.kt | 25 +++++ .../ca/gosyer/jui/data/SharedDataComponent.kt | 45 --------- .../ca/gosyer/jui/data/SharedDataComponent.kt | 45 --------- .../ca/gosyer/jui/domain/ServerListeners.kt | 21 +++-- .../backup/service/BackupRepositoryOld.kt | 61 ------------ .../category/service/CategoryRepositoryOld.kt | 79 ---------------- .../domain/chapter/interactor/GetChapter.kt | 4 +- .../domain/chapter/interactor/GetChapters.kt | 4 +- .../chapter/service/ChapterRepositoryOld.kt | 86 ----------------- .../download/service/DownloadRepositoryOld.kt | 54 ----------- .../service/ExtensionRepositoryOld.kt | 73 --------------- .../global/service/GlobalRepositoryOld.kt | 27 ------ .../library/service/LibraryRepositoryOld.kt | 25 ----- .../manga/service/MangaRepositoryOld.kt | 48 ---------- .../domain/settings/interactor/AboutServer.kt | 6 +- .../domain/settings/interactor/CheckUpdate.kt | 33 ------- .../gosyer/jui/domain/settings/model/About.kt | 1 - .../settings/service/SettingsRepository.kt | 3 + .../settings/service/SettingsRepositoryOld.kt | 21 ----- .../source/service/SourceRepositoryOld.kt | 92 ------------------- .../updates/service/UpdatesRepositoryOld.kt | 32 ------- .../ui/main/about/components/AboutContent.kt | 2 +- .../jui/ui/manga/MangaScreenViewModel.kt | 61 ++++++------ 25 files changed, 97 insertions(+), 808 deletions(-) delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/service/BackupRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/service/CategoryRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/service/ChapterRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/service/GlobalRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/manga/service/MangaRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/SourceRepositoryOld.kt delete mode 100644 domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatesRepositoryOld.kt diff --git a/data/src/androidMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt b/data/src/androidMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt index 685917a2..ee01e816 100644 --- a/data/src/androidMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt +++ b/data/src/androidMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt @@ -1,50 +1,4 @@ package ca.gosyer.jui.data -import ca.gosyer.jui.domain.backup.service.createBackupRepositoryOld -import ca.gosyer.jui.domain.category.service.createCategoryRepositoryOld -import ca.gosyer.jui.domain.chapter.service.createChapterRepositoryOld -import ca.gosyer.jui.domain.download.service.createDownloadRepositoryOld -import ca.gosyer.jui.domain.extension.service.createExtensionRepositoryOld -import ca.gosyer.jui.domain.global.service.createGlobalRepositoryOld -import ca.gosyer.jui.domain.library.service.createLibraryRepositoryOld -import ca.gosyer.jui.domain.manga.service.createMangaRepositoryOld -import ca.gosyer.jui.domain.settings.service.createSettingsRepositoryOld -import ca.gosyer.jui.domain.source.service.createSourceRepositoryOld -import ca.gosyer.jui.domain.updates.service.createUpdatesRepositoryOld -import de.jensklingenberg.ktorfit.Ktorfit -import me.tatarka.inject.annotations.Provides - actual interface SharedDataComponent { - @Provides - fun backupRepositoryOld(ktorfit: Ktorfit) = ktorfit.createBackupRepositoryOld() - - @Provides - fun categoryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createCategoryRepositoryOld() - - @Provides - fun chapterRepositoryOld(ktorfit: Ktorfit) = ktorfit.createChapterRepositoryOld() - - @Provides - fun downloadRepositoryOld(ktorfit: Ktorfit) = ktorfit.createDownloadRepositoryOld() - - @Provides - fun extensionRepositoryOld(ktorfit: Ktorfit) = ktorfit.createExtensionRepositoryOld() - - @Provides - fun globalRepositoryOld(ktorfit: Ktorfit) = ktorfit.createGlobalRepositoryOld() - - @Provides - fun libraryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createLibraryRepositoryOld() - - @Provides - fun mangaRepositoryOld(ktorfit: Ktorfit) = ktorfit.createMangaRepositoryOld() - - @Provides - fun settingsRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSettingsRepositoryOld() - - @Provides - fun sourceRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSourceRepositoryOld() - - @Provides - fun updatesRepositoryOld(ktorfit: Ktorfit) = ktorfit.createUpdatesRepositoryOld() } diff --git a/data/src/commonMain/graphql/Setting.graphql b/data/src/commonMain/graphql/Setting.graphql index 12202305..5bb4ebdd 100644 --- a/data/src/commonMain/graphql/Setting.graphql +++ b/data/src/commonMain/graphql/Setting.graphql @@ -229,3 +229,14 @@ mutation SetSettings( clientMutationId } } + +query AboutServer { + aboutServer { + buildTime + buildType + discord + github + name + version + } +} diff --git a/data/src/commonMain/kotlin/ca/gosyer/jui/data/settings/SettingsRepositoryImpl.kt b/data/src/commonMain/kotlin/ca/gosyer/jui/data/settings/SettingsRepositoryImpl.kt index 3ab6ce5e..3a47167c 100644 --- a/data/src/commonMain/kotlin/ca/gosyer/jui/data/settings/SettingsRepositoryImpl.kt +++ b/data/src/commonMain/kotlin/ca/gosyer/jui/data/settings/SettingsRepositoryImpl.kt @@ -6,6 +6,7 @@ package ca.gosyer.jui.data.settings +import ca.gosyer.jui.data.graphql.AboutServerQuery import ca.gosyer.jui.data.graphql.AllSettingsQuery import ca.gosyer.jui.data.graphql.SetSettingsMutation import ca.gosyer.jui.data.graphql.fragment.SettingsTypeFragment @@ -20,6 +21,8 @@ import ca.gosyer.jui.data.graphql.type.WebUIChannel import ca.gosyer.jui.data.graphql.type.WebUIFlavor import ca.gosyer.jui.data.graphql.type.WebUIInterface import ca.gosyer.jui.data.util.toOptional +import ca.gosyer.jui.domain.settings.model.About +import ca.gosyer.jui.domain.settings.model.AboutBuildType import ca.gosyer.jui.domain.settings.model.SetSettingsInput import ca.gosyer.jui.domain.settings.model.Settings import ca.gosyer.jui.domain.settings.service.SettingsRepository @@ -350,4 +353,26 @@ class SettingsRepositoryImpl( Unit } .flowOn(Dispatchers.IO) + + override fun aboutServer(): Flow { + return apolloClient.query( + AboutServerQuery() + ) + .toFlow() + .map { + val data = it.dataAssertNoErrors + About( + data.aboutServer.name, + data.aboutServer.version, + when (data.aboutServer.buildType) { + "Preview" -> AboutBuildType.Preview + else -> AboutBuildType.Stable + }, + data.aboutServer.buildTime, + data.aboutServer.github, + data.aboutServer.discord + ) + } + .flowOn(Dispatchers.IO) + } } diff --git a/data/src/desktopMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt b/data/src/desktopMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt index 685917a2..cb98f575 100644 --- a/data/src/desktopMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt +++ b/data/src/desktopMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt @@ -1,50 +1,5 @@ package ca.gosyer.jui.data -import ca.gosyer.jui.domain.backup.service.createBackupRepositoryOld -import ca.gosyer.jui.domain.category.service.createCategoryRepositoryOld -import ca.gosyer.jui.domain.chapter.service.createChapterRepositoryOld -import ca.gosyer.jui.domain.download.service.createDownloadRepositoryOld -import ca.gosyer.jui.domain.extension.service.createExtensionRepositoryOld -import ca.gosyer.jui.domain.global.service.createGlobalRepositoryOld -import ca.gosyer.jui.domain.library.service.createLibraryRepositoryOld -import ca.gosyer.jui.domain.manga.service.createMangaRepositoryOld -import ca.gosyer.jui.domain.settings.service.createSettingsRepositoryOld -import ca.gosyer.jui.domain.source.service.createSourceRepositoryOld -import ca.gosyer.jui.domain.updates.service.createUpdatesRepositoryOld -import de.jensklingenberg.ktorfit.Ktorfit -import me.tatarka.inject.annotations.Provides - actual interface SharedDataComponent { - @Provides - fun backupRepositoryOld(ktorfit: Ktorfit) = ktorfit.createBackupRepositoryOld() - @Provides - fun categoryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createCategoryRepositoryOld() - - @Provides - fun chapterRepositoryOld(ktorfit: Ktorfit) = ktorfit.createChapterRepositoryOld() - - @Provides - fun downloadRepositoryOld(ktorfit: Ktorfit) = ktorfit.createDownloadRepositoryOld() - - @Provides - fun extensionRepositoryOld(ktorfit: Ktorfit) = ktorfit.createExtensionRepositoryOld() - - @Provides - fun globalRepositoryOld(ktorfit: Ktorfit) = ktorfit.createGlobalRepositoryOld() - - @Provides - fun libraryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createLibraryRepositoryOld() - - @Provides - fun mangaRepositoryOld(ktorfit: Ktorfit) = ktorfit.createMangaRepositoryOld() - - @Provides - fun settingsRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSettingsRepositoryOld() - - @Provides - fun sourceRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSourceRepositoryOld() - - @Provides - fun updatesRepositoryOld(ktorfit: Ktorfit) = ktorfit.createUpdatesRepositoryOld() } diff --git a/data/src/iosMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt b/data/src/iosMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt index 685917a2..cb98f575 100644 --- a/data/src/iosMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt +++ b/data/src/iosMain/kotlin/ca/gosyer/jui/data/SharedDataComponent.kt @@ -1,50 +1,5 @@ package ca.gosyer.jui.data -import ca.gosyer.jui.domain.backup.service.createBackupRepositoryOld -import ca.gosyer.jui.domain.category.service.createCategoryRepositoryOld -import ca.gosyer.jui.domain.chapter.service.createChapterRepositoryOld -import ca.gosyer.jui.domain.download.service.createDownloadRepositoryOld -import ca.gosyer.jui.domain.extension.service.createExtensionRepositoryOld -import ca.gosyer.jui.domain.global.service.createGlobalRepositoryOld -import ca.gosyer.jui.domain.library.service.createLibraryRepositoryOld -import ca.gosyer.jui.domain.manga.service.createMangaRepositoryOld -import ca.gosyer.jui.domain.settings.service.createSettingsRepositoryOld -import ca.gosyer.jui.domain.source.service.createSourceRepositoryOld -import ca.gosyer.jui.domain.updates.service.createUpdatesRepositoryOld -import de.jensklingenberg.ktorfit.Ktorfit -import me.tatarka.inject.annotations.Provides - actual interface SharedDataComponent { - @Provides - fun backupRepositoryOld(ktorfit: Ktorfit) = ktorfit.createBackupRepositoryOld() - @Provides - fun categoryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createCategoryRepositoryOld() - - @Provides - fun chapterRepositoryOld(ktorfit: Ktorfit) = ktorfit.createChapterRepositoryOld() - - @Provides - fun downloadRepositoryOld(ktorfit: Ktorfit) = ktorfit.createDownloadRepositoryOld() - - @Provides - fun extensionRepositoryOld(ktorfit: Ktorfit) = ktorfit.createExtensionRepositoryOld() - - @Provides - fun globalRepositoryOld(ktorfit: Ktorfit) = ktorfit.createGlobalRepositoryOld() - - @Provides - fun libraryRepositoryOld(ktorfit: Ktorfit) = ktorfit.createLibraryRepositoryOld() - - @Provides - fun mangaRepositoryOld(ktorfit: Ktorfit) = ktorfit.createMangaRepositoryOld() - - @Provides - fun settingsRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSettingsRepositoryOld() - - @Provides - fun sourceRepositoryOld(ktorfit: Ktorfit) = ktorfit.createSourceRepositoryOld() - - @Provides - fun updatesRepositoryOld(ktorfit: Ktorfit) = ktorfit.createUpdatesRepositoryOld() } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ServerListeners.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ServerListeners.kt index 0a0cbbfe..29eaa6ab 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ServerListeners.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/ServerListeners.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.buffer +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.onStart @@ -39,6 +40,11 @@ class ServerListeners ) val chapterIdsListener = _chapterIdsListener.asSharedFlow() + private val _mangaChapterIdsListener = MutableSharedFlow>( + extraBufferCapacity = Channel.UNLIMITED, + ) + val mangaChapterIdsListener = _mangaChapterIdsListener.asSharedFlow() + private val categoryMangaListener = MutableSharedFlow( extraBufferCapacity = Channel.UNLIMITED, ) @@ -85,13 +91,16 @@ class ServerListeners fun combineChapters( flow: Flow, - idPredate: (suspend (List) -> Boolean)? = null, + chapterIdPredate: (suspend (List) -> Boolean)? = null, + mangaIdPredate: (suspend (List) -> Boolean)? = null, ): Flow { - val idsListener = if (idPredate != null) { - _chapterIdsListener.filter { idPredate(it) }.startWith(Unit) - } else { - _chapterIdsListener.startWith(Unit) - } + val idsListener = _chapterIdsListener + .filter { chapterIdPredate?.invoke(it) ?: false } + .startWith(Unit) + .combine( + _mangaChapterIdsListener.filter { mangaIdPredate?.invoke(it) ?: false } + .startWith(Unit) + ) { _, _ -> } return idsListener .buffer(capacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/service/BackupRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/service/BackupRepositoryOld.kt deleted file mode 100644 index af1c076c..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/backup/service/BackupRepositoryOld.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.backup.service - -import ca.gosyer.jui.core.io.SYSTEM -import ca.gosyer.jui.domain.backup.model.BackupValidationResult -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Multipart -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Part -import de.jensklingenberg.ktorfit.http.ReqBuilder -import io.ktor.client.request.HttpRequestBuilder -import io.ktor.client.request.forms.formData -import io.ktor.client.statement.HttpResponse -import io.ktor.http.ContentType -import io.ktor.http.Headers -import io.ktor.http.HttpHeaders -import io.ktor.http.content.PartData -import kotlinx.coroutines.flow.Flow -import okio.FileSystem -import okio.Path -import okio.buffer - -interface BackupRepositoryOld { - @Multipart - @POST("api/v1/backup/import/file") - fun importBackupFile( - @Part("") formData: List, - @ReqBuilder block: HttpRequestBuilder.() -> Unit = {}, - ): Flow - - @Multipart - @POST("api/v1/backup/validate/file") - fun validateBackupFile( - @Part("") formData: List, - @ReqBuilder block: HttpRequestBuilder.() -> Unit = {}, - ): Flow - - @GET("api/v1/backup/export/file") - fun exportBackupFile( - @ReqBuilder block: HttpRequestBuilder.() -> Unit = {}, - ): Flow - - companion object { - fun buildBackupFormData(file: Path) = - formData { - append( - "backup.proto.gz", - FileSystem.SYSTEM.source(file).buffer().readByteArray(), - Headers.build { - append(HttpHeaders.ContentType, ContentType.MultiPart.FormData.toString()) - append(HttpHeaders.ContentDisposition, "filename=backup.proto.gz") - }, - ) - } - } -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/service/CategoryRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/service/CategoryRepositoryOld.kt deleted file mode 100644 index e822372a..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/category/service/CategoryRepositoryOld.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.category.service - -import ca.gosyer.jui.domain.category.model.Category -import ca.gosyer.jui.domain.manga.model.Manga -import de.jensklingenberg.ktorfit.http.DELETE -import de.jensklingenberg.ktorfit.http.Field -import de.jensklingenberg.ktorfit.http.FormUrlEncoded -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.PATCH -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Path -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface CategoryRepositoryOld { - @GET("api/v1/manga/{mangaId}/category/") - fun getMangaCategories( - @Path("mangaId") mangaId: Long, - ): Flow> - - @GET("api/v1/manga/{mangaId}/category/{categoryId}") - fun addMangaToCategory( - @Path("mangaId") mangaId: Long, - @Path("categoryId") categoryId: Long, - ): Flow - - @DELETE("api/v1/manga/{mangaId}/category/{categoryId}") - fun removeMangaFromCategory( - @Path("mangaId") mangaId: Long, - @Path("categoryId") categoryId: Long, - ): Flow - - @GET("api/v1/category/") - fun getCategories(): Flow> - - @FormUrlEncoded - @POST("api/v1/category/") - fun createCategory( - @Field("name") name: String, - ): Flow - - @FormUrlEncoded - @PATCH("api/v1/category/{categoryId}") - fun modifyCategory( - @Path("categoryId") categoryId: Long, - @Field("name") name: String, - ): Flow - - @FormUrlEncoded - @PATCH("api/v1/category/reorder") - fun reorderCategory( - @Field("to") to: Int, - @Field("from") from: Int, - ): Flow - - @DELETE("api/v1/category/{categoryId}") - fun deleteCategory( - @Path("categoryId") categoryId: Long, - ): Flow - - @GET("api/v1/category/{categoryId}") - fun getMangaFromCategory( - @Path("categoryId") categoryId: Long, - ): Flow> - - @FormUrlEncoded - @PATCH("api/v1/category/{categoryId}/meta") - fun updateCategoryMeta( - @Path("categoryId") categoryId: Long, - @Field("key") key: String, - @Field("value") value: String, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapter.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapter.kt index e14f3a53..3023dff2 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapter.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapter.kt @@ -47,13 +47,13 @@ class GetChapter chapterId: Long, ) = serverListeners.combineChapters( chapterRepository.getChapter(chapterId), - idPredate = { ids -> chapterId in ids }, + chapterIdPredate = { ids -> chapterId in ids }, ) fun asFlow(chapter: Chapter) = serverListeners.combineChapters( chapterRepository.getChapter(chapter.id), - idPredate = { ids -> chapter.id in ids }, + chapterIdPredate = { ids -> chapter.id in ids }, ) companion object { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapters.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapters.kt index 4d7a5cc3..b0987526 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapters.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/interactor/GetChapters.kt @@ -46,13 +46,13 @@ class GetChapters fun asFlow(mangaId: Long) = serverListeners.combineChapters( chapterRepository.getChapters(mangaId), - idPredate = { ids -> false }, // todo + chapterIdPredate = { ids -> false }, // todo ) fun asFlow(manga: Manga) = serverListeners.combineChapters( chapterRepository.getChapters(manga.id), - idPredate = { ids -> false }, // todo + chapterIdPredate = { ids -> false }, // todo ) companion object { diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/service/ChapterRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/service/ChapterRepositoryOld.kt deleted file mode 100644 index ed6a2ff0..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/chapter/service/ChapterRepositoryOld.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.chapter.service - -import ca.gosyer.jui.domain.chapter.model.Chapter -import ca.gosyer.jui.domain.chapter.model.ChapterBatchEditInput -import ca.gosyer.jui.domain.chapter.model.MangaChapterBatchEditInput -import de.jensklingenberg.ktorfit.http.Body -import de.jensklingenberg.ktorfit.http.DELETE -import de.jensklingenberg.ktorfit.http.Field -import de.jensklingenberg.ktorfit.http.FormUrlEncoded -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Headers -import de.jensklingenberg.ktorfit.http.PATCH -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Path -import de.jensklingenberg.ktorfit.http.Query -import de.jensklingenberg.ktorfit.http.ReqBuilder -import io.ktor.client.request.HttpRequestBuilder -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface ChapterRepositoryOld { - @GET("api/v1/manga/{mangaId}/chapters") - fun getChapters( - @Path("mangaId") mangaId: Long, - @Query("onlineFetch") refresh: Boolean = false, - ): Flow> - - @GET("api/v1/manga/{mangaId}/chapter/{chapterIndex}") - fun getChapter( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - ): Flow - - @FormUrlEncoded - @PATCH("api/v1/manga/{mangaId}/chapter/{chapterIndex}") - fun updateChapter( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - @Field("read") read: Boolean? = null, - @Field("bookmarked") bookmarked: Boolean? = null, - @Field("lastPageRead") lastPageRead: Int? = null, - @Field("markPrevRead") markPreviousRead: Boolean? = null, - ): Flow - - @POST("api/v1/manga/{mangaId}/chapter/batch") - @Headers("Content-Type: application/json") - fun batchUpdateChapter( - @Path("mangaId") mangaId: Long, - @Body input: MangaChapterBatchEditInput, - ): Flow - - @POST("api/v1/chapter/batch") - @Headers("Content-Type: application/json") - fun batchUpdateChapter( - @Body input: ChapterBatchEditInput, - ): Flow - - @GET("api/v1/manga/{mangaId}/chapter/{chapterIndex}/page/{pageNum}") - fun getPage( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - @Path("pageNum") pageNum: Int, - @ReqBuilder block: HttpRequestBuilder.() -> Unit, - ): Flow - - @DELETE("api/v1/manga/{mangaId}/chapter/{chapterIndex}") - fun deleteChapterDownload( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - ): Flow - - @FormUrlEncoded - @PATCH("api/v1/manga/{mangaId}/chapter/{chapterIndex}/meta") - fun updateChapterMeta( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - @Field("key") key: String, - @Field("value") value: String, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadRepositoryOld.kt deleted file mode 100644 index 7c276daa..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/download/service/DownloadRepositoryOld.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.download.service - -import ca.gosyer.jui.domain.download.model.DownloadEnqueue -import de.jensklingenberg.ktorfit.http.Body -import de.jensklingenberg.ktorfit.http.DELETE -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Headers -import de.jensklingenberg.ktorfit.http.PATCH -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Path -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface DownloadRepositoryOld { - @GET("api/v1/downloads/start") - fun startDownloading(): Flow - - @GET("api/v1/downloads/stop") - fun stopDownloading(): Flow - - @GET("api/v1/downloads/clear") - fun clearDownloadQueue(): Flow - - @GET("api/v1/download/{mangaId}/chapter/{chapterIndex}") - fun queueChapterDownload( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - ): Flow - - @DELETE("api/v1/download/{mangaId}/chapter/{chapterIndex}") - fun stopChapterDownload( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - ): Flow - - @PATCH("api/v1/download/{mangaId}/chapter/{chapterIndex}/reorder/{to}") - fun reorderChapterDownload( - @Path("mangaId") mangaId: Long, - @Path("chapterIndex") chapterIndex: Int, - @Path("to") to: Int, - ): Flow - - @POST("api/v1/download/batch") - @Headers("Content-Type: application/json") - fun batchDownload( - @Body downloadEnqueue: DownloadEnqueue, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionRepositoryOld.kt deleted file mode 100644 index bf7a8690..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/extension/service/ExtensionRepositoryOld.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.extension.service - -import ca.gosyer.jui.core.io.SYSTEM -import ca.gosyer.jui.domain.extension.model.Extension -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Multipart -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Part -import de.jensklingenberg.ktorfit.http.Path -import de.jensklingenberg.ktorfit.http.ReqBuilder -import io.ktor.client.request.HttpRequestBuilder -import io.ktor.client.request.forms.formData -import io.ktor.client.statement.HttpResponse -import io.ktor.http.ContentType -import io.ktor.http.Headers -import io.ktor.http.HttpHeaders -import io.ktor.http.content.PartData -import io.ktor.utils.io.ByteReadChannel -import kotlinx.coroutines.flow.Flow -import okio.FileSystem -import okio.buffer - -interface ExtensionRepositoryOld { - @GET("api/v1/extension/list") - fun getExtensionList(): Flow> - - @Multipart - @POST("api/v1/extension/install") - fun installExtension( - @Part("") formData: List, - ): Flow - - @GET("api/v1/extension/install/{pkgName}") - fun installExtension( - @Path("pkgName") pkgName: String, - ): Flow - - @GET("api/v1/extension/update/{pkgName}") - fun updateExtension( - @Path("pkgName") pkgName: String, - ): Flow - - @GET("api/v1/extension/uninstall/{pkgName}") - fun uninstallExtension( - @Path("pkgName") pkgName: String, - ): Flow - - @GET("api/v1/extension/icon/{apkName}") - fun getApkIcon( - @Path("apkName") apkName: String, - @ReqBuilder block: HttpRequestBuilder.() -> Unit, - ): Flow - - companion object { - fun buildExtensionFormData(file: okio.Path) = - formData { - append( - "file", - FileSystem.SYSTEM.source(file).buffer().readByteArray(), - Headers.build { - append(HttpHeaders.ContentType, ContentType.MultiPart.FormData.toString()) - append(HttpHeaders.ContentDisposition, "filename=file") - }, - ) - } - } -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/service/GlobalRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/service/GlobalRepositoryOld.kt deleted file mode 100644 index 85a30fe6..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/global/service/GlobalRepositoryOld.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.global.service - -import ca.gosyer.jui.domain.global.model.GlobalMeta -import de.jensklingenberg.ktorfit.http.Field -import de.jensklingenberg.ktorfit.http.FormUrlEncoded -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.PATCH -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface GlobalRepositoryOld { - @GET("api/v1/meta") - fun getGlobalMeta(): Flow - - @FormUrlEncoded - @PATCH("api/v1/meta") - fun updateGlobalMeta( - @Field("key") key: String, - @Field("value") value: String, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryRepositoryOld.kt deleted file mode 100644 index e134df04..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/library/service/LibraryRepositoryOld.kt +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.library.service - -import de.jensklingenberg.ktorfit.http.DELETE -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Path -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface LibraryRepositoryOld { - @GET("api/v1/manga/{mangaId}/library") - fun addMangaToLibrary( - @Path("mangaId") mangaId: Long, - ): Flow - - @DELETE("api/v1/manga/{mangaId}/library") - fun removeMangaFromLibrary( - @Path("mangaId") mangaId: Long, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/manga/service/MangaRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/manga/service/MangaRepositoryOld.kt deleted file mode 100644 index b869e233..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/manga/service/MangaRepositoryOld.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.manga.service - -import ca.gosyer.jui.domain.manga.model.Manga -import de.jensklingenberg.ktorfit.http.Field -import de.jensklingenberg.ktorfit.http.FormUrlEncoded -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.PATCH -import de.jensklingenberg.ktorfit.http.Path -import de.jensklingenberg.ktorfit.http.Query -import de.jensklingenberg.ktorfit.http.ReqBuilder -import io.ktor.client.request.HttpRequestBuilder -import io.ktor.client.statement.HttpResponse -import io.ktor.utils.io.ByteReadChannel -import kotlinx.coroutines.flow.Flow - -interface MangaRepositoryOld { - @GET("api/v1/manga/{mangaId}/") - fun getManga( - @Path("mangaId") mangaId: Long, - @Query("onlineFetch") refresh: Boolean = false, - ): Flow - - @GET("api/v1/manga/{mangaId}/full") - fun getMangaFull( - @Path("mangaId") mangaId: Long, - @Query("onlineFetch") refresh: Boolean = false, - ): Flow - - @GET("api/v1/manga/{mangaId}/thumbnail") - fun getMangaThumbnail( - @Path("mangaId") mangaId: Long, - @ReqBuilder block: HttpRequestBuilder.() -> Unit, - ): Flow - - @PATCH("api/v1/manga/{mangaId}/meta") - @FormUrlEncoded - fun updateMangaMeta( - @Path("mangaId") mangaId: Long, - @Field("key") key: String, - @Field("value") value: String, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt index 1d36cca3..5e3dc412 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/AboutServer.kt @@ -6,7 +6,7 @@ package ca.gosyer.jui.domain.settings.interactor -import ca.gosyer.jui.domain.settings.service.SettingsRepositoryOld +import ca.gosyer.jui.domain.settings.service.SettingsRepository import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.singleOrNull import me.tatarka.inject.annotations.Inject @@ -15,7 +15,7 @@ import org.lighthousegames.logging.logging class AboutServer @Inject constructor( - private val settingsRepositoryOld: SettingsRepositoryOld, + private val settingsRepository: SettingsRepository, ) { suspend fun await(onError: suspend (Throwable) -> Unit = {}) = asFlow() @@ -25,7 +25,7 @@ class AboutServer } .singleOrNull() - fun asFlow() = settingsRepositoryOld.aboutServer() + fun asFlow() = settingsRepository.aboutServer() companion object { private val log = logging() diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt deleted file mode 100644 index 2829ce87..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/interactor/CheckUpdate.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.settings.interactor - -import ca.gosyer.jui.domain.settings.service.SettingsRepositoryOld -import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.singleOrNull -import me.tatarka.inject.annotations.Inject -import org.lighthousegames.logging.logging - -class CheckUpdate - @Inject - constructor( - private val settingsRepositoryOld: SettingsRepositoryOld, - ) { - suspend fun await(onError: suspend (Throwable) -> Unit = {}) = - asFlow() - .catch { - onError(it) - log.warn(it) { "Failed to check for server updates" } - } - .singleOrNull() - - fun asFlow() = settingsRepositoryOld.checkUpdate() - - companion object { - private val log = logging() - } - } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/model/About.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/model/About.kt index 15a8f695..8dd30b36 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/model/About.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/model/About.kt @@ -15,7 +15,6 @@ import kotlinx.serialization.Serializable data class About( val name: String, val version: String, - val revision: String, val buildType: AboutBuildType, val buildTime: Long, val github: String, diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepository.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepository.kt index 46d22094..a2ec9054 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepository.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepository.kt @@ -6,6 +6,7 @@ package ca.gosyer.jui.domain.settings.service +import ca.gosyer.jui.domain.settings.model.About import ca.gosyer.jui.domain.settings.model.SetSettingsInput import ca.gosyer.jui.domain.settings.model.Settings import kotlinx.coroutines.flow.Flow @@ -14,4 +15,6 @@ interface SettingsRepository { fun getSettings(): Flow fun setSettings(input: SetSettingsInput): Flow + + fun aboutServer(): Flow } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepositoryOld.kt deleted file mode 100644 index 065cd6de..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/settings/service/SettingsRepositoryOld.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.settings.service - -import ca.gosyer.jui.domain.settings.model.About -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.POST -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface SettingsRepositoryOld { - @GET("api/v1/settings/about") - fun aboutServer(): Flow - - @POST("api/v1/settings/check-update") - fun checkUpdate(): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/SourceRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/SourceRepositoryOld.kt deleted file mode 100644 index df10904d..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/source/service/SourceRepositoryOld.kt +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.source.service - -import ca.gosyer.jui.domain.source.model.MangaPage -import ca.gosyer.jui.domain.source.model.Source -import ca.gosyer.jui.domain.source.model.sourcefilters.SourceFilterChangeOld -import ca.gosyer.jui.domain.source.model.sourcefilters.SourceFilterData -import ca.gosyer.jui.domain.source.model.sourcefilters.SourceFilterOld -import ca.gosyer.jui.domain.source.model.sourcepreference.SourcePreferenceChange -import ca.gosyer.jui.domain.source.model.sourcepreference.SourcePreferenceOld -import de.jensklingenberg.ktorfit.http.Body -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.Headers -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Path -import de.jensklingenberg.ktorfit.http.Query -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface SourceRepositoryOld { - @GET("api/v1/source/list") - fun getSourceList(): Flow> - - @GET("api/v1/source/{sourceId}") - fun getSourceInfo( - @Path("sourceId") sourceId: Long, - ): Flow - - @GET("api/v1/source/{sourceId}/popular/{pageNum}") - fun getPopularManga( - @Path("sourceId") sourceId: Long, - @Path("pageNum") pageNum: Int, - ): Flow - - @GET("api/v1/source/{sourceId}/latest/{pageNum}") - fun getLatestManga( - @Path("sourceId") sourceId: Long, - @Path("pageNum") pageNum: Int, - ): Flow - - @GET("api/v1/source/{sourceId}/search") - fun getSearchResults( - @Path("sourceId") sourceId: Long, - @Query("searchTerm") searchTerm: String?, - @Query("pageNum") pageNum: Int, - ): Flow - - @GET("api/v1/source/{sourceId}/filters") - fun getFilterList( - @Path("sourceId") sourceId: Long, - @Query("reset") reset: Boolean = false, - ): Flow> - - @POST("api/v1/source/{sourceId}/filters") - @Headers("Content-Type: application/json") - fun setFilter( - @Path("sourceId") sourceId: Long, - @Body sourceFilter: SourceFilterChangeOld, - ): Flow - - @POST("api/v1/source/{sourceId}/filters") - @Headers("Content-Type: application/json") - fun setFilters( - @Path("sourceId") sourceId: Long, - @Body sourceFilters: List, - ): Flow - - @POST("api/v1/source/{sourceId}/quick-search") - @Headers("Content-Type: application/json") - fun getQuickSearchResults( - @Path("sourceId") sourceId: Long, - @Query("pageNum") pageNum: Int, - @Body filterData: SourceFilterData, - ): Flow - - @GET("api/v1/source/{sourceId}/preferences") - fun getSourceSettings( - @Path("sourceId") sourceId: Long, - ): Flow> - - @POST("api/v1/source/{sourceId}/preferences") - @Headers("Content-Type: application/json") - fun setSourceSetting( - @Path("sourceId") sourceId: Long, - @Body sourcePreference: SourcePreferenceChange, - ): Flow -} diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatesRepositoryOld.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatesRepositoryOld.kt deleted file mode 100644 index 1da94a3a..00000000 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/updates/service/UpdatesRepositoryOld.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -package ca.gosyer.jui.domain.updates.service - -import ca.gosyer.jui.domain.updates.model.Updates -import de.jensklingenberg.ktorfit.http.Field -import de.jensklingenberg.ktorfit.http.FormUrlEncoded -import de.jensklingenberg.ktorfit.http.GET -import de.jensklingenberg.ktorfit.http.POST -import de.jensklingenberg.ktorfit.http.Path -import io.ktor.client.statement.HttpResponse -import kotlinx.coroutines.flow.Flow - -interface UpdatesRepositoryOld { - @GET("api/v1/update/recentChapters/{pageNum}/") - fun getRecentUpdates( - @Path("pageNum") pageNum: Int, - ): Flow - - @POST("api/v1/update/fetch/") - fun updateLibrary(): Flow - - @POST("api/v1/update/fetch/") - @FormUrlEncoded - fun updateCategory( - @Field("category") categoryId: Long, - ): Flow -} diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt index ea125014..7e9ececf 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/main/about/components/AboutContent.kt @@ -187,7 +187,7 @@ private fun ServerVersionInfo( } else { PreferenceRow( title = stringResource(MR.strings.server_version), - subtitle = "${about.buildType.name} ${about.version}-${about.revision} ($formattedBuildTime)", + subtitle = "${about.buildType.name} ${about.version} ($formattedBuildTime)", ) } } diff --git a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt index 9dd7858d..b7bb5e78 100644 --- a/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt +++ b/presentation/src/commonMain/kotlin/ca/gosyer/jui/ui/manga/MangaScreenViewModel.kt @@ -42,6 +42,7 @@ import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map @@ -90,7 +91,9 @@ class MangaScreenViewModel private val loadingManga = MutableStateFlow(true) private val loadingChapters = MutableStateFlow(true) - val isLoading = combine(loadingManga, loadingChapters) { a, b -> a || b } + private val refreshingChapters = MutableStateFlow(false) + private val refreshingManga = MutableStateFlow(false) + val isLoading = combine(loadingManga, loadingChapters, refreshingManga, refreshingChapters) { a, b, c, d -> a || b || c || d } .stateIn(scope, SharingStarted.Eagerly, true) val categories = getCategories.asFlow(true) @@ -137,19 +140,11 @@ class MangaScreenViewModel } .onEach { _manga.value = it - if (_manga.value?.initialized == false) { - refreshManga.await( - params.mangaId, - onError = { - log.warn(it) { "Error when fetching manga" } - toast(it.message.orEmpty()) - } - ) - } loadingManga.value = false } .catch { toast(it.message.orEmpty()) + log.warn(it) { "Error when loading manga" } loadingManga.value = false } .launchIn(scope) @@ -159,16 +154,7 @@ class MangaScreenViewModel getChapters.asFlow(params.mangaId) } .onEach { - _chapters.value = it.toDownloadChapters() - if (_chapters.value.isEmpty()) { - refreshChapters.await( - params.mangaId, - onError = { - log.warn(it) { "Error when fetching chapters" } - toast(it.message.orEmpty()) - } - ) - } + updateChapters(it) loadingChapters.value = false } .catch { @@ -184,6 +170,13 @@ class MangaScreenViewModel _mangaCategories.value = mangaCategories.toImmutableList() } } + + scope.launch { + val manga = manga.first { it != null }!! + if (!manga.initialized) { + refreshManga() + } + } } fun loadManga() { @@ -198,28 +191,38 @@ class MangaScreenViewModel } } + fun updateChapters(chapters: List) { + _chapters.value = chapters.sortedByDescending { it.index }.toDownloadChapters() + } + fun refreshManga() { scope.launch { - loadingManga.value = true - refreshManga.await( + refreshingManga.value = true + val manga = refreshManga.await( params.mangaId, onError = { log.warn(it) { "Error when refreshing manga" } toast(it.message.orEmpty()) } ) - loadingManga.value = false + if (manga != null) { + _manga.value = manga + } + refreshingManga.value = false } scope.launch { - loadingChapters.value = true - refreshChapters.await( + refreshingChapters.value = true + val chapters = refreshChapters.await( params.mangaId, onError = { log.warn(it) { "Error when refreshing chapters" } toast(it.message.orEmpty()) } ) - loadingChapters.value = false + if (!chapters.isNullOrEmpty()) { + updateChapters(chapters) + } + refreshingChapters.value = false } } @@ -242,6 +245,7 @@ class MangaScreenViewModel chooseCategoriesFlow.emit(Unit) } } + loadManga() } } } @@ -275,6 +279,8 @@ class MangaScreenViewModel if (mangaCategories != null) { _mangaCategories.value = mangaCategories.toImmutableList() } + + loadManga() } } } @@ -287,6 +293,7 @@ class MangaScreenViewModel manga.value?.let { updateChapter.await(chapterIds, read = read, onError = { toast(it.message.orEmpty()) }) _selectedIds.value = persistentListOf() + loadChapters() } } } @@ -303,6 +310,7 @@ class MangaScreenViewModel manga.value?.let { updateChapter.await(chapterIds, bookmarked = bookmark, onError = { toast(it.message.orEmpty()) }) _selectedIds.value = persistentListOf() + loadChapters() } } } @@ -319,6 +327,7 @@ class MangaScreenViewModel .subList(0, index).map{it.chapter.id} // todo test updateChapter.await(chapters, read = true, onError = { toast(it.message.orEmpty()) }) _selectedIds.value = persistentListOf() + loadChapters() } } }