mirror of
https://github.com/revanced/revanced-manager-compose.git
synced 2025-04-30 06:14:25 +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
f26bb47bc4
commit
a97dcd4a22
@ -1,13 +1,13 @@
|
|||||||
package app.revanced.manager.compose.di
|
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.network.api.ManagerAPI
|
||||||
import app.revanced.manager.compose.patcher.data.repository.PatchesRepository
|
import app.revanced.manager.compose.patcher.data.repository.PatchesRepository
|
||||||
import org.koin.core.module.dsl.singleOf
|
import org.koin.core.module.dsl.singleOf
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val repositoryModule = module {
|
val repositoryModule = module {
|
||||||
singleOf(::ReVancedRepositoryImpl)
|
singleOf(::ReVancedRepository)
|
||||||
singleOf(::ManagerAPI)
|
singleOf(::ManagerAPI)
|
||||||
singleOf(::PatchesRepository)
|
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.HttpService
|
||||||
import app.revanced.manager.compose.network.service.ReVancedService
|
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.core.module.dsl.singleOf
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
@ -10,7 +9,7 @@ val serviceModule = module {
|
|||||||
fun provideReVancedService(
|
fun provideReVancedService(
|
||||||
client: HttpService,
|
client: HttpService,
|
||||||
): ReVancedService {
|
): ReVancedService {
|
||||||
return ReVancedServiceImpl(
|
return ReVancedService(
|
||||||
client = client,
|
client = client,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,13 @@
|
|||||||
package app.revanced.manager.compose.domain.repository
|
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.service.ReVancedService
|
||||||
import app.revanced.manager.compose.network.utils.APIResponse
|
|
||||||
|
|
||||||
interface ReVancedRepository {
|
class ReVancedRepository(
|
||||||
suspend fun getAssets(): APIResponse<ReVancedReleases>
|
|
||||||
|
|
||||||
suspend fun getContributors(): APIResponse<ReVancedRepositories>
|
|
||||||
|
|
||||||
suspend fun findAsset(repo: String, file: String): PatchesAsset
|
|
||||||
}
|
|
||||||
|
|
||||||
class ReVancedRepositoryImpl(
|
|
||||||
private val service: ReVancedService
|
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.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
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.ghIntegrations
|
||||||
import app.revanced.manager.compose.util.ghPatches
|
import app.revanced.manager.compose.util.ghPatches
|
||||||
import app.revanced.manager.compose.util.tag
|
import app.revanced.manager.compose.util.tag
|
||||||
@ -21,7 +21,7 @@ import java.io.File
|
|||||||
class ManagerAPI(
|
class ManagerAPI(
|
||||||
private val app: Application,
|
private val app: Application,
|
||||||
private val client: HttpClient,
|
private val client: HttpClient,
|
||||||
private val revancedRepository: ReVancedRepositoryImpl
|
private val revancedRepository: ReVancedRepository
|
||||||
) {
|
) {
|
||||||
var downloadProgress: Float? by mutableStateOf(null)
|
var downloadProgress: Float? by mutableStateOf(null)
|
||||||
|
|
||||||
|
@ -11,18 +11,10 @@ import io.ktor.client.request.*
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
interface ReVancedService {
|
class ReVancedService(
|
||||||
suspend fun getAssets(): APIResponse<ReVancedReleases>
|
|
||||||
|
|
||||||
suspend fun getContributors(): APIResponse<ReVancedRepositories>
|
|
||||||
|
|
||||||
suspend fun findAsset(repo: String, file: String): PatchesAsset
|
|
||||||
}
|
|
||||||
|
|
||||||
class ReVancedServiceImpl(
|
|
||||||
private val client: HttpService,
|
private val client: HttpService,
|
||||||
) : ReVancedService {
|
) {
|
||||||
override suspend fun getAssets(): APIResponse<ReVancedReleases> {
|
suspend fun getAssets(): APIResponse<ReVancedReleases> {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
client.request {
|
client.request {
|
||||||
url("$apiUrl/tools")
|
url("$apiUrl/tools")
|
||||||
@ -30,7 +22,7 @@ class ReVancedServiceImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getContributors(): APIResponse<ReVancedRepositories> {
|
suspend fun getContributors(): APIResponse<ReVancedRepositories> {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
client.request {
|
client.request {
|
||||||
url("$apiUrl/contributors")
|
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 releases = getAssets().getOrNull() ?: throw Exception("Cannot retrieve assets")
|
||||||
val asset = releases.tools.find { asset ->
|
val asset = releases.tools.find { asset ->
|
||||||
(asset.name.contains(file) && asset.repository.contains(repo))
|
(asset.name.contains(file) && asset.repository.contains(repo))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user