mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 02:25:28 +00:00
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()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
delegate.onResume()
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,10 @@ class CompatDelegate internal constructor(
|
||||
private val view: CompatView<*>
|
||||
) {
|
||||
|
||||
fun onResume() {
|
||||
view.viewModel.requestRefresh()
|
||||
}
|
||||
|
||||
fun ensureInsets() {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view.viewRoot) { _, insets ->
|
||||
insets.asInsets()
|
||||
|
@ -18,4 +18,10 @@ abstract class CompatFragment<ViewModel : CompatViewModel, Binding : ViewDataBin
|
||||
delegate.ensureInsets()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
delegate.onResume()
|
||||
}
|
||||
|
||||
}
|
@ -3,9 +3,23 @@ package com.topjohnwu.magisk.redesign.compat
|
||||
import android.graphics.Insets
|
||||
import com.skoumal.teanity.util.KObservableField
|
||||
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||
import io.reactivex.disposables.Disposable
|
||||
|
||||
abstract class CompatViewModel : MagiskViewModel() {
|
||||
|
||||
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