Added refreshing upon connection restore

This commit is contained in:
Viktor De Pasquale 2019-10-12 16:30:18 +02:00
parent 9dd272b357
commit 37fa227fb5

View File

@ -1,6 +1,8 @@
package com.topjohnwu.magisk.redesign.compat package com.topjohnwu.magisk.redesign.compat
import android.graphics.Insets import android.graphics.Insets
import androidx.annotation.CallSuper
import androidx.databinding.Observable
import com.skoumal.teanity.util.KObservableField import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.ui.base.MagiskViewModel import com.topjohnwu.magisk.ui.base.MagiskViewModel
import io.reactivex.disposables.Disposable import io.reactivex.disposables.Disposable
@ -10,6 +12,15 @@ abstract class CompatViewModel : MagiskViewModel() {
val insets = KObservableField(Insets.NONE) val insets = KObservableField(Insets.NONE)
private var runningTask: Disposable? = null private var runningTask: Disposable? = null
private val refreshCallback = object : Observable.OnPropertyChangedCallback() {
override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
requestRefresh()
}
}
init {
isConnected.addOnPropertyChangedCallback(refreshCallback)
}
/** This should probably never be called manually, it's called manually via delegate. */ /** This should probably never be called manually, it's called manually via delegate. */
@Synchronized @Synchronized
@ -22,4 +33,10 @@ abstract class CompatViewModel : MagiskViewModel() {
protected open fun refresh(): Disposable? = null protected open fun refresh(): Disposable? = null
@CallSuper
override fun onCleared() {
isConnected.removeOnPropertyChangedCallback(refreshCallback)
super.onCleared()
}
} }