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:
Viktor De Pasquale 2020-01-06 18:20:01 +01:00
parent ed837ba26f
commit 7342509b2e
4 changed files with 17 additions and 2 deletions

View File

@ -20,11 +20,11 @@ abstract class TeanityViewModel : ViewModel() {
} }
fun <Event : ViewEvent> Event.publish() { fun <Event : ViewEvent> Event.publish() {
_viewEvents.value = this _viewEvents.postValue(this)
} }
fun Int.publish() { fun Int.publish() {
_viewEvents.value = SimpleViewEvent(this) _viewEvents.postValue(SimpleViewEvent(this))
} }
fun Disposable.add() { fun Disposable.add() {

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding import com.topjohnwu.magisk.databinding.FragmentModuleMd2Binding
import com.topjohnwu.magisk.model.events.InstallExternalModuleEvent 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.MainActivity
import com.topjohnwu.magisk.redesign.ReselectionTarget import com.topjohnwu.magisk.redesign.ReselectionTarget
import com.topjohnwu.magisk.redesign.compat.CompatFragment 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) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_module_md2, menu) inflater.inflate(R.menu.menu_module_md2, menu)
} }

View File

@ -20,6 +20,7 @@ import com.topjohnwu.magisk.model.events.OpenChangelogEvent
import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog import com.topjohnwu.magisk.model.events.dialog.ModuleInstallDialog
import com.topjohnwu.magisk.redesign.compat.* import com.topjohnwu.magisk.redesign.compat.*
import com.topjohnwu.magisk.tasks.RepoUpdater import com.topjohnwu.magisk.tasks.RepoUpdater
import com.topjohnwu.magisk.utils.EndlessRecyclerScrollListener
import com.topjohnwu.magisk.utils.KObservableField import com.topjohnwu.magisk.utils.KObservableField
import com.topjohnwu.magisk.utils.currentLocale import com.topjohnwu.magisk.utils.currentLocale
import io.reactivex.Completable import io.reactivex.Completable
@ -175,6 +176,9 @@ class ModuleViewModel(
if (remoteJob?.isDisposed?.not() == true) { if (remoteJob?.isDisposed?.not() == true) {
return return
} }
if (itemsRemote.isEmpty()) {
EndlessRecyclerScrollListener.ResetState().publish()
}
remoteJob = Single.fromCallable { itemsRemote.size } remoteJob = Single.fromCallable { itemsRemote.size }
.flatMap { loadRemoteInternal(offset = it) } .flatMap { loadRemoteInternal(offset = it) }
.subscribeK(onError = Timber::e) { .subscribeK(onError = Timber::e) {

View File

@ -4,6 +4,7 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.topjohnwu.magisk.model.events.ViewEvent
class EndlessRecyclerScrollListener( class EndlessRecyclerScrollListener(
private val layoutManager: RecyclerView.LayoutManager, private val layoutManager: RecyclerView.LayoutManager,
@ -110,4 +111,6 @@ class EndlessRecyclerScrollListener(
previousTotalItemCount = 0 previousTotalItemCount = 0
loading = true loading = true
} }
class ResetState : ViewEvent()
} }