Removed events from modules / replaced with retrofit/rx

This commit is contained in:
Viktor De Pasquale
2019-05-07 15:41:56 +02:00
parent 10e903c9fc
commit 7c755a3991
17 changed files with 116 additions and 223 deletions

View File

@@ -1,5 +1,6 @@
package com.topjohnwu.magisk.data.network
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.model.entity.GithubRepo
import io.reactivex.Single
import retrofit2.http.GET
@@ -12,7 +13,11 @@ interface GithubApiServices {
fun fetchRepos(
@Query("page") page: Int,
@Query("per_page") count: Int = REPOS_PER_PAGE,
@Query("sort") sortOrder: String = "pushed"
@Query("sort") sortOrder: String = when (Config.get<Int>(Config.Key.REPO_ORDER)) {
Config.Value.ORDER_DATE -> "updated"
Config.Value.ORDER_NAME -> "full_name"
else -> "updated"
}
): Single<List<GithubRepo>>
companion object {

View File

@@ -48,7 +48,7 @@ interface GithubRawApiServices {
@GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}")
@Streaming
fun fetchFile(id: String, file: String): Single<ResponseBody>
fun fetchFile(@Path(MODULE) id: String, @Path(FILE) file: String): Single<ResponseBody>
//endregion

View File

@@ -6,6 +6,7 @@ import com.topjohnwu.magisk.data.network.GithubRawApiServices
import com.topjohnwu.magisk.data.network.GithubServices
import com.topjohnwu.magisk.model.entity.GithubRepo
import com.topjohnwu.magisk.model.entity.toRepository
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.writeToFile
import com.topjohnwu.magisk.utils.writeToString
import io.reactivex.Single
@@ -18,9 +19,16 @@ class ModuleRepository(
) {
fun fetchModules() = fetchAllRepos()
.flattenAsFlowable { it }
.flatMapSingle { fetchProperties(it.name, it.updatedAtMillis) }
.toList()
.map {
it.mapNotNull {
runCatching {
fetchProperties(it.name, it.updatedAtMillis).blockingGet()
}.getOrNull()
}
}
fun fetchInstalledModules() = Single.fromCallable { Utils.loadModulesLeanback() }
.map { it.values.toList() }
fun fetchInstallFile(module: String) = apiRaw
.fetchFile(module, FILE_INSTALL_SH)