diff --git a/app/src/main/java/eu/kanade/domain/DomainModule.kt b/app/src/main/java/eu/kanade/domain/DomainModule.kt index ea6ee4c72..2410657ad 100644 --- a/app/src/main/java/eu/kanade/domain/DomainModule.kt +++ b/app/src/main/java/eu/kanade/domain/DomainModule.kt @@ -57,6 +57,7 @@ import mihon.domain.extensionrepo.manga.interactor.GetMangaExtensionRepoCount import mihon.domain.extensionrepo.manga.interactor.ReplaceMangaExtensionRepo import mihon.domain.extensionrepo.manga.interactor.UpdateMangaExtensionRepo import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository +import mihon.domain.extensionrepo.service.ExtensionRepoService import tachiyomi.data.category.anime.AnimeCategoryRepositoryImpl import tachiyomi.data.category.manga.MangaCategoryRepositoryImpl import tachiyomi.data.entries.anime.AnimeRepositoryImpl @@ -343,6 +344,8 @@ class DomainModule : InjektModule { addFactory { TrustAnimeExtension(get()) } addFactory { TrustMangaExtension(get()) } + addFactory { ExtensionRepoService(get(), get()) } + addSingletonFactory { AnimeExtensionRepoRepositoryImpl(get()) } addFactory { GetAnimeExtensionRepo(get()) } addFactory { GetAnimeExtensionRepoCount(get()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 620334206..a3d5011bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -618,7 +618,7 @@ object Migrations { coroutineScope.launchIO { for ((index, source) in sourcePreferences.animeExtensionRepos().get().withIndex()) { try { - animeExtensionRepoRepository.upsertRepository( + animeExtensionRepoRepository.upsertRepo( source, "Repo #${index + 1}", null, @@ -635,7 +635,7 @@ object Migrations { for ((index, source) in sourcePreferences.mangaExtensionRepos().get().withIndex()) { try { - mangaExtensionRepoRepository.upsertRepository( + mangaExtensionRepoRepository.upsertRepo( source, "Repo #${index + 1}", null, diff --git a/data/src/main/java/mihon/data/repository/anime/AnimeExtensionRepoRepositoryImpl.kt b/data/src/main/java/mihon/data/repository/anime/AnimeExtensionRepoRepositoryImpl.kt index 6d4f3d30f..687f6430d 100644 --- a/data/src/main/java/mihon/data/repository/anime/AnimeExtensionRepoRepositoryImpl.kt +++ b/data/src/main/java/mihon/data/repository/anime/AnimeExtensionRepoRepositoryImpl.kt @@ -19,11 +19,11 @@ class AnimeExtensionRepoRepositoryImpl( 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 AnimeExtensionRepoRepositoryImpl( 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 AnimeExtensionRepoRepositoryImpl( } } - override suspend fun upsertRepository( + override suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -61,7 +61,7 @@ class AnimeExtensionRepoRepositoryImpl( } } - override suspend fun replaceRepository(newRepo: ExtensionRepo) { + override suspend fun replaceRepo(newRepo: ExtensionRepo) { handler.await { extension_reposQueries.replace( newRepo.baseUrl, @@ -73,7 +73,7 @@ class AnimeExtensionRepoRepositoryImpl( } } - override suspend fun deleteRepository(baseUrl: String) { + override suspend fun deleteRepo(baseUrl: String) { return handler.await { extension_reposQueries.delete(baseUrl) } } diff --git a/data/src/main/java/mihon/data/repository/manga/MangaExtensionRepoRepositoryImpl.kt b/data/src/main/java/mihon/data/repository/manga/MangaExtensionRepoRepositoryImpl.kt index a58ba8101..37673243c 100644 --- a/data/src/main/java/mihon/data/repository/manga/MangaExtensionRepoRepositoryImpl.kt +++ b/data/src/main/java/mihon/data/repository/manga/MangaExtensionRepoRepositoryImpl.kt @@ -19,11 +19,11 @@ class MangaExtensionRepoRepositoryImpl( 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 MangaExtensionRepoRepositoryImpl( 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 MangaExtensionRepoRepositoryImpl( } } - override suspend fun upsertRepository( + override suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -61,7 +61,7 @@ class MangaExtensionRepoRepositoryImpl( } } - override suspend fun replaceRepository(newRepo: ExtensionRepo) { + override suspend fun replaceRepo(newRepo: ExtensionRepo) { handler.await { extension_reposQueries.replace( newRepo.baseUrl, @@ -73,7 +73,7 @@ class MangaExtensionRepoRepositoryImpl( } } - 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/anime/interactor/CreateAnimeExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/CreateAnimeExtensionRepo.kt index 480c8989b..d92c6812a 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/CreateAnimeExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/CreateAnimeExtensionRepo.kt @@ -1,37 +1,30 @@ package mihon.domain.extensionrepo.anime.interactor -import eu.kanade.tachiyomi.network.NetworkHelper import logcat.LogPriority import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository import mihon.domain.extensionrepo.exception.SaveExtensionRepoException import mihon.domain.extensionrepo.model.ExtensionRepo import mihon.domain.extensionrepo.service.ExtensionRepoService -import okhttp3.OkHttpClient import tachiyomi.core.common.util.system.logcat class CreateAnimeExtensionRepo( - private val extensionRepoRepository: AnimeExtensionRepoRepository, - private val networkHelper: NetworkHelper, + private val repository: AnimeExtensionRepoRepository, + 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 CreateAnimeExtensionRepo( */ @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/anime/interactor/DeleteAnimeExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/DeleteAnimeExtensionRepo.kt index 44bdbff73..22b1673ff 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/DeleteAnimeExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/DeleteAnimeExtensionRepo.kt @@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.anime.interactor import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository class DeleteAnimeExtensionRepo( - private val extensionRepoRepository: AnimeExtensionRepoRepository, + private val repository: AnimeExtensionRepoRepository, ) { suspend fun await(baseUrl: String) { - extensionRepoRepository.deleteRepository(baseUrl) + repository.deleteRepo(baseUrl) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepo.kt index f1bfa3d55..7b85f7bd7 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepo.kt @@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository import mihon.domain.extensionrepo.model.ExtensionRepo class GetAnimeExtensionRepo( - private val extensionRepoRepository: AnimeExtensionRepoRepository, + private val repository: AnimeExtensionRepoRepository, ) { - 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/anime/interactor/GetAnimeExtensionRepoCount.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepoCount.kt index a9e99018b..478f54964 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepoCount.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/GetAnimeExtensionRepoCount.kt @@ -3,7 +3,7 @@ package mihon.domain.extensionrepo.anime.interactor import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository class GetAnimeExtensionRepoCount( - private val extensionRepoRepository: AnimeExtensionRepoRepository, + private val repository: AnimeExtensionRepoRepository, ) { - fun subscribe() = extensionRepoRepository.getCount() + fun subscribe() = repository.getCount() } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/ReplaceAnimeExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/ReplaceAnimeExtensionRepo.kt index f6687a097..7ea2c60a7 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/ReplaceAnimeExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/ReplaceAnimeExtensionRepo.kt @@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository import mihon.domain.extensionrepo.model.ExtensionRepo class ReplaceAnimeExtensionRepo( - private val extensionRepoRepository: AnimeExtensionRepoRepository, + private val repository: AnimeExtensionRepoRepository, ) { suspend fun await(repo: ExtensionRepo) { - extensionRepoRepository.replaceRepository(repo) + repository.replaceRepo(repo) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/UpdateAnimeExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/UpdateAnimeExtensionRepo.kt index 06f41f72f..1d772581a 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/UpdateAnimeExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/interactor/UpdateAnimeExtensionRepo.kt @@ -1,6 +1,5 @@ package mihon.domain.extensionrepo.anime.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.model.ExtensionRepo import mihon.domain.extensionrepo.service.ExtensionRepoService class UpdateAnimeExtensionRepo( - private val extensionRepoRepository: AnimeExtensionRepoRepository, - networkService: NetworkHelper, + private val repository: AnimeExtensionRepoRepository, + 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/anime/repository/AnimeExtensionRepoRepository.kt b/domain/src/main/java/mihon/domain/extensionrepo/anime/repository/AnimeExtensionRepoRepository.kt index aef43a3a3..60088bebb 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/anime/repository/AnimeExtensionRepoRepository.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/anime/repository/AnimeExtensionRepoRepository.kt @@ -9,13 +9,13 @@ interface AnimeExtensionRepoRepository { 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 AnimeExtensionRepoRepository { signingKeyFingerprint: String, ) - suspend fun upsertRepository( + suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -31,8 +31,8 @@ interface AnimeExtensionRepoRepository { 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 AnimeExtensionRepoRepository { ) } - 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/manga/interactor/CreateMangaExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/CreateMangaExtensionRepo.kt index e5887f437..9fabf4265 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/CreateMangaExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/CreateMangaExtensionRepo.kt @@ -10,28 +10,23 @@ import okhttp3.OkHttpClient import tachiyomi.core.common.util.system.logcat class CreateMangaExtensionRepo( - private val extensionRepoRepository: MangaExtensionRepoRepository, - private val networkHelper: NetworkHelper, + private val repository: MangaExtensionRepoRepository, + 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 +52,11 @@ class CreateMangaExtensionRepo( */ @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/manga/interactor/DeleteMangaExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/DeleteMangaExtensionRepo.kt index 2a7fe46ee..c2a39d9a0 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/DeleteMangaExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/DeleteMangaExtensionRepo.kt @@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.manga.interactor import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository class DeleteMangaExtensionRepo( - private val extensionRepoRepository: MangaExtensionRepoRepository, + private val repository: MangaExtensionRepoRepository, ) { suspend fun await(baseUrl: String) { - extensionRepoRepository.deleteRepository(baseUrl) + repository.deleteRepo(baseUrl) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepo.kt index e2a436889..5f27cd382 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepo.kt @@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository import mihon.domain.extensionrepo.model.ExtensionRepo class GetMangaExtensionRepo( - private val extensionRepoRepository: MangaExtensionRepoRepository, + private val repository: MangaExtensionRepoRepository, ) { - 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/manga/interactor/GetMangaExtensionRepoCount.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepoCount.kt index cb5573653..5af679a03 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepoCount.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/GetMangaExtensionRepoCount.kt @@ -3,7 +3,7 @@ package mihon.domain.extensionrepo.manga.interactor import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository class GetMangaExtensionRepoCount( - private val extensionRepoRepository: MangaExtensionRepoRepository, + private val repository: MangaExtensionRepoRepository, ) { - fun subscribe() = extensionRepoRepository.getCount() + fun subscribe() = repository.getCount() } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/ReplaceMangaExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/ReplaceMangaExtensionRepo.kt index 348be2071..86aab464d 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/ReplaceMangaExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/ReplaceMangaExtensionRepo.kt @@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository import mihon.domain.extensionrepo.model.ExtensionRepo class ReplaceMangaExtensionRepo( - private val extensionRepoRepository: MangaExtensionRepoRepository, + private val repository: MangaExtensionRepoRepository, ) { suspend fun await(repo: ExtensionRepo) { - extensionRepoRepository.replaceRepository(repo) + repository.replaceRepo(repo) } } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/UpdateMangaExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/UpdateMangaExtensionRepo.kt index bf0c9b471..d5e1a1c14 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/UpdateMangaExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/interactor/UpdateMangaExtensionRepo.kt @@ -1,6 +1,5 @@ package mihon.domain.extensionrepo.manga.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.model.ExtensionRepo import mihon.domain.extensionrepo.service.ExtensionRepoService class UpdateMangaExtensionRepo( - private val extensionRepoRepository: MangaExtensionRepoRepository, - networkService: NetworkHelper, + private val repository: MangaExtensionRepoRepository, + 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/manga/repository/MangaExtensionRepoRepository.kt b/domain/src/main/java/mihon/domain/extensionrepo/manga/repository/MangaExtensionRepoRepository.kt index 187ec0549..96f016111 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/manga/repository/MangaExtensionRepoRepository.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/manga/repository/MangaExtensionRepoRepository.kt @@ -9,13 +9,13 @@ interface MangaExtensionRepoRepository { 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 MangaExtensionRepoRepository { signingKeyFingerprint: String, ) - suspend fun upsertRepository( + suspend fun upsertRepo( baseUrl: String, name: String, shortName: String?, @@ -31,8 +31,8 @@ interface MangaExtensionRepoRepository { 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 MangaExtensionRepoRepository { ) } - 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..e3c97a0bd 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt @@ -14,10 +14,9 @@ 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,