diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt index 941f356a0..a261e002d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/ModuleRvItem.kt @@ -146,6 +146,19 @@ class ModuleItem(val item: Module) : ObservableItem(), Observable { } +object LoadingItem : ComparableRvItem() { + override val layoutRes = R.layout.item_loading + + override fun onBindingBound(binding: ViewDataBinding) { + super.onBindingBound(binding) + val params = binding.root.layoutParams as? StaggeredGridLayoutManager.LayoutParams ?: return + params.isFullSpan = true + } + + override fun contentSameAs(other: LoadingItem) = this == other + override fun itemSameAs(other: LoadingItem) = this === other +} + abstract class ObservableItem : ComparableRvItem(), Observable { private val list = PropertyChangeRegistry() 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 8397c1ec4..6a290bc30 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 @@ -12,6 +12,7 @@ import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.extensions.subscribeK import com.topjohnwu.magisk.model.entity.module.Module import com.topjohnwu.magisk.model.entity.module.Repo +import com.topjohnwu.magisk.model.entity.recycler.LoadingItem import com.topjohnwu.magisk.model.entity.recycler.ModuleItem import com.topjohnwu.magisk.model.entity.recycler.RepoItem import com.topjohnwu.magisk.model.entity.recycler.SectionTitle @@ -25,6 +26,7 @@ import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter +import timber.log.Timber class ModuleViewModel( private val repoName: RepoByNameDao, @@ -96,12 +98,17 @@ class ModuleViewModel( remoteJob = loadRepos(offset = size) .map { it.map { RepoItem(it) } } .applyViewModel(this) - .subscribeK { + .subscribeK(onError = { + Timber.e(it) + items.remove(LoadingItem) + }) { + items.remove(LoadingItem) if (!items.contains(sectionRemote)) { items.add(sectionRemote) } items.addAll(it) } + items.add(LoadingItem) } private fun loadRepos( diff --git a/app/src/main/res/layout/item_loading.xml b/app/src/main/res/layout/item_loading.xml new file mode 100644 index 000000000..c10346364 --- /dev/null +++ b/app/src/main/res/layout/item_loading.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file