Fix formatting in a bunch of files

This commit is contained in:
Syer10
2025-10-03 21:20:55 -04:00
parent a7cc5e664b
commit bdd4ef20cb
92 changed files with 4647 additions and 4709 deletions

View File

@@ -23,9 +23,8 @@ import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ServerListeners
@Inject
constructor() {
@Inject
class ServerListeners {
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private fun <T> Flow<T>.startWith(value: T) = onStart { emit(value) }
@@ -122,4 +121,4 @@ class ServerListeners
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ExportBackupFile
@Inject
constructor(
@Inject
class ExportBackupFile(
private val backupRepository: BackupRepository,
) {
) {
suspend fun await(
includeCategories: Boolean,
includeChapters: Boolean,
@@ -39,4 +38,4 @@ class ExportBackupFile
companion object {
private val log = logging()
}
}
}

View File

@@ -15,11 +15,10 @@ import okio.Path
import okio.SYSTEM
import org.lighthousegames.logging.logging
class ImportBackupFile
@Inject
constructor(
@Inject
class ImportBackupFile(
private val backupRepository: BackupRepository,
) {
) {
suspend fun await(
file: Path,
onError: suspend (Throwable) -> Unit = {},
@@ -35,4 +34,4 @@ class ImportBackupFile
companion object {
private val log = logging()
}
}
}

View File

@@ -15,11 +15,10 @@ import okio.Path
import okio.SYSTEM
import org.lighthousegames.logging.logging
class ValidateBackupFile
@Inject
constructor(
@Inject
class ValidateBackupFile(
private val backupRepository: BackupRepository,
) {
) {
suspend fun await(
file: Path,
onError: suspend (Throwable) -> Unit = {},
@@ -35,4 +34,4 @@ class ValidateBackupFile
companion object {
private val log = logging()
}
}
}

View File

@@ -17,12 +17,11 @@ import kotlinx.coroutines.flow.map
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class AddMangaToCategory
@Inject
constructor(
@Inject
class AddMangaToCategory(
private val categoryRepository: CategoryRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
categoryId: Long,
@@ -74,4 +73,4 @@ class AddMangaToCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class CreateCategory
@Inject
constructor(
@Inject
class CreateCategory(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
name: String,
onError: suspend (Throwable) -> Unit = {},
@@ -32,4 +31,4 @@ class CreateCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class DeleteCategory
@Inject
constructor(
@Inject
class DeleteCategory(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
categoryId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -45,4 +44,4 @@ class DeleteCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetCategories
@Inject
constructor(
@Inject
class GetCategories(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
dropDefault: Boolean = false,
onError: suspend (Throwable) -> Unit = {},
@@ -41,4 +40,4 @@ class GetCategories
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetMangaCategories
@Inject
constructor(
@Inject
class GetMangaCategories(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -45,4 +44,4 @@ class GetMangaCategories
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.take
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetMangaListFromCategory
@Inject
constructor(
@Inject
class GetMangaListFromCategory(
private val categoryRepository: CategoryRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
categoryId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -56,4 +55,4 @@ class GetMangaListFromCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ModifyCategory
@Inject
constructor(
@Inject
class ModifyCategory(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
categoryId: Long,
name: String,
@@ -61,4 +60,4 @@ class ModifyCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -17,12 +17,11 @@ import kotlinx.coroutines.flow.map
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class RemoveMangaFromCategory
@Inject
constructor(
@Inject
class RemoveMangaFromCategory(
private val categoryRepository: CategoryRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
categoryId: Long,
@@ -74,4 +73,4 @@ class RemoveMangaFromCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ReorderCategory
@Inject
constructor(
@Inject
class ReorderCategory(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
categoryId: Long,
position: Int,
@@ -36,4 +35,4 @@ class ReorderCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -14,11 +14,10 @@ import kotlinx.coroutines.flow.flow
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateCategoryMeta
@Inject
constructor(
@Inject
class UpdateCategoryMeta(
private val categoryRepository: CategoryRepository,
) {
) {
suspend fun await(
category: Category,
example: Int = category.meta.example,
@@ -47,4 +46,4 @@ class UpdateCategoryMeta
companion object {
private val log = logging()
}
}
}

View File

@@ -16,12 +16,11 @@ import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
import kotlin.jvm.JvmName
class DeleteChapterDownload
@Inject
constructor(
@Inject
class DeleteChapterDownload(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapterId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -85,4 +84,4 @@ class DeleteChapterDownload
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.take
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetChapter
@Inject
constructor(
@Inject
class GetChapter(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapterId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -58,4 +57,4 @@ class GetChapter
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetChapterPages
@Inject
constructor(
@Inject
class GetChapterPages(
private val chapterRepository: ChapterRepository,
) {
) {
suspend fun await(
chapterId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -49,4 +48,4 @@ class GetChapterPages
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.take
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetChapters
@Inject
constructor(
@Inject
class GetChapters(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -58,4 +57,4 @@ class GetChapters
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class RefreshChapters
@Inject
constructor(
@Inject
class RefreshChapters(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -52,4 +51,4 @@ class RefreshChapters
companion object {
private val log = logging()
}
}
}

View File

@@ -16,12 +16,11 @@ import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
import kotlin.jvm.JvmName
class UpdateChapter
@Inject
constructor(
@Inject
class UpdateChapter(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapterId: Long,
bookmarked: Boolean? = null,
@@ -127,4 +126,4 @@ class UpdateChapter
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateChapterLastPageRead
@Inject
constructor(
@Inject
class UpdateChapterLastPageRead(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapterId: Long,
lastPageRead: Int,
@@ -62,4 +61,4 @@ class UpdateChapterLastPageRead
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.flow
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateChapterMeta
@Inject
constructor(
@Inject
class UpdateChapterMeta(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapter: Chapter,
pageOffset: Int = chapter.meta.juiPageOffset,
@@ -50,4 +49,4 @@ class UpdateChapterMeta
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateChapterRead
@Inject
constructor(
@Inject
class UpdateChapterRead(
private val chapterRepository: ChapterRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
chapterId: Long,
read: Boolean,
@@ -70,4 +69,4 @@ class UpdateChapterRead
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class BatchChapterDownload
@Inject
constructor(
@Inject
class BatchChapterDownload(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(
chapterIds: List<Long>,
onError: suspend (Throwable) -> Unit = {},
@@ -44,4 +43,4 @@ class BatchChapterDownload
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ClearDownloadQueue
@Inject
constructor(
@Inject
class ClearDownloadQueue(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class ClearDownloadQueue
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class QueueChapterDownload
@Inject
constructor(
@Inject
class QueueChapterDownload(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(
chapterId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -32,4 +31,4 @@ class QueueChapterDownload
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ReorderChapterDownload
@Inject
constructor(
@Inject
class ReorderChapterDownload(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(
chapterId: Long,
to: Int,
@@ -36,4 +35,4 @@ class ReorderChapterDownload
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class StartDownloading
@Inject
constructor(
@Inject
class StartDownloading(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class StartDownloading
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class StopChapterDownload
@Inject
constructor(
@Inject
class StopChapterDownload(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(
chapterId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -32,4 +31,4 @@ class StopChapterDownload
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class StopDownloading
@Inject
constructor(
@Inject
class StopDownloading(
private val downloadRepository: DownloadRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class StopDownloading
companion object {
private val log = logging()
}
}
}

View File

@@ -16,15 +16,13 @@ import io.ktor.websocket.Frame
import io.ktor.websocket.readText
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.serialization.decodeFromString
import me.tatarka.inject.annotations.Inject
class DownloadService
@Inject
constructor(
@Inject
class DownloadService(
serverPreferences: ServerPreferences,
client: Http,
) : WebsocketService(serverPreferences, client) {
) : WebsocketService(serverPreferences, client) {
override val _status: MutableStateFlow<Status>
get() = status
@@ -54,4 +52,4 @@ class DownloadService
it.filter { it.mangaId in mangaIds }
}
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetExtensionList
@Inject
constructor(
@Inject
class GetExtensionList(
private val extensionRepository: ExtensionRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class GetExtensionList
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class InstallExtension
@Inject
constructor(
@Inject
class InstallExtension(
private val extensionRepository: ExtensionRepository,
) {
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},
@@ -33,4 +32,4 @@ class InstallExtension
companion object {
private val log = logging()
}
}
}

View File

@@ -15,11 +15,10 @@ import okio.Path
import okio.SYSTEM
import org.lighthousegames.logging.logging
class InstallExtensionFile
@Inject
constructor(
@Inject
class InstallExtensionFile(
private val extensionRepository: ExtensionRepository,
) {
) {
suspend fun await(
path: Path,
onError: suspend (Throwable) -> Unit = {},
@@ -35,4 +34,4 @@ class InstallExtensionFile
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UninstallExtension
@Inject
constructor(
@Inject
class UninstallExtension(
private val extensionRepository: ExtensionRepository,
) {
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},
@@ -33,4 +32,4 @@ class UninstallExtension
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateExtension
@Inject
constructor(
@Inject
class UpdateExtension(
private val extensionRepository: ExtensionRepository,
) {
) {
suspend fun await(
extension: Extension,
onError: suspend (Throwable) -> Unit = {},
@@ -33,4 +32,4 @@ class UpdateExtension
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetGlobalMeta
@Inject
constructor(
@Inject
class GetGlobalMeta(
private val globalRepository: GlobalRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class GetGlobalMeta
companion object {
private val log = logging()
}
}
}

View File

@@ -14,11 +14,10 @@ import kotlinx.coroutines.flow.flow
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateGlobalMeta
@Inject
constructor(
@Inject
class UpdateGlobalMeta(
private val globalRepository: GlobalRepository,
) {
) {
suspend fun await(
globalMeta: GlobalMeta,
example: Int = globalMeta.example,
@@ -46,4 +45,4 @@ class UpdateGlobalMeta
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class AddMangaToLibrary
@Inject
constructor(
@Inject
class AddMangaToLibrary(
private val libraryRepository: LibraryRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -52,4 +51,4 @@ class AddMangaToLibrary
companion object {
private val log = logging()
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class RemoveMangaFromLibrary
@Inject
constructor(
@Inject
class RemoveMangaFromLibrary(
private val libraryRepository: LibraryRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -52,4 +51,4 @@ class RemoveMangaFromLibrary
companion object {
private val log = logging()
}
}
}

View File

@@ -16,12 +16,11 @@ import kotlinx.coroutines.flow.MutableStateFlow
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class LibraryUpdateService
@Inject
constructor(
@Inject
class LibraryUpdateService(
serverPreferences: ServerPreferences,
client: Http,
) : WebsocketService(serverPreferences, client) {
) : WebsocketService(serverPreferences, client) {
override val _status: MutableStateFlow<Status>
get() = status
@@ -38,4 +37,4 @@ class LibraryUpdateService
val status = MutableStateFlow(Status.STARTING)
val updateStatus = MutableStateFlow(UpdateStatus(emptyMap(), emptyMap(), false))
}
}
}

View File

@@ -15,12 +15,11 @@ import kotlinx.coroutines.flow.take
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetManga
@Inject
constructor(
@Inject
class GetManga(
private val mangaRepository: MangaRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -56,4 +55,4 @@ class GetManga
companion object {
private val log = logging()
}
}
}

View File

@@ -16,12 +16,11 @@ import kotlinx.coroutines.flow.take
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class RefreshManga
@Inject
constructor(
@Inject
class RefreshManga(
private val mangaRepository: MangaRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
mangaId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -51,4 +50,4 @@ class RefreshManga
companion object {
private val log = logging()
}
}
}

View File

@@ -17,12 +17,11 @@ import kotlinx.coroutines.flow.flow
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateMangaMeta
@Inject
constructor(
@Inject
class UpdateMangaMeta(
private val mangaRepository: MangaRepository,
private val serverListeners: ServerListeners,
) {
) {
suspend fun await(
manga: Manga,
readerMode: String = manga.meta.juiReaderMode,
@@ -52,4 +51,4 @@ class UpdateMangaMeta
companion object {
private val log = logging()
}
}
}

View File

@@ -11,12 +11,11 @@ import ca.gosyer.jui.domain.migration.service.MigrationPreferences
import ca.gosyer.jui.domain.reader.service.ReaderPreferences
import me.tatarka.inject.annotations.Inject
class RunMigrations
@Inject
constructor(
@Inject
class RunMigrations(
private val migrationPreferences: MigrationPreferences,
private val readerPreferences: ReaderPreferences,
) {
) {
fun runMigrations() {
val code = migrationPreferences.version().get()
if (code <= 0) {
@@ -27,4 +26,4 @@ class RunMigrations
return
}
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class AboutServer
@Inject
constructor(
@Inject
class AboutServer(
private val settingsRepository: SettingsRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class AboutServer
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetSettings
@Inject
constructor(
@Inject
class GetSettings(
private val settingsRepository: SettingsRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class GetSettings
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SetSettings
@Inject
constructor(
@Inject
class SetSettings(
private val settingsRepository: SettingsRepository,
) {
) {
suspend fun await(
input: SetSettingsInput,
onError: suspend (Throwable) -> Unit = {},
@@ -33,4 +32,4 @@ class SetSettings
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetFilterList
@Inject
constructor(
@Inject
class GetFilterList(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
source: Source,
onError: suspend (Throwable) -> Unit = {},
@@ -45,4 +44,4 @@ class GetFilterList
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetLatestManga
@Inject
constructor(
@Inject
class GetLatestManga(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
source: Source,
page: Int,
@@ -53,4 +52,4 @@ class GetLatestManga
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetPopularManga
@Inject
constructor(
@Inject
class GetPopularManga(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
source: Source,
page: Int,
@@ -53,4 +52,4 @@ class GetPopularManga
companion object {
private val log = logging()
}
}
}

View File

@@ -14,11 +14,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetSearchManga
@Inject
constructor(
@Inject
class GetSearchManga(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
source: Source,
page: Int,
@@ -74,4 +73,4 @@ class GetSearchManga
companion object {
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetSourceList
@Inject
constructor(
@Inject
class GetSourceList(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class GetSourceList
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetSourceSettings
@Inject
constructor(
@Inject
class GetSourceSettings(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
source: Source,
onError: suspend (Throwable) -> Unit = {},
@@ -45,4 +44,4 @@ class GetSourceSettings
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SetSourceSetting
@Inject
constructor(
@Inject
class SetSourceSetting(
private val sourceRepository: SourceRepository,
) {
) {
suspend fun await(
sourceId: Long,
sourcePreference: SourcePreference,
@@ -41,4 +40,4 @@ class SetSourceSetting
companion object {
private val log = logging()
}
}
}

View File

@@ -33,13 +33,12 @@ fun interface GetMangaPage {
suspend fun get(page: Int): MangaPage?
}
class SourcePager
@Inject
constructor(
@Inject
class SourcePager(
private val getManga: GetManga,
private val serverListeners: ServerListeners,
@Assisted private val fetcher: GetMangaPage,
) : CoroutineScope by CoroutineScope(Dispatchers.Default + SupervisorJob()) {
) : CoroutineScope by CoroutineScope(Dispatchers.Default + SupervisorJob()) {
private val sourceMutex = Mutex()
private val _sourceManga = MutableStateFlow<List<Manga>>(emptyList())
@@ -47,7 +46,8 @@ class SourcePager
private val mangaIds = _sourceManga.map { mangas -> mangas.map { it.id } }
.stateIn(this, SharingStarted.Eagerly, emptyList())
private val changedManga = serverListeners.mangaListener.runningFold(emptyMap<Long, Manga>()) { manga, updatedMangaIds ->
private val changedManga =
serverListeners.mangaListener.runningFold(emptyMap<Long, Manga>()) { manga, updatedMangaIds ->
coroutineScope {
manga + updatedMangaIds.filter { it in mangaIds.value }.map {
async {
@@ -90,4 +90,4 @@ class SourcePager
companion object {
private val log = logging()
}
}
}

View File

@@ -15,7 +15,7 @@ enum class StartScreen {
Library,
Updates,
// History,
// History,
Sources,
Extensions,
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GetRecentUpdates
@Inject
constructor(
@Inject
class GetRecentUpdates(
private val updatesRepository: UpdatesRepository,
) {
) {
suspend fun await(
pageNum: Int,
onError: suspend (Throwable) -> Unit = {},
@@ -32,4 +31,4 @@ class GetRecentUpdates
companion object {
private val log = logging()
}
}
}

View File

@@ -13,11 +13,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateCategory
@Inject
constructor(
@Inject
class UpdateCategory(
private val updatesRepository: UpdatesRepository,
) {
) {
suspend fun await(
categoryId: Long,
onError: suspend (Throwable) -> Unit = {},
@@ -45,4 +44,4 @@ class UpdateCategory
companion object {
private val log = logging()
}
}
}

View File

@@ -21,12 +21,11 @@ import kotlinx.coroutines.flow.singleOrNull
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateChecker
@Inject
constructor(
@Inject
class UpdateChecker(
private val updatePreferences: UpdatePreferences,
private val client: Http,
) {
) {
suspend fun await(
manualFetch: Boolean,
onError: suspend (Throwable) -> Unit = {},
@@ -94,4 +93,4 @@ class UpdateChecker
private val log = logging()
}
}
}

View File

@@ -12,11 +12,10 @@ import kotlinx.coroutines.flow.collect
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdateLibrary
@Inject
constructor(
@Inject
class UpdateLibrary(
private val updatesRepository: UpdatesRepository,
) {
) {
suspend fun await(onError: suspend (Throwable) -> Unit = {}) =
asFlow()
.catch {
@@ -30,4 +29,4 @@ class UpdateLibrary
companion object {
private val log = logging()
}
}
}

View File

@@ -37,14 +37,13 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import me.tatarka.inject.annotations.Inject
class UpdatesPager
@Inject
constructor(
@Inject
class UpdatesPager(
private val getRecentUpdates: GetRecentUpdates,
private val getManga: GetManga,
private val getChapter: GetChapter,
private val serverListeners: ServerListeners,
) : CoroutineScope by CoroutineScope(Dispatchers.Default + SupervisorJob()) {
) : CoroutineScope by CoroutineScope(Dispatchers.Default + SupervisorJob()) {
private val updatesMutex = Mutex()
private val fetchedUpdates = MutableSharedFlow<List<MangaAndChapter>>()
@@ -84,7 +83,8 @@ class UpdatesPager
updates.filterIsInstance<Updates.Update>().map { it.chapter.id }
}.stateIn(this, SharingStarted.Eagerly, emptyList())
private val changedManga = serverListeners.mangaListener.runningFold(emptyMap<Long, Manga>()) { manga, updatedMangaIds ->
private val changedManga =
serverListeners.mangaListener.runningFold(emptyMap<Long, Manga>()) { manga, updatedMangaIds ->
coroutineScope {
manga + updatedMangaIds.filter { it in mangaIds.value }.map {
async {
@@ -172,4 +172,4 @@ class UpdatesPager
fetchedUpdates.emit(updates.page)
return true
}
}
}

View File

@@ -38,11 +38,10 @@ import kotlin.io.path.exists
import kotlin.io.path.isExecutable
@OptIn(DelicateCoroutinesApi::class)
class ServerService
@Inject
constructor(
@Inject
class ServerService(
private val serverHostPreferences: ServerHostPreferences,
) {
) {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
private val host = serverHostPreferences.host().stateIn(GlobalScope)
@@ -203,4 +202,4 @@ class ServerService
private companion object {
private val log = logging()
}
}
}

View File

@@ -15,8 +15,7 @@ import me.tatarka.inject.annotations.Inject
@Composable
actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit = {}
actual class SettingsServerHostViewModel
@Inject
constructor(
@Inject
actual class SettingsServerHostViewModel(
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper)
) : ViewModel(contextWrapper)

View File

@@ -30,13 +30,12 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import me.tatarka.inject.annotations.Inject
class ImageLoaderProvider
@Inject
constructor(
@Inject
class ImageLoaderProvider(
private val http: Http,
serverPreferences: ServerPreferences,
private val context: ContextWrapper,
) {
) {
@OptIn(DelicateCoroutinesApi::class)
val serverUrl = serverPreferences.serverUrl().stateIn(GlobalScope)
@@ -126,7 +125,7 @@ class ImageLoaderProvider
return data.iconUrl
}
}
}
}
expect fun OptionsBuilder.configure(contextWrapper: ContextWrapper)

View File

@@ -59,12 +59,11 @@ fun AppTheme(content: @Composable () -> Unit) {
}
}
class AppThemeViewModel
@Inject
constructor(
@Inject
class AppThemeViewModel(
private val uiPreferences: UiPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
override val scope = MainScope()
private val themeMode = uiPreferences.themeMode().asStateFlow()
@@ -95,7 +94,10 @@ class AppThemeViewModel
val secondary by colors.secondaryStateFlow.collectAsState()
val tertiary by colors.tertiaryStateFlow.collectAsState()
return getMaterialColors(baseTheme.colors, primary, secondary) to getExtraColors(baseTheme.extraColors, tertiary)
return getMaterialColors(baseTheme.colors, primary, secondary) to getExtraColors(
baseTheme.extraColors,
tertiary,
)
}
@Composable
@@ -155,4 +157,4 @@ class AppThemeViewModel
baseThemeScope.cancel()
scope.cancel()
}
}
}

View File

@@ -27,16 +27,15 @@ import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class CategoriesScreenViewModel
@Inject
constructor(
@Inject
class CategoriesScreenViewModel(
private val getCategories: GetCategories,
private val createCategory: CreateCategory,
private val deleteCategory: DeleteCategory,
private val modifyCategory: ModifyCategory,
private val reorderCategory: ReorderCategory,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private var originalCategories = emptyList<Category>()
private val _categories = MutableStateFlow<ImmutableList<MenuCategory>>(persistentListOf())
val categories = _categories.asStateFlow()
@@ -75,7 +74,8 @@ class CategoriesScreenViewModel
}
var updatedCategories = getCategories.await(true, onError = { toast(it.message.orEmpty()) })
categories.sortedBy { it.order }.forEach { category ->
val updatedCategory = updatedCategories?.find { it.id == category.id || it.name == category.name } ?: return@forEach
val updatedCategory =
updatedCategories?.find { it.id == category.id || it.name == category.name } ?: return@forEach
if (category.order != updatedCategory.order) {
log.debug { "${category.name}: ${updatedCategory.order} to ${category.order}" }
reorderCategory.await(category.id!!, category.order, onError = { toast(it.message.orEmpty()) })
@@ -92,7 +92,8 @@ class CategoriesScreenViewModel
category: MenuCategory,
newName: String,
) {
_categories.value = (_categories.value.toPersistentList() - category + category.copy(name = newName)).sortedBy { it.order }
_categories.value =
(_categories.value.toPersistentList() - category + category.copy(name = newName)).sortedBy { it.order }
.toImmutableList()
}
@@ -102,7 +103,11 @@ class CategoriesScreenViewModel
fun createCategory(name: String) {
_categories.value =
_categories.value.toPersistentList() + MenuCategory(order = categories.value.size + 1, name = name, default = false)
_categories.value.toPersistentList() + MenuCategory(
order = categories.value.size + 1,
name = name,
default = false,
)
}
fun moveUp(category: MenuCategory) {
@@ -144,4 +149,4 @@ class CategoriesScreenViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -31,9 +31,8 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class DownloadsScreenViewModel
@Inject
constructor(
@Inject
class DownloadsScreenViewModel(
private val downloadService: DownloadService,
private val startDownloading: StartDownloading,
private val stopDownloading: StopDownloading,
@@ -43,7 +42,7 @@ class DownloadsScreenViewModel
private val reorderChapterDownload: ReorderChapterDownload,
private val contextWrapper: ContextWrapper,
@Assisted standalone: Boolean,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val uiScope = if (standalone) {
MainScope()
} else {
@@ -76,7 +75,8 @@ class DownloadsScreenViewModel
fun moveUp(chapter: Chapter) {
scope.launch {
val index = downloadQueue.value.indexOfFirst { it.mangaId == chapter.mangaId && it.chapterIndex == chapter.index }
val index =
downloadQueue.value.indexOfFirst { it.mangaId == chapter.mangaId && it.chapterIndex == chapter.index }
if (index == -1 || index <= 0) return@launch
reorderChapterDownload.await(chapter.id, index - 1, onError = { toast(it.message.orEmpty()) })
}
@@ -84,7 +84,8 @@ class DownloadsScreenViewModel
fun moveDown(chapter: Chapter) {
scope.launch {
val index = downloadQueue.value.indexOfFirst { it.mangaId == chapter.mangaId && it.chapterIndex == chapter.index }
val index =
downloadQueue.value.indexOfFirst { it.mangaId == chapter.mangaId && it.chapterIndex == chapter.index }
if (index == -1 || index >= downloadQueue.value.lastIndex) return@launch
reorderChapterDownload.await(chapter.id, index + 1, onError = { toast(it.message.orEmpty()) })
}
@@ -98,7 +99,11 @@ class DownloadsScreenViewModel
fun moveToBottom(chapter: Chapter) {
scope.launch {
reorderChapterDownload.await(chapter.id, downloadQueue.value.lastIndex, onError = { toast(it.message.orEmpty()) })
reorderChapterDownload.await(
chapter.id,
downloadQueue.value.lastIndex,
onError = { toast(it.message.orEmpty()) },
)
}
}
@@ -112,4 +117,4 @@ class DownloadsScreenViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -41,9 +41,8 @@ import okio.Source
import org.lighthousegames.logging.logging
import kotlin.random.Random
class ExtensionsScreenViewModel
@Inject
constructor(
@Inject
class ExtensionsScreenViewModel(
private val getExtensionList: GetExtensionList,
private val installExtensionFile: InstallExtensionFile,
private val installExtension: InstallExtension,
@@ -51,7 +50,7 @@ class ExtensionsScreenViewModel
private val uninstallExtension: UninstallExtension,
extensionPreferences: ExtensionPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val extensionList = MutableStateFlow<List<Extension>?>(null)
private val _enabledLangs = extensionPreferences.languages().asStateFlow()
@@ -221,7 +220,7 @@ class ExtensionsScreenViewModel
private companion object {
private val log = logging()
}
}
}
@Immutable
sealed class ExtensionUI {

View File

@@ -119,9 +119,8 @@ private fun LibraryMap.setManga(
}
}
class LibraryScreenViewModel
@Inject
constructor(
@Inject
class LibraryScreenViewModel(
private val getCategories: GetCategories,
private val getMangaListFromCategory: GetMangaListFromCategory,
private val removeMangaFromLibrary: RemoveMangaFromLibrary,
@@ -130,7 +129,7 @@ class LibraryScreenViewModel
libraryPreferences: LibraryPreferences,
contextWrapper: ContextWrapper,
@Assisted private val savedStateHandle: SavedStateHandle,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val library = Library(MutableStateFlow(LibraryState.Loading), mutableMapOf())
val categories = library.categories.asStateFlow()
@@ -339,4 +338,4 @@ class LibraryScreenViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -11,12 +11,11 @@ import ca.gosyer.jui.uicore.vm.ContextWrapper
import ca.gosyer.jui.uicore.vm.ViewModel
import me.tatarka.inject.annotations.Inject
class LibrarySettingsViewModel
@Inject
constructor(
@Inject
class LibrarySettingsViewModel(
libraryPreferences: LibraryPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val filterDownloaded = libraryPreferences.filterDownloaded().asStateFlow()
val filterUnread = libraryPreferences.filterUnread().asStateFlow()
val filterCompleted = libraryPreferences.filterCompleted().asStateFlow()
@@ -29,4 +28,4 @@ class LibrarySettingsViewModel
val downloadBadges = libraryPreferences.downloadBadge().asStateFlow()
val languageBadges = libraryPreferences.languageBadge().asStateFlow()
val localBadges = libraryPreferences.localBadge().asStateFlow()
}
}

View File

@@ -14,12 +14,11 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import me.tatarka.inject.annotations.Inject
class MainViewModel
@Inject
constructor(
@Inject
class MainViewModel(
uiPreferences: UiPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
override val scope = MainScope()
val startScreen = uiPreferences.startScreen().get()
@@ -33,4 +32,4 @@ class MainViewModel
fun confirmExitToast() {
toast(MR.strings.confirm_exit_toast.toPlatformString())
}
}
}

View File

@@ -26,14 +26,13 @@ import kotlinx.datetime.Instant
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class AboutViewModel
@Inject
constructor(
@Inject
class AboutViewModel(
private val dateHandler: DateHandler,
private val aboutServer: AboutServer,
private val updateChecker: UpdateChecker,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _aboutHolder = MutableStateFlow<About?>(null)
val aboutHolder = _aboutHolder.asStateFlow()
@@ -71,4 +70,4 @@ class AboutViewModel
companion object {
private val log = logging()
}
}
}

View File

@@ -18,13 +18,12 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class LibraryUpdatesViewModel
@Inject
constructor(
@Inject
class LibraryUpdatesViewModel(
private val libraryUpdateService: LibraryUpdateService,
private val contextWrapper: ContextWrapper,
@Assisted standalone: Boolean,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val uiScope = if (standalone) {
MainScope()
} else {
@@ -47,4 +46,4 @@ class LibraryUpdatesViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -55,9 +55,8 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class MangaScreenViewModel
@Inject
constructor(
@Inject
class MangaScreenViewModel(
private val dateHandler: DateHandler,
private val getManga: GetManga,
private val refreshManga: RefreshManga,
@@ -77,7 +76,7 @@ class MangaScreenViewModel
uiPreferences: UiPreferences,
contextWrapper: ContextWrapper,
@Assisted private val params: Params,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _manga = MutableStateFlow<Manga?>(null)
val manga = _manga.asStateFlow()
@@ -93,7 +92,8 @@ class MangaScreenViewModel
private val loadingChapters = MutableStateFlow(true)
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 }
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)
@@ -203,7 +203,7 @@ class MangaScreenViewModel
onError = {
log.warn(it) { "Error when refreshing manga" }
toast(it.message.orEmpty())
}
},
)
if (manga != null) {
_manga.value = manga
@@ -217,7 +217,7 @@ class MangaScreenViewModel
onError = {
log.warn(it) { "Error when refreshing chapters" }
toast(it.message.orEmpty())
}
},
)
if (!chapters.isNullOrEmpty()) {
updateChapters(chapters)
@@ -324,7 +324,7 @@ class MangaScreenViewModel
manga.value?.let {
val chapters = chapters.value
.sortedBy { it.chapter.index }
.subList(0, index).map{it.chapter.id} // todo test
.subList(0, index).map { it.chapter.id } // todo test
updateChapter.await(chapters, read = true, onError = { toast(it.message.orEmpty()) })
_selectedIds.value = persistentListOf()
loadChapters()
@@ -437,4 +437,4 @@ class MangaScreenViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -42,7 +42,6 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.cancel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -69,9 +68,8 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class ReaderMenuViewModel
@Inject
constructor(
@Inject
class ReaderMenuViewModel(
private val readerPreferences: ReaderPreferences,
private val getManga: GetManga,
private val getChapters: GetChapters,
@@ -84,7 +82,7 @@ class ReaderMenuViewModel
private val http: Http,
contextWrapper: ContextWrapper,
@Assisted private val params: Params,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
override val scope = MainScope()
private val _manga = MutableStateFlow<Manga?>(null)
private val viewerChapters = MutableStateFlow(ViewerChapters(null, null, null))
@@ -437,4 +435,4 @@ class ReaderMenuViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -73,14 +73,13 @@ class SettingsAdvancedScreen : Screen {
}
}
class SettingsAdvancedViewModel
@Inject
constructor(
@Inject
class SettingsAdvancedViewModel(
updatePreferences: UpdatePreferences,
private val imageCache: ImageCache,
private val chapterCache: ChapterCache,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val updatesEnabled = updatePreferences.enabled().asStateFlow()
val imageCacheSize = flow {
@@ -112,7 +111,7 @@ class SettingsAdvancedViewModel
companion object {
private val log = logging()
}
}
}
@Composable
fun SettingsAdvancedScreenContent(

View File

@@ -108,12 +108,11 @@ class SettingsAppearanceScreen : Screen {
}
}
class ThemesViewModel
@Inject
constructor(
@Inject
class ThemesViewModel(
private val uiPreferences: UiPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val themeMode = uiPreferences.themeMode().asStateFlow()
val lightTheme = uiPreferences.lightTheme().asStateFlow()
val darkTheme = uiPreferences.darkTheme().asStateFlow()
@@ -124,7 +123,7 @@ class ThemesViewModel
@Composable
fun getActiveColors(): AppColorsPreferenceState = if (MaterialTheme.colors.isLight) lightColors else darkColors
}
}
expect val showWindowDecorationsOption: Boolean

View File

@@ -118,14 +118,13 @@ class SettingsBackupScreen : Screen {
}
}
class SettingsBackupViewModel
@Inject
constructor(
@Inject
class SettingsBackupViewModel(
private val validateBackupFile: ValidateBackupFile,
private val importBackupFile: ImportBackupFile,
private val exportBackupFile: ExportBackupFile,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _restoreStatus = MutableStateFlow<Status>(Status.Nothing)
val restoreStatus = _restoreStatus.asStateFlow()
@@ -207,7 +206,7 @@ class SettingsBackupViewModel
fun exportBackup() {
exportBackupFile
.asFlow(
true, true // todo
true, true, // todo
) {
onDownload { bytesSentTotal, contentLength ->
_creatingStatus.value = Status.InProgress(
@@ -267,7 +266,7 @@ class SettingsBackupViewModel
private companion object {
private val log = logging()
}
}
}
sealed class Status {
data object Nothing : Status()

View File

@@ -78,13 +78,12 @@ class SettingsGeneralScreen : Screen {
}
}
class SettingsGeneralViewModel
@Inject
constructor(
@Inject
class SettingsGeneralViewModel(
private val dateHandler: DateHandler,
uiPreferences: UiPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val startScreen = uiPreferences.startScreen().asStateFlow()
val confirmExit = uiPreferences.confirmExit().asStateFlow()
val language = uiPreferences.language().asStateFlow()
@@ -117,7 +116,12 @@ class SettingsGeneralViewModel
}
}
}
return mapOf("" to stringResource(MR.strings.language_system_default, currentLocale.getDisplayName(currentLocale)))
return mapOf(
"" to stringResource(
MR.strings.language_system_default,
currentLocale.getDisplayName(currentLocale),
),
)
.plus(langs)
.toImmutableMap()
}
@@ -133,7 +137,7 @@ class SettingsGeneralViewModel
@Composable
private fun getFormattedDate(prefValue: String): String = dateHandler.getDateFormat(prefValue).invoke(now)
}
}
@Composable
fun SettingsGeneralScreenContent(

View File

@@ -94,13 +94,12 @@ class SettingsLibraryScreen : Screen {
}
}
class SettingsLibraryViewModel
@Inject
constructor(
@Inject
class SettingsLibraryViewModel(
libraryPreferences: LibraryPreferences,
private val getCategories: GetCategories,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val displayMode = libraryPreferences.displayMode().asStateFlow()
val gridColumns = libraryPreferences.gridColumns().asStateFlow()
val gridSize = libraryPreferences.gridSize().asStateFlow()
@@ -124,7 +123,7 @@ class SettingsLibraryViewModel
DisplayMode.entries
.associateWith { stringResource(it.res) }
.toImmutableMap()
}
}
@Composable
fun SettingsLibraryScreenContent(

View File

@@ -88,12 +88,11 @@ class SettingsReaderScreen : Screen {
}
}
class SettingsReaderViewModel
@Inject
constructor(
@Inject
class SettingsReaderViewModel(
readerPreferences: ReaderPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val modes = readerPreferences.modes().asStateFlow()
.map {
it.associateWith { it }
@@ -111,7 +110,8 @@ class SettingsReaderViewModel
modes.onEach { modes ->
val modeSettings = _modeSettings.value
val modesInSettings = modeSettings.map { it.item.mode }
_modeSettings.value = modeSettings.filter { it.item.mode in modes }.toPersistentList() + modes.filter { (it) ->
_modeSettings.value =
modeSettings.filter { it.item.mode in modes }.toPersistentList() + modes.filter { (it) ->
it !in modesInSettings
}.map { (it) ->
StableHolder(ReaderModePreference(scope, it, readerPreferences.getMode(it)))
@@ -155,7 +155,7 @@ class SettingsReaderViewModel
fun getNavigationModeChoices() =
NavigationMode.entries.associateWith { it.res.toPlatformString() }
.toImmutableMap()
}
}
data class ReaderModePreference(
val scope: CoroutineScope,

View File

@@ -191,7 +191,8 @@ class ServerSettings(
getSetting = { it.backupTime },
getInput = { SetSettingsInput(backupTime = it) },
)
// val basicAuthEnabled = getServerFlow(
// val basicAuthEnabled = getServerFlow(
// getSetting = { it.basicAuthEnabled },
// getInput = { SetSettingsInput(basicAuthEnabled = it) },
// )
@@ -263,7 +264,8 @@ class ServerSettings(
getSetting = { it.globalUpdateInterval.toString() },
getInput = { SetSettingsInput(globalUpdateInterval = it.toDoubleOrNull()?.takeIf { it !in 0.01..5.99 }) },
)
// val gqlDebugLogsEnabled = getServerFlow(
// val gqlDebugLogsEnabled = getServerFlow(
// getSetting = { it.gqlDebugLogsEnabled },
// getInput = { SetSettingsInput(gqlDebugLogsEnabled = it) },
// )
@@ -360,15 +362,14 @@ class ServerSettings(
)
}
class SettingsServerViewModel
@Inject
constructor(
@Inject
class SettingsServerViewModel(
private val getSettings: GetSettings,
private val setSettings: SetSettings,
serverPreferences: ServerPreferences,
serverHostPreferences: ServerHostPreferences,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val serverUrl = serverPreferences.server().asStateIn(scope)
val serverPort = serverPreferences.port().asStringStateIn(scope)
val serverPathPrefix = serverPreferences.pathPrefix().asStateIn(scope)
@@ -420,7 +421,7 @@ class SettingsServerViewModel
}
}
}
}
}
@Composable
fun SettingsServerScreenContent(

View File

@@ -43,16 +43,15 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class GlobalSearchViewModel
@Inject
constructor(
@Inject
class GlobalSearchViewModel(
private val getSourceList: GetSourceList,
private val getSearchManga: GetSearchManga,
catalogPreferences: CatalogPreferences,
contextWrapper: ContextWrapper,
@Assisted private val savedStateHandle: SavedStateHandle,
@Assisted params: Params,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _query by savedStateHandle.getStateFlow { params.initialQuery }
val query = _query.asStateFlow()
@@ -168,4 +167,4 @@ class GlobalSearchViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -34,14 +34,13 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceHomeScreenViewModel
@Inject
constructor(
@Inject
class SourceHomeScreenViewModel(
private val getSourceList: GetSourceList,
catalogPreferences: CatalogPreferences,
contextWrapper: ContextWrapper,
@Assisted private val savedStateHandle: SavedStateHandle,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _isLoading = MutableStateFlow(true)
val isLoading = _isLoading.asStateFlow()
@@ -126,7 +125,7 @@ class SourceHomeScreenViewModel
private companion object {
private val log = logging()
}
}
}
@Stable
sealed class SourceUI {

View File

@@ -28,14 +28,13 @@ import me.tatarka.inject.annotations.Assisted
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class SourceSettingsScreenViewModel
@Inject
constructor(
@Inject
class SourceSettingsScreenViewModel(
private val getSourceSettings: GetSourceSettings,
private val setSourceSetting: SetSourceSetting,
contextWrapper: ContextWrapper,
@Assisted private val params: Params,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _loading = MutableStateFlow(true)
val loading = _loading.asStateFlow()
@@ -89,4 +88,4 @@ class SourceSettingsScreenViewModel
private companion object {
private val log = logging()
}
}
}

View File

@@ -40,9 +40,8 @@ import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
class UpdatesScreenViewModel
@Inject
constructor(
@Inject
class UpdatesScreenViewModel(
private val queueChapterDownload: QueueChapterDownload,
private val stopChapterDownload: StopChapterDownload,
private val deleteChapterDownload: DeleteChapterDownload,
@@ -52,7 +51,7 @@ class UpdatesScreenViewModel
private val updateLibrary: UpdateLibrary,
private val updatesPager: UpdatesPager,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
private val _isLoading = MutableStateFlow(true)
val isLoading = _isLoading.asStateFlow()
@@ -236,7 +235,7 @@ class UpdatesScreenViewModel
private companion object {
private val log = logging()
}
}
}
sealed class UpdatesUI {
data class Item(

View File

@@ -18,12 +18,12 @@ import kotlinx.coroutines.flow.shareIn
import me.tatarka.inject.annotations.Inject
import org.lighthousegames.logging.logging
@Inject
class TrayViewModel
@Inject
constructor(
constructor(
updateChecker: UpdateChecker,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
override val scope = MainScope()
val updateFound = updateChecker
@@ -40,4 +40,4 @@ class TrayViewModel
companion object {
private val log = logging()
}
}
}

View File

@@ -66,14 +66,14 @@ actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostVie
}
}
@Inject
actual class SettingsServerHostViewModel
@Inject
constructor(
constructor(
serverPreferences: ServerPreferences,
serverHostPreferences: ServerHostPreferences,
private val serverService: ServerService,
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
val host = serverHostPreferences.host().asStateIn(scope)
// IP
@@ -130,7 +130,7 @@ actual class SettingsServerHostViewModel
}
}.launchIn(scope)
}
}
}
fun LazyListScope.ServerHostItems(
hostValue: Boolean,

View File

@@ -11,12 +11,12 @@ import ca.gosyer.jui.uicore.vm.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import me.tatarka.inject.annotations.Inject
@Inject
actual class DebugOverlayViewModel
@Inject
constructor(
constructor(
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
actual val maxMemory: String
get() = ""
actual val usedMemoryFlow: MutableStateFlow<String> = MutableStateFlow("")
}
}

View File

@@ -15,8 +15,8 @@ import me.tatarka.inject.annotations.Inject
@Composable
actual fun getServerHostItems(viewModel: @Composable () -> SettingsServerHostViewModel): LazyListScope.() -> Unit = {}
@Inject
actual class SettingsServerHostViewModel
@Inject
constructor(
constructor(
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper)
) : ViewModel(contextWrapper)

View File

@@ -16,11 +16,11 @@ import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import kotlin.time.Duration.Companion.milliseconds
@Inject
actual class DebugOverlayViewModel
@Inject
constructor(
constructor(
contextWrapper: ContextWrapper,
) : ViewModel(contextWrapper) {
) : ViewModel(contextWrapper) {
override val scope = MainScope()
val runtime: Runtime = Runtime.getRuntime()
@@ -48,4 +48,4 @@ actual class DebugOverlayViewModel
super.onDispose()
scope.cancel()
}
}
}