From 0245e135919ac77064a2fbf26821ce742b3cbf9e Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 12 May 2019 18:00:58 +0200 Subject: [PATCH] Removed usage of old database object --- .../magisk/ui/surequest/SuRequestViewModel.kt | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index a3f67743b..b5abb974a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -15,9 +15,11 @@ import com.skoumal.teanity.util.KObservableField import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.data.database.MagiskDB +import com.topjohnwu.magisk.data.repository.AppRepository +import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.Policy import com.topjohnwu.magisk.model.entity.recycler.SpinnerRvItem +import com.topjohnwu.magisk.model.entity.toPolicy import com.topjohnwu.magisk.model.events.DieEvent import com.topjohnwu.magisk.ui.base.MagiskViewModel import com.topjohnwu.magisk.utils.FingerprintHelper @@ -29,7 +31,7 @@ import java.util.concurrent.TimeUnit.* class SuRequestViewModel( private val packageManager: PackageManager, - private val database: MagiskDB, + private val appRepo: AppRepository, private val timeoutPrefs: SharedPreferences, private val resources: Resources ) : MagiskViewModel() { @@ -52,7 +54,7 @@ class SuRequestViewModel( var handler: ActionHandler? = null private var timer: CountDownTimer? = null - private var policy: Policy? = null + private var policy: MagiskPolicy? = null set(value) { field = value updatePolicy(value) @@ -64,10 +66,10 @@ class SuRequestViewModel( .let { items.update(it) } } - private fun updatePolicy(policy: Policy?) { + private fun updatePolicy(policy: MagiskPolicy?) { policy ?: return - icon.value = policy.info.loadIcon(packageManager) + icon.value = policy.applicationInfo.loadIcon(packageManager) title.value = policy.appName packageName.value = policy.packageName @@ -107,8 +109,8 @@ class SuRequestViewModel( } val bundle = connector.readSocketInput() val uid = bundle.getString("uid")?.toIntOrNull() ?: return false - database.clearOutdated() - policy = database.getPolicy(uid) ?: Policy(uid, packageManager) + appRepo.deleteOutdated().blockingGet() // wrong! + policy = appRepo.fetch(uid).blockingGet() ?: uid.toPolicy(packageManager) } catch (e: IOException) { e.printStackTrace() return false @@ -130,18 +132,18 @@ class SuRequestViewModel( } override fun handleAction(action: Int, time: Int) { - policy?.apply { - policy = action - if (time >= 0) { - until = if (time == 0) { - 0 - } else { - MILLISECONDS.toSeconds(now) + MINUTES.toSeconds(time.toLong()) - } - database.updatePolicy(this) + val until = if (time >= 0) { + if (time == 0) { + 0 + } else { + MILLISECONDS.toSeconds(now) + MINUTES.toSeconds(time.toLong()) } + } else { + policy?.until ?: 0 + } + policy = policy?.copy(policy = action, until = until)?.apply { + appRepo.update(this).blockingGet() } - policy?.policy = action handleAction() }