mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 10:57:39 +00:00
Added resetting state of the recyclerview scroll listener
In some edge-cases the listener can still think that the content is loading.
This commit is contained in:
parent
ed837ba26f
commit
7342509b2e
@ -20,11 +20,11 @@ abstract class TeanityViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun <Event : ViewEvent> Event.publish() {
|
||||
_viewEvents.value = this
|
||||
_viewEvents.postValue(this)
|
||||
}
|
||||
|
||||
fun Int.publish() {
|
||||
_viewEvents.value = SimpleViewEvent(this)
|
||||
_viewEvents.postValue(SimpleViewEvent(this))
|
||||
}
|
||||
|
||||
fun Disposable.add() {
|
||||
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
|
||||
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent
|
||||
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||
import com.topjohnwu.magisk.redesign.MainActivity
|
||||
import com.topjohnwu.magisk.redesign.ReselectionTarget
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatFragment
|
||||
@ -93,6 +94,13 @@ class ModuleFragment : CompatFragment<ModuleViewModel, FragmentModuleMd2Binding>
|
||||
|
||||
// ---
|
||||
|
||||
override fun onEventDispatched(event: ViewEvent) = when (event) {
|
||||
is EndlessRecyclerScrollListener.ResetState -> listeners.forEach { it.resetState() }
|
||||
else -> super.onEventDispatched(event)
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_module_md2, menu)
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import com.topjohnwu.magisk.model.events.OpenChangelogEvent
|
||||
import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog
|
||||
import com.topjohnwu.magisk.redesign.compat.*
|
||||
import com.topjohnwu.magisk.tasks.RepoUpdater
|
||||
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
|
||||
import com.topjohnwu.magisk.utils.KObservableField
|
||||
import com.topjohnwu.magisk.utils.currentLocale
|
||||
import io.reactivex.Completable
|
||||
@ -175,6 +176,9 @@ class ModuleViewModel(
|
||||
if (remoteJob?.isDisposed?.not() == true) {
|
||||
return
|
||||
}
|
||||
if (itemsRemote.isEmpty()) {
|
||||
EndlessRecyclerScrollListener.ResetState().publish()
|
||||
}
|
||||
remoteJob = Single.fromCallable { itemsRemote.size }
|
||||
.flatMap { loadRemoteInternal(offset = it) }
|
||||
.subscribeK(onError = Timber::e) {
|
||||
|
@ -4,6 +4,7 @@ import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||
|
||||
class EndlessRecyclerScrollListener(
|
||||
private val layoutManager: RecyclerView.LayoutManager,
|
||||
@ -110,4 +111,6 @@ class EndlessRecyclerScrollListener(
|
||||
previousTotalItemCount = 0
|
||||
loading = true
|
||||
}
|
||||
|
||||
class ResetState : ViewEvent()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user