Move setContentView out of onCreate
This commit is contained in:
parent
e66b0bf3b2
commit
d7f7508fa2
@ -48,6 +48,9 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setTheme(themeRes)
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
startObserveEvents()
|
||||
|
||||
// We need to set the window background explicitly since for whatever reason it's not
|
||||
// propagated upstream
|
||||
@ -55,16 +58,6 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
|
||||
.use { it.getDrawable(0) }
|
||||
.also { window.setBackgroundDrawable(it) }
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
startObserveEvents()
|
||||
|
||||
binding = DataBindingUtil.setContentView<Binding>(this, layoutRes).also {
|
||||
it.setVariable(BR.viewModel, viewModel)
|
||||
it.lifecycleOwner = this
|
||||
}
|
||||
|
||||
ensureInsets()
|
||||
|
||||
directionsDispatcher.observe(this) {
|
||||
it?.navigate()
|
||||
// we don't want the directions to be re-dispatched, so we preemptively set them to null
|
||||
@ -74,6 +67,15 @@ abstract class BaseUIActivity<VM : BaseViewModel, Binding : ViewDataBinding> :
|
||||
}
|
||||
}
|
||||
|
||||
fun setContentView() {
|
||||
binding = DataBindingUtil.setContentView<Binding>(this, layoutRes).also {
|
||||
it.setVariable(BR.viewModel, viewModel)
|
||||
it.lifecycleOwner = this
|
||||
}
|
||||
|
||||
ensureInsets()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
viewModel.requestRefresh()
|
||||
|
@ -51,6 +51,12 @@ class DieEvent : ViewEvent(), ActivityExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
class ShowUIEvent : ViewEvent(), ActivityExecutor {
|
||||
override fun invoke(activity: BaseUIActivity<*, *>) {
|
||||
activity.setContentView()
|
||||
}
|
||||
}
|
||||
|
||||
class RecreateEvent : ViewEvent(), ActivityExecutor {
|
||||
override fun invoke(activity: BaseUIActivity<*, *>) {
|
||||
activity.recreate()
|
||||
|
@ -14,7 +14,6 @@ import androidx.core.view.setPadding
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.navigation.NavDirections
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.topjohnwu.magisk.BuildConfig
|
||||
import com.topjohnwu.magisk.MainDirections
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.arch.BaseUIActivity
|
||||
@ -60,6 +59,7 @@ open class MainActivity : BaseUIActivity<MainViewModel, ActivityMainMd2Binding>(
|
||||
return
|
||||
}
|
||||
|
||||
setContentView()
|
||||
showUnsupportedMessage()
|
||||
askForHomeShortcut()
|
||||
|
||||
|
@ -18,9 +18,9 @@ import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY
|
||||
import com.topjohnwu.magisk.core.su.SuRequestHandler
|
||||
import com.topjohnwu.magisk.core.utils.BiometricHelper
|
||||
import com.topjohnwu.magisk.events.DieEvent
|
||||
import com.topjohnwu.magisk.events.ShowUIEvent
|
||||
import com.topjohnwu.magisk.ui.superuser.SpinnerRvItem
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
import com.topjohnwu.superuser.internal.UiThreadHandler
|
||||
import kotlinx.coroutines.launch
|
||||
import me.tatarka.bindingcollectionadapter2.BindingListViewAdapter
|
||||
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
||||
@ -33,26 +33,14 @@ class SuRequestViewModel(
|
||||
private val res: Resources
|
||||
) : BaseViewModel() {
|
||||
|
||||
@get:Bindable
|
||||
var icon: Drawable? = null
|
||||
set(value) = set(value, field, { field = it }, BR.icon)
|
||||
|
||||
@get:Bindable
|
||||
var title = ""
|
||||
set(value) = set(value, field, { field = it }, BR.title)
|
||||
|
||||
@get:Bindable
|
||||
var packageName = ""
|
||||
set(value) = set(value, field, { field = it }, BR.packageName)
|
||||
lateinit var icon: Drawable
|
||||
lateinit var title: String
|
||||
lateinit var packageName: String
|
||||
|
||||
@get:Bindable
|
||||
var denyText = res.getString(R.string.deny)
|
||||
set(value) = set(value, field, { field = it }, BR.denyText)
|
||||
|
||||
@get:Bindable
|
||||
var warningText = res.getString(R.string.su_warning)
|
||||
set(value) = set(value, field, { field = it }, BR.warningText)
|
||||
|
||||
@get:Bindable
|
||||
var selectedItemPosition = 0
|
||||
set(value) = set(value, field, { field = it }, BR.selectedItemPosition)
|
||||
@ -124,14 +112,14 @@ class SuRequestViewModel(
|
||||
icon = policy.applicationInfo.loadIcon(pm)
|
||||
title = policy.appName
|
||||
packageName = policy.packageName
|
||||
UiThreadHandler.handler.post {
|
||||
// Delay is required to properly do selection
|
||||
selectedItemPosition = timeoutPrefs.getInt(policy.packageName, 0)
|
||||
}
|
||||
selectedItemPosition = timeoutPrefs.getInt(policy.packageName, 0)
|
||||
|
||||
// Set timer
|
||||
val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong())
|
||||
timer = SuTimer(millis, 1000).apply { start() }
|
||||
|
||||
// Actually show the UI
|
||||
ShowUIEvent().publish()
|
||||
}
|
||||
|
||||
private inner class SuTimer(
|
||||
|
@ -109,7 +109,7 @@
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="@dimen/l1"
|
||||
android:gravity="center"
|
||||
android:text="@{viewModel.warningText}"
|
||||
android:text="@string/su_warning"
|
||||
android:textAppearance="@style/AppearanceFoundation.Body"
|
||||
android:textColor="?colorError"
|
||||
android:textStyle="bold"
|
||||
|
Loading…
Reference in New Issue
Block a user