mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
Fixed selection not persisting throughout root requests
This commit is contained in:
parent
8515971ccf
commit
076e5cea3b
@ -33,7 +33,7 @@ open class SuRequestActivity : MagiskActivity<SuRequestViewModel, ActivityReques
|
||||
val action = intent.action
|
||||
|
||||
if (TextUtils.equals(action, GeneralReceiver.REQUEST)) {
|
||||
if (!viewModel.handleRequest(intent) {})
|
||||
if (!viewModel.handleRequest(intent))
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.hardware.fingerprint.FingerprintManager
|
||||
import android.os.CountDownTimer
|
||||
import android.text.TextUtils
|
||||
import com.skoumal.teanity.databinding.ComparableRvItem
|
||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||
import com.skoumal.teanity.util.DiffObservableList
|
||||
import com.skoumal.teanity.util.KObservableField
|
||||
import com.topjohnwu.magisk.BuildConfig
|
||||
@ -25,7 +26,9 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||
import com.topjohnwu.magisk.utils.FingerprintHelper
|
||||
import com.topjohnwu.magisk.utils.SuConnector
|
||||
import com.topjohnwu.magisk.utils.now
|
||||
import me.tatarka.bindingcollectionadapter2.BindingListViewAdapter
|
||||
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit.*
|
||||
|
||||
@ -46,11 +49,16 @@ class SuRequestViewModel(
|
||||
val canUseFingerprint = KObservableField(FingerprintHelper.useFingerprint())
|
||||
val selectedItemPosition = KObservableField(0)
|
||||
|
||||
val items = DiffObservableList(ComparableRvItem.callback)
|
||||
val itemBinding = ItemBinding.of<ComparableRvItem<*>> { binding, _, item ->
|
||||
private val items = DiffObservableList(ComparableRvItem.callback)
|
||||
private val itemBinding = ItemBinding.of<ComparableRvItem<*>> { binding, _, item ->
|
||||
item.bind(binding)
|
||||
}
|
||||
|
||||
val adapter = BindingListViewAdapter<ComparableRvItem<*>>(1).apply {
|
||||
itemBinding = this@SuRequestViewModel.itemBinding
|
||||
setItems(items)
|
||||
}
|
||||
|
||||
|
||||
var handler: ActionHandler? = null
|
||||
private var timer: CountDownTimer? = null
|
||||
@ -64,6 +72,10 @@ class SuRequestViewModel(
|
||||
resources.getStringArray(R.array.allow_timeout)
|
||||
.map { SpinnerRvItem(it) }
|
||||
.let { items.update(it) }
|
||||
|
||||
selectedItemPosition.addOnPropertyChangedCallback {
|
||||
Timber.e("Changed position to $it")
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePolicy(policy: MagiskPolicy?) {
|
||||
@ -96,7 +108,7 @@ class SuRequestViewModel(
|
||||
return false
|
||||
}
|
||||
|
||||
fun handleRequest(intent: Intent, createUICallback: () -> Unit): Boolean {
|
||||
fun handleRequest(intent: Intent): Boolean {
|
||||
val socketName = intent.getStringExtra("socket") ?: return false
|
||||
|
||||
val connector: SuConnector
|
||||
@ -126,9 +138,10 @@ class SuRequestViewModel(
|
||||
done()
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
override fun handleAction(action: Int) {
|
||||
val pos = selectedItemPosition.value
|
||||
timeoutPrefs.edit().putInt(policy?.packageName, pos).apply()
|
||||
timeoutPrefs.edit().putInt(policy?.packageName, pos).commit()
|
||||
handleAction(action, Config.Value.TIMEOUT_LIST[pos])
|
||||
}
|
||||
|
||||
@ -160,7 +173,7 @@ class SuRequestViewModel(
|
||||
return true
|
||||
}
|
||||
|
||||
when (Config.get<Any>(Config.Key.SU_AUTO_RESPONSE) as Int) {
|
||||
when (Config.get<Int>(Config.Key.SU_AUTO_RESPONSE)) {
|
||||
Config.Value.SU_AUTO_DENY -> {
|
||||
handler?.handleAction(Policy.DENY, 0)
|
||||
return true
|
||||
@ -171,7 +184,6 @@ class SuRequestViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
createUICallback()
|
||||
showUI()
|
||||
return true
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.topjohnwu.magisk.utils
|
||||
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.DrawableRes
|
||||
@ -115,7 +113,7 @@ fun setMovieBehavior(view: TextView, isMovieBehavior: Boolean, text: String) {
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("android:selectedItemPosition")
|
||||
/*@BindingAdapter("selection"*//*, "selectionAttrChanged", "adapter"*//*)
|
||||
fun setSelectedItemPosition(view: Spinner, position: Int) {
|
||||
view.setSelection(position)
|
||||
}
|
||||
@ -126,7 +124,7 @@ fun setSelectedItemPosition(view: Spinner, position: Int) {
|
||||
)
|
||||
fun getSelectedItemPosition(view: Spinner) = view.selectedItemPosition
|
||||
|
||||
@BindingAdapter("android:selectedItemPositionAttrChanged")
|
||||
@BindingAdapter("selectedItemPositionAttrChanged")
|
||||
fun setSelectedItemPositionListener(view: Spinner, listener: InverseBindingListener) {
|
||||
view.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onNothingSelected(p0: AdapterView<*>?) {
|
||||
@ -137,7 +135,7 @@ fun setSelectedItemPositionListener(view: Spinner, listener: InverseBindingListe
|
||||
listener.onChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@BindingAdapter("onTouch")
|
||||
fun setOnTouchListener(view: View, listener: View.OnTouchListener) {
|
||||
|
@ -89,15 +89,12 @@
|
||||
|
||||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
android:id="@+id/timeout"
|
||||
itemBinding="@{viewModel.itemBinding}"
|
||||
items="@{viewModel.items}"
|
||||
onTouch="@{() -> viewModel.spinnerTouched()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:selectedItemPosition="@={viewModel.selectedItemPosition}" />
|
||||
itemDropDownLayout="@{android.R.layout.simple_spinner_dropdown_item}"
|
||||
android:onClick="@{() -> viewModel.spinnerPressed()}"
|
||||
android:adapter="@{viewModel.adapter}"
|
||||
android:selection="@={viewModel.selectedItemPosition}" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/warning"
|
||||
|
Loading…
Reference in New Issue
Block a user