mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-28 08:57:40 +00:00
Don't always refresh on network state change
This commit is contained in:
parent
20124fe410
commit
482a5b991b
@ -21,9 +21,7 @@ import com.topjohnwu.magisk.events.PermissionEvent
|
||||
import com.topjohnwu.magisk.events.SnackbarEvent
|
||||
import kotlinx.coroutines.Job
|
||||
|
||||
abstract class BaseViewModel(
|
||||
initialState: State = State.LOADING
|
||||
) : ViewModel(), ObservableHost {
|
||||
abstract class BaseViewModel : ViewModel(), ObservableHost {
|
||||
|
||||
override var callbacks: PropertyChangeRegistry? = null
|
||||
|
||||
@ -40,7 +38,7 @@ abstract class BaseViewModel(
|
||||
|
||||
val viewEvents: LiveData<ViewEvent> get() = _viewEvents
|
||||
|
||||
var state= initialState
|
||||
var state = State.LOADING
|
||||
set(value) = set(value, field, { field = it }, BR.loading, BR.loaded, BR.loadFailed)
|
||||
|
||||
private val _viewEvents = MutableLiveData<ViewEvent>()
|
||||
@ -60,6 +58,8 @@ abstract class BaseViewModel(
|
||||
|
||||
protected open fun refresh(): Job? = null
|
||||
|
||||
open fun onNetworkChanged(network: Boolean) {}
|
||||
|
||||
fun withPermission(permission: String, callback: (Boolean) -> Unit) {
|
||||
PermissionEvent(permission, callback).publish()
|
||||
}
|
||||
|
@ -17,12 +17,8 @@ interface ViewModelHolder : LifecycleOwner, ViewModelStoreOwner {
|
||||
val viewModel: BaseViewModel
|
||||
|
||||
fun startObserveLiveData() {
|
||||
viewModel.viewEvents.observe(this) {
|
||||
onEventDispatched(it)
|
||||
}
|
||||
Info.isConnected.observe(this) {
|
||||
viewModel.requestRefresh()
|
||||
}
|
||||
viewModel.viewEvents.observe(this, this::onEventDispatched)
|
||||
Info.isConnected.observe(this, viewModel::onNetworkChanged)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,13 +104,9 @@ class HomeViewModel(
|
||||
ensureEnv()
|
||||
}
|
||||
|
||||
val showTest = false
|
||||
|
||||
fun onTestPressed() = object : ViewEvent(), ActivityExecutor {
|
||||
override fun invoke(activity: UIActivity<*>) {
|
||||
/* Entry point to trigger test events within the app */
|
||||
}
|
||||
}.publish()
|
||||
override fun onNetworkChanged(network: Boolean) {
|
||||
requestRefresh()
|
||||
}
|
||||
|
||||
fun onProgressUpdate(progress: Float, subject: Subject) {
|
||||
if (subject is App)
|
||||
@ -151,4 +147,10 @@ class HomeViewModel(
|
||||
checkedEnv = true
|
||||
}
|
||||
|
||||
val showTest = false
|
||||
fun onTestPressed() = object : ViewEvent(), ActivityExecutor {
|
||||
override fun invoke(activity: UIActivity<*>) {
|
||||
/* Entry point to trigger test events within the app */
|
||||
}
|
||||
}.publish()
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ class ModuleViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNetworkChanged(network: Boolean) {
|
||||
requestRefresh()
|
||||
}
|
||||
|
||||
private suspend fun loadInstalled() {
|
||||
val installed = LocalModule.installed().map { LocalModuleRvItem(it) }
|
||||
val diff = withContext(Dispatchers.Default) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user