From 37fa227fb5afaee522c436ae23de6267d06bdc89 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 12 Oct 2019 16:30:18 +0200 Subject: [PATCH] Added refreshing upon connection restore --- .../magisk/redesign/compat/CompatViewModel.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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