diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt index d19af09d1..9c639b1c4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/CompatViewModel.kt @@ -1,6 +1,8 @@ package com.topjohnwu.magisk.redesign.compat import android.graphics.Insets +import androidx.annotation.CallSuper +import androidx.databinding.Observable import com.skoumal.teanity.util.KObservableField import com.topjohnwu.magisk.ui.base.MagiskViewModel import io.reactivex.disposables.Disposable @@ -10,6 +12,15 @@ abstract class CompatViewModel : MagiskViewModel() { val insets = KObservableField(Insets.NONE) 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. */ @Synchronized @@ -22,4 +33,10 @@ abstract class CompatViewModel : MagiskViewModel() { protected open fun refresh(): Disposable? = null + @CallSuper + override fun onCleared() { + isConnected.removeOnPropertyChangedCallback(refreshCallback) + super.onCleared() + } + } \ No newline at end of file