Remove more code using RxJava

This commit is contained in:
topjohnwu
2020-07-10 04:19:18 -07:00
parent f7a650b9a4
commit 6348d0a6fb
31 changed files with 309 additions and 429 deletions
@@ -3,6 +3,8 @@ package com.topjohnwu.magisk.data.database
import androidx.room.*
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.model.module.Repo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@Database(version = 6, entities = [Repo::class, RepoEtag::class], exportSchema = false)
abstract class RepoDatabase : RoomDatabase() {
@@ -26,7 +28,7 @@ abstract class RepoDao(private val db: RepoDatabase) {
set(value) = addEtagRaw(RepoEtag(0, value))
get() = etagRaw()?.key.orEmpty()
fun clear() = db.clearAllTables()
suspend fun clear() = withContext(Dispatchers.IO) { db.clearAllTables() }
@Query("SELECT * FROM repos ORDER BY last_update DESC")
protected abstract fun getReposDateOrder(): List<Repo>
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.data.network
import com.topjohnwu.magisk.core.Const
import com.topjohnwu.magisk.core.model.UpdateInfo
import com.topjohnwu.magisk.core.tasks.GithubRepoInfo
import io.reactivex.Single
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.*
@@ -26,18 +25,15 @@ interface GithubRawServices {
@GET("$MAGISK_FILES/{$REVISION}/snet.jar")
@Streaming
fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): Single<ResponseBody>
suspend fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): ResponseBody
@GET("$MAGISK_FILES/{$REVISION}/bootctl")
@Streaming
fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): Single<ResponseBody>
suspend fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): ResponseBody
@GET("$MAGISK_MASTER/scripts/module_installer.sh")
@Streaming
fun fetchInstaller(): Single<ResponseBody>
@GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}")
fun fetchModuleInfo(@Path(MODULE) id: String, @Path(FILE) file: String): Single<String>
suspend fun fetchInstaller(): ResponseBody
@GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}")
suspend fun fetchModuleFile(@Path(MODULE) id: String, @Path(FILE) file: String): String
@@ -50,10 +46,10 @@ interface GithubRawServices {
* */
@GET
@Streaming
fun fetchFile(@Url url: String): Single<ResponseBody>
suspend fun fetchFile(@Url url: String): ResponseBody
@GET
fun fetchString(@Url url: String): Single<String>
suspend fun fetchString(@Url url: String): String
companion object {
@@ -20,8 +20,6 @@ class MagiskRepository(
private val packageManager: PackageManager
) {
fun fetchSafetynet() = apiRaw.fetchSafetynet()
suspend fun fetchUpdate() = try {
var info = when (Config.updateChannel) {
Config.Value.DEFAULT_CHANNEL, Config.Value.STABLE_CHANNEL -> apiRaw.fetchStableUpdate()
@@ -7,9 +7,10 @@ class StringRepository(
private val api: GithubRawServices
) {
fun getString(url: String) = api.fetchString(url)
suspend fun getString(url: String) = api.fetchString(url)
suspend fun getMetadata(repo: Repo) = api.fetchModuleFile(repo.id, "module.prop")
fun getReadme(repo: Repo) = api.fetchModuleInfo(repo.id, "README.md")
suspend fun getReadme(repo: Repo) = api.fetchModuleFile(repo.id, "README.md")
}