Commit 7342509b authored by Viktor De Pasquale's avatar Viktor De Pasquale

Added resetting state of the recyclerview scroll listener

In some edge-cases the listener can still think that the content is loading.
parent ed837ba2
...@@ -20,11 +20,11 @@ abstract class TeanityViewModel : ViewModel() { ...@@ -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() {
......
...@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.StaggeredGridLayoutManager ...@@ -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> ...@@ -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)
} }
......
...@@ -20,6 +20,7 @@ import com.topjohnwu.magisk.model.events.OpenChangelogEvent ...@@ -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( ...@@ -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) {
......
...@@ -4,6 +4,7 @@ import androidx.recyclerview.widget.GridLayoutManager ...@@ -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( ...@@ -110,4 +111,6 @@ class EndlessRecyclerScrollListener(
previousTotalItemCount = 0 previousTotalItemCount = 0
loading = true loading = true
} }
class ResetState : ViewEvent()
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment