From e020ae5ed558e80742ef0ad8bfa0f69af0959d5a Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sun, 24 Mar 2024 05:16:31 +0600 Subject: [PATCH] Fix more TypeReference issues and cleanup --- .../java/eu/kanade/domain/DomainModule.kt | 2 ++ .../java/eu/kanade/tachiyomi/Migrations.kt | 2 +- .../repository/ExtensionRepoRepositoryImpl.kt | 12 +++++------ .../interactor/CreateExtensionRepo.kt | 20 ++++++------------- .../interactor/DeleteExtensionRepo.kt | 4 ++-- .../interactor/GetExtensionRepo.kt | 6 +++--- .../interactor/GetExtensionRepoCount.kt | 4 ++-- .../interactor/ReplaceExtensionRepo.kt | 4 ++-- .../interactor/UpdateExtensionRepo.kt | 13 +++++------- .../repository/ExtensionRepoRepository.kt | 16 +++++++-------- .../service/ExtensionRepoService.kt | 4 +--- 11 files changed, 38 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index 2bea7586b..cace3e974 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -31,6 +31,7 @@ import mihon.domain.extensionrepo.interactor.GetExtensionRepoCount import mihon.domain.extensionrepo.interactor.ReplaceExtensionRepo import mihon.domain.extensionrepo.interactor.UpdateExtensionRepo import mihon.domain.extensionrepo.repository.ExtensionRepoRepository +import mihon.domain.extensionrepo.service.ExtensionRepoService import tachiyomi.data.category.CategoryRepositoryImpl import tachiyomi.data.chapter.ChapterRepositoryImpl import tachiyomi.data.history.HistoryRepositoryImpl @@ -179,6 +180,7 @@ class DomainModule : InjektModule { addFactory { TrustExtension(get()) } addSingletonFactory { ExtensionRepoRepositoryImpl(get()) } + addFactory { ExtensionRepoService(get(), get()) } addFactory { GetExtensionRepo(get()) } addFactory { GetExtensionRepoCount(get()) } addFactory { CreateExtensionRepo(get(), get()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 58ea5d29d..7bb0042e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -48,7 +48,7 @@ object Migrations { coroutineScope.launchIO { for ((index, source) in sourcePreferences.extensionRepos().get().withIndex()) { try { - extensionRepoRepository.upsertRepository( + extensionRepoRepository.upsertRepo( source, "Repo #${index + 1}", null, diff --git a/data/src/main/java/mihon/data/repository/ExtensionRepoRepositoryImpl.kt b/data/src/main/java/mihon/data/repository/ExtensionRepoRepositoryImpl.kt index 65fcd149c..24910d968 100644 --- a/data/src/main/java/mihon/data/repository/ExtensionRepoRepositoryImpl.kt +++ b/data/src/main/java/mihon/data/repository/ExtensionRepoRepositoryImpl.kt @@ -19,11 +19,11 @@ class ExtensionRepoRepositoryImpl( return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) } } - override suspend fun getRepository(baseUrl: String): ExtensionRepo? { + override suspend fun getRepo(baseUrl: String): ExtensionRepo? { return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) } } - override suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? { + override suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? { return handler.awaitOneOrNull { extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo) } @@ -33,7 +33,7 @@ class ExtensionRepoRepositoryImpl( return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() } } - override suspend fun insertRepository( + override suspend fun insertRepo( baseUrl: String, name: String, shortName: String?, @@ -47,7 +47,7 @@ class ExtensionRepoRepositoryImpl( } } - override suspend fun upsertRepository( + override suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -61,7 +61,7 @@ class ExtensionRepoRepositoryImpl( } } - override suspend fun replaceRepository(newRepo: ExtensionRepo) { + override suspend fun replaceRepo(newRepo: ExtensionRepo) { handler.await { extension_reposQueries.replace( newRepo.baseUrl, @@ -73,7 +73,7 @@ class ExtensionRepoRepositoryImpl( } } - override suspend fun deleteRepository(baseUrl: String) { + override suspend fun deleteRepo(baseUrl: String) { return handler.await { extension_reposQueries.delete(baseUrl) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt index 2e6de446d..ec9ca6e72 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt @@ -1,37 +1,30 @@ package mihon.domain.extensionrepo.interactor -import eu.kanade.tachiyomi.network.NetworkHelper import logcat.LogPriority import mihon.domain.extensionrepo.exception.SaveExtensionRepoException import mihon.domain.extensionrepo.model.ExtensionRepo import mihon.domain.extensionrepo.repository.ExtensionRepoRepository import mihon.domain.extensionrepo.service.ExtensionRepoService -import okhttp3.OkHttpClient import tachiyomi.core.common.util.system.logcat class CreateExtensionRepo( - private val extensionRepoRepository: ExtensionRepoRepository, - private val networkHelper: NetworkHelper, + private val repository: ExtensionRepoRepository, + private val service: ExtensionRepoService, ) { private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() - private val client: OkHttpClient - get() = networkHelper.client - - private val extensionRepoService = ExtensionRepoService(client) - suspend fun await(repoUrl: String): Result { if (!repoUrl.matches(repoRegex)) { return Result.InvalidUrl } val baseUrl = repoUrl.removeSuffix("/index.min.json") - return extensionRepoService.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl + return service.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl } private suspend fun insert(repo: ExtensionRepo): Result { return try { - extensionRepoRepository.insertRepository( + repository.insertRepo( repo.baseUrl, repo.name, repo.shortName, @@ -57,12 +50,11 @@ class CreateExtensionRepo( */ @Suppress("ReturnCount") private suspend fun handleInsertionError(repo: ExtensionRepo): Result { - val repoExists = extensionRepoRepository.getRepository(repo.baseUrl) + val repoExists = repository.getRepo(repo.baseUrl) if (repoExists != null) { return Result.RepoAlreadyExists } - val matchingFingerprintRepo = - extensionRepoRepository.getRepositoryBySigningKeyFingerprint(repo.signingKeyFingerprint) + val matchingFingerprintRepo = repository.getRepoBySigningKeyFingerprint(repo.signingKeyFingerprint) if (matchingFingerprintRepo != null) { return Result.DuplicateFingerprint(matchingFingerprintRepo, repo) } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/DeleteExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/DeleteExtensionRepo.kt index 3be5c1ad9..4b4b678e1 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/DeleteExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/DeleteExtensionRepo.kt @@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.interactor import mihon.domain.extensionrepo.repository.ExtensionRepoRepository class DeleteExtensionRepo( - private val extensionRepoRepository: ExtensionRepoRepository, + private val repository: ExtensionRepoRepository, ) { suspend fun await(baseUrl: String) { - extensionRepoRepository.deleteRepository(baseUrl) + repository.deleteRepo(baseUrl) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepo.kt index e85bd6c01..25b919607 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepo.kt @@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.model.ExtensionRepo import mihon.domain.extensionrepo.repository.ExtensionRepoRepository class GetExtensionRepo( - private val extensionRepoRepository: ExtensionRepoRepository, + private val repository: ExtensionRepoRepository, ) { - fun subscribeAll(): Flow> = extensionRepoRepository.subscribeAll() + fun subscribeAll(): Flow> = repository.subscribeAll() - suspend fun getAll(): List = extensionRepoRepository.getAll() + suspend fun getAll(): List = repository.getAll() } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepoCount.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepoCount.kt index 6ca59f10b..a7c4e7c6d 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepoCount.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/GetExtensionRepoCount.kt @@ -3,7 +3,7 @@ package mihon.domain.extensionrepo.interactor import mihon.domain.extensionrepo.repository.ExtensionRepoRepository class GetExtensionRepoCount( - private val extensionRepoRepository: ExtensionRepoRepository, + private val repository: ExtensionRepoRepository, ) { - fun subscribe() = extensionRepoRepository.getCount() + fun subscribe() = repository.getCount() } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/ReplaceExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/ReplaceExtensionRepo.kt index 6543b8924..112ea701c 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/ReplaceExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/ReplaceExtensionRepo.kt @@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.model.ExtensionRepo import mihon.domain.extensionrepo.repository.ExtensionRepoRepository class ReplaceExtensionRepo( - private val extensionRepoRepository: ExtensionRepoRepository, + private val repository: ExtensionRepoRepository, ) { suspend fun await(repo: ExtensionRepo) { - extensionRepoRepository.replaceRepository(repo) + repository.replaceRepo(repo) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/UpdateExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/UpdateExtensionRepo.kt index 90e49307e..a393e69d5 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/UpdateExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/UpdateExtensionRepo.kt @@ -1,6 +1,5 @@ package mihon.domain.extensionrepo.interactor -import eu.kanade.tachiyomi.network.NetworkHelper import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope @@ -9,25 +8,23 @@ import mihon.domain.extensionrepo.repository.ExtensionRepoRepository import mihon.domain.extensionrepo.service.ExtensionRepoService class UpdateExtensionRepo( - private val extensionRepoRepository: ExtensionRepoRepository, - networkService: NetworkHelper, + private val repository: ExtensionRepoRepository, + private val service: ExtensionRepoService, ) { - private val extensionRepoService = ExtensionRepoService(networkService.client) - suspend fun awaitAll() = coroutineScope { - extensionRepoRepository.getAll() + repository.getAll() .map { async { await(it) } } .awaitAll() } suspend fun await(repo: ExtensionRepo) { - val newRepo = extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return + val newRepo = service.fetchRepoDetails(repo.baseUrl) ?: return if ( repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") || repo.signingKeyFingerprint == newRepo.signingKeyFingerprint ) { - extensionRepoRepository.upsertRepository(newRepo) + repository.upsertRepo(newRepo) } } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/repository/ExtensionRepoRepository.kt b/domain/src/main/java/mihon/domain/extensionrepo/repository/ExtensionRepoRepository.kt index 8551254be..47be56dcf 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/repository/ExtensionRepoRepository.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/repository/ExtensionRepoRepository.kt @@ -9,13 +9,13 @@ interface ExtensionRepoRepository { suspend fun getAll(): List - suspend fun getRepository(baseUrl: String): ExtensionRepo? + suspend fun getRepo(baseUrl: String): ExtensionRepo? - suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? + suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? fun getCount(): Flow - suspend fun insertRepository( + suspend fun insertRepo( baseUrl: String, name: String, shortName: String?, @@ -23,7 +23,7 @@ interface ExtensionRepoRepository { signingKeyFingerprint: String, ) - suspend fun upsertRepository( + suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -31,8 +31,8 @@ interface ExtensionRepoRepository { signingKeyFingerprint: String, ) - suspend fun upsertRepository(repo: ExtensionRepo) { - upsertRepository( + suspend fun upsertRepo(repo: ExtensionRepo) { + upsertRepo( baseUrl = repo.baseUrl, name = repo.name, shortName = repo.shortName, @@ -41,7 +41,7 @@ interface ExtensionRepoRepository { ) } - suspend fun replaceRepository(newRepo: ExtensionRepo) + suspend fun replaceRepo(newRepo: ExtensionRepo) - suspend fun deleteRepository(baseUrl: String) + suspend fun deleteRepo(baseUrl: String) } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt b/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt index a8522ac40..09a52d908 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt @@ -10,14 +10,12 @@ import mihon.domain.extensionrepo.model.ExtensionRepo import okhttp3.OkHttpClient import tachiyomi.core.common.util.lang.withIOContext import tachiyomi.core.common.util.system.logcat -import uy.kohesive.injekt.injectLazy class ExtensionRepoService( private val client: OkHttpClient, + private val json: Json, ) { - private val json: Json by injectLazy() - @Suppress("TooGenericExceptionCaught") suspend fun fetchRepoDetails( repo: String,