mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
refactor(net apis): remove unnecessary interfaces
Having interfaces like that is only really useful if you have unit tests, which we don't. Other similar compose projects don't make interfaces either. Not having them is more readable.
This commit is contained in:
parent
32839656f8
commit
ad14818de8
@ -1,13 +1,13 @@
|
||||
package app.revanced.manager.compose.di
|
||||
|
||||
import app.revanced.manager.compose.domain.repository.ReVancedRepositoryImpl
|
||||
import app.revanced.manager.compose.domain.repository.ReVancedRepository
|
||||
import app.revanced.manager.compose.network.api.ManagerAPI
|
||||
import app.revanced.manager.compose.patcher.data.repository.PatchesRepository
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.module
|
||||
|
||||
val repositoryModule = module {
|
||||
singleOf(::ReVancedRepositoryImpl)
|
||||
singleOf(::ReVancedRepository)
|
||||
singleOf(::ManagerAPI)
|
||||
singleOf(::PatchesRepository)
|
||||
}
|
@ -2,7 +2,6 @@ package app.revanced.manager.compose.di
|
||||
|
||||
import app.revanced.manager.compose.network.service.HttpService
|
||||
import app.revanced.manager.compose.network.service.ReVancedService
|
||||
import app.revanced.manager.compose.network.service.ReVancedServiceImpl
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.module
|
||||
|
||||
@ -10,7 +9,7 @@ val serviceModule = module {
|
||||
fun provideReVancedService(
|
||||
client: HttpService,
|
||||
): ReVancedService {
|
||||
return ReVancedServiceImpl(
|
||||
return ReVancedService(
|
||||
client = client,
|
||||
)
|
||||
}
|
||||
|
@ -1,25 +1,13 @@
|
||||
package app.revanced.manager.compose.domain.repository
|
||||
|
||||
import app.revanced.manager.compose.network.api.PatchesAsset
|
||||
import app.revanced.manager.compose.network.dto.ReVancedReleases
|
||||
import app.revanced.manager.compose.network.dto.ReVancedRepositories
|
||||
import app.revanced.manager.compose.network.service.ReVancedService
|
||||
import app.revanced.manager.compose.network.utils.APIResponse
|
||||
|
||||
interface ReVancedRepository {
|
||||
suspend fun getAssets(): APIResponse<ReVancedReleases>
|
||||
|
||||
suspend fun getContributors(): APIResponse<ReVancedRepositories>
|
||||
|
||||
suspend fun findAsset(repo: String, file: String): PatchesAsset
|
||||
}
|
||||
|
||||
class ReVancedRepositoryImpl(
|
||||
class ReVancedRepository(
|
||||
private val service: ReVancedService
|
||||
) : ReVancedRepository {
|
||||
override suspend fun getAssets() = service.getAssets()
|
||||
) {
|
||||
suspend fun getAssets() = service.getAssets()
|
||||
|
||||
override suspend fun getContributors() = service.getContributors()
|
||||
suspend fun getContributors() = service.getContributors()
|
||||
|
||||
override suspend fun findAsset(repo: String, file: String) = service.findAsset(repo, file)
|
||||
suspend fun findAsset(repo: String, file: String) = service.findAsset(repo, file)
|
||||
}
|
@ -5,7 +5,7 @@ import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import app.revanced.manager.compose.domain.repository.ReVancedRepositoryImpl
|
||||
import app.revanced.manager.compose.domain.repository.ReVancedRepository
|
||||
import app.revanced.manager.compose.util.ghIntegrations
|
||||
import app.revanced.manager.compose.util.ghPatches
|
||||
import app.revanced.manager.compose.util.tag
|
||||
@ -21,7 +21,7 @@ import java.io.File
|
||||
class ManagerAPI(
|
||||
private val app: Application,
|
||||
private val client: HttpClient,
|
||||
private val revancedRepository: ReVancedRepositoryImpl
|
||||
private val revancedRepository: ReVancedRepository
|
||||
) {
|
||||
var downloadProgress: Float? by mutableStateOf(null)
|
||||
|
||||
|
@ -11,18 +11,10 @@ import io.ktor.client.request.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
interface ReVancedService {
|
||||
suspend fun getAssets(): APIResponse<ReVancedReleases>
|
||||
|
||||
suspend fun getContributors(): APIResponse<ReVancedRepositories>
|
||||
|
||||
suspend fun findAsset(repo: String, file: String): PatchesAsset
|
||||
}
|
||||
|
||||
class ReVancedServiceImpl(
|
||||
class ReVancedService(
|
||||
private val client: HttpService,
|
||||
) : ReVancedService {
|
||||
override suspend fun getAssets(): APIResponse<ReVancedReleases> {
|
||||
) {
|
||||
suspend fun getAssets(): APIResponse<ReVancedReleases> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
client.request {
|
||||
url("$apiUrl/tools")
|
||||
@ -30,7 +22,7 @@ class ReVancedServiceImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getContributors(): APIResponse<ReVancedRepositories> {
|
||||
suspend fun getContributors(): APIResponse<ReVancedRepositories> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
client.request {
|
||||
url("$apiUrl/contributors")
|
||||
@ -38,7 +30,7 @@ class ReVancedServiceImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun findAsset(repo: String, file: String): PatchesAsset {
|
||||
suspend fun findAsset(repo: String, file: String): PatchesAsset {
|
||||
val releases = getAssets().getOrNull() ?: throw Exception("Cannot retrieve assets")
|
||||
val asset = releases.tools.find { asset ->
|
||||
(asset.name.contains(file) && asset.repository.contains(repo))
|
||||
|
Loading…
Reference in New Issue
Block a user