diff --git a/app/src/main/java/com/topjohnwu/magisk/base/viewmodel/TeanityViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/base/viewmodel/TeanityViewModel.kt index 4fb10599a..17449a115 100644 --- a/app/src/main/java/com/topjohnwu/magisk/base/viewmodel/TeanityViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/base/viewmodel/TeanityViewModel.kt @@ -20,11 +20,11 @@ abstract class TeanityViewModel : ViewModel() { } fun Event.publish() { - _viewEvents.value = this + _viewEvents.postValue(this) } fun Int.publish() { - _viewEvents.value = SimpleViewEvent(this) + _viewEvents.postValue(SimpleViewEvent(this)) } fun Disposable.add() { diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleFragment.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleFragment.kt index cee00a054..bb33a86f9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleFragment.kt @@ -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 // --- + 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) } diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index 5c516aa3b..25c50cc80 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -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) { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/EndlessRecyclerScrollListener.kt b/app/src/main/java/com/topjohnwu/magisk/utils/EndlessRecyclerScrollListener.kt index 869f12444..624e40a7d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/EndlessRecyclerScrollListener.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/EndlessRecyclerScrollListener.kt @@ -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() } \ No newline at end of file