diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt index 470edb3e7..9407c2f36 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQuery.kt @@ -1,5 +1,5 @@ package com.topjohnwu.magisk.data.database.base -data class MagiskQuery(private val _query: String) { - val query = "magisk --sqlite '$_query'" +inline class MagiskQuery(private val _query: String) { + val query get() = "magisk --sqlite '$_query'" } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt index 788113b51..0c95bd6f4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt @@ -82,7 +82,7 @@ open class Insert : MagiskQueryBuilder { override lateinit var table: String private val keys get() = _values.keys.joinToString(",") - private val values get() = _values.values.joinToString(",") + private val values get() = _values.values.joinToString(",") { "\"$it\"" } private var _values: Map = mapOf() fun values(vararg pairs: Pair) { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt index 6111325f3..11938a238 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/MagiskPolicy.kt @@ -59,7 +59,7 @@ fun MagiskPolicy.toMap() = mapOf( "until" to until, "logging" to if (logging) 1 else 0, "notification" to if (notification) 1 else 0 -).mapValues { it.toString() } +).mapValues { it.value.toString() } @Throws(PackageManager.NameNotFoundException::class) fun Map.toPolicy(pm: PackageManager): MagiskPolicy { diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt index a713ba389..764fbd1cf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt @@ -26,6 +26,13 @@ class PolicyRvItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvIte private val rxBus: RxBus by inject() + private val currentStateItem + get() = item.copy( + policy = if (isEnabled.value) Policy.ALLOW else Policy.DENY, + notification = shouldNotify.value, + logging = shouldLog.value + ) + init { isEnabled.addOnPropertyChangedCallback { it ?: return@addOnPropertyChangedCallback @@ -33,11 +40,11 @@ class PolicyRvItem(val item: MagiskPolicy, val icon: Drawable) : ComparableRvIte } shouldNotify.addOnPropertyChangedCallback { it ?: return@addOnPropertyChangedCallback - rxBus.post(PolicyUpdateEvent.Notification(this@PolicyRvItem, shouldNotify.value)) + rxBus.post(PolicyUpdateEvent.Notification(currentStateItem)) } shouldLog.addOnPropertyChangedCallback { it ?: return@addOnPropertyChangedCallback - rxBus.post(PolicyUpdateEvent.Log(this@PolicyRvItem, shouldLog.value)) + rxBus.post(PolicyUpdateEvent.Log(currentStateItem)) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt index b0c1aebbe..5f6335bfe 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/RxEvents.kt @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.model.events import com.skoumal.teanity.rxbus.RxBus +import com.topjohnwu.magisk.model.entity.MagiskPolicy import com.topjohnwu.magisk.model.entity.recycler.HideProcessRvItem import com.topjohnwu.magisk.model.entity.recycler.ModuleRvItem import com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem @@ -8,9 +9,9 @@ import com.topjohnwu.magisk.model.entity.recycler.PolicyRvItem class HideProcessEvent(val item: HideProcessRvItem) : RxBus.Event class PolicyEnableEvent(val item: PolicyRvItem, val enable: Boolean) : RxBus.Event -sealed class PolicyUpdateEvent(val item: PolicyRvItem) : RxBus.Event { - class Notification(item: PolicyRvItem, val shouldNotify: Boolean) : PolicyUpdateEvent(item) - class Log(item: PolicyRvItem, val shouldLog: Boolean) : PolicyUpdateEvent(item) +sealed class PolicyUpdateEvent(val item: MagiskPolicy) : RxBus.Event { + class Notification(item: MagiskPolicy) : PolicyUpdateEvent(item) + class Log(item: MagiskPolicy) : PolicyUpdateEvent(item) } class ModuleUpdatedEvent(val item: ModuleRvItem) : RxBus.Event diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 78dcf930f..6f555b0fb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -85,13 +85,13 @@ class SuperuserViewModel( } private fun updatePolicy(it: PolicyUpdateEvent) = when (it) { - is PolicyUpdateEvent.Notification -> updatePolicy(it.item.item.copy(notification = it.shouldNotify)) { + is PolicyUpdateEvent.Notification -> updatePolicy(it.item) { val textId = if (it.notification) R.string.su_snack_notif_on else R.string.su_snack_notif_off val text = resources.getString(textId).format(it.appName) SnackbarEvent(text).publish() } - is PolicyUpdateEvent.Log -> updatePolicy(it.item.item.copy(logging = it.shouldLog)) { + is PolicyUpdateEvent.Log -> updatePolicy(it.item) { val textId = if (it.logging) R.string.su_snack_log_on else R.string.su_snack_log_off val text = resources.getString(textId).format(it.appName)