Added automated loading to new compat-based redesign

This commit is contained in:
Viktor De Pasquale 2019-10-04 19:35:22 +02:00
parent f161cf8b0a
commit 277d8773f2
4 changed files with 30 additions and 0 deletions

View File

@ -18,4 +18,10 @@ abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBin
delegate.ensureInsets() delegate.ensureInsets()
} }
override fun onResume() {
super.onResume()
delegate.onResume()
}
} }

View File

@ -8,6 +8,10 @@ class CompatDelegate internal constructor(
private val view: CompatView<*> private val view: CompatView<*>
) { ) {
fun onResume() {
view.viewModel.requestRefresh()
}
fun ensureInsets() { fun ensureInsets() {
ViewCompat.setOnApplyWindowInsetsListener(view.viewRoot) { _, insets -> ViewCompat.setOnApplyWindowInsetsListener(view.viewRoot) { _, insets ->
insets.asInsets() insets.asInsets()

View File

@ -18,4 +18,10 @@ abstract class CompatFragment<ViewModel : CompatViewModel, Binding : ViewDataBin
delegate.ensureInsets() delegate.ensureInsets()
} }
override fun onResume() {
super.onResume()
delegate.onResume()
}
} }

View File

@ -3,9 +3,23 @@ package com.topjohnwu.magisk.redesign.compat
import android.graphics.Insets import android.graphics.Insets
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
abstract class CompatViewModel : MagiskViewModel() { abstract class CompatViewModel : MagiskViewModel() {
val insets = KObservableField(Insets.NONE) val insets = KObservableField(Insets.NONE)
private var runningTask: Disposable? = null
/** This should probably never be called manually, it's called manually via delegate. */
@Synchronized
fun requestRefresh() {
if (runningTask?.isDisposed?.not() == true) {
return
}
runningTask = refresh()
}
protected open fun refresh(): Disposable? = null
} }