Added automated loading to new compat-based redesign
This commit is contained in:
parent
f161cf8b0a
commit
277d8773f2
@ -18,4 +18,10 @@ abstract class CompatActivity<ViewModel : CompatViewModel, Binding : ViewDataBin
|
|||||||
delegate.ensureInsets()
|
delegate.ensureInsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
delegate.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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()
|
||||||
|
@ -18,4 +18,10 @@ abstract class CompatFragment<ViewModel : CompatViewModel, Binding : ViewDataBin
|
|||||||
delegate.ensureInsets()
|
delegate.ensureInsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
|
||||||
|
delegate.onResume()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user