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 41d768b7c..e848bbc91 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 @@ -107,7 +107,7 @@ class ModuleItem(val item: Module) : ObservableItem(), Observable { fun delete(viewModel: ModuleViewModel) { isRemoved = !isRemoved - viewModel.updateState() + viewModel.moveToState(this) } override fun contentSameAs(other: ModuleItem): Boolean = item.version == other.item.version 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 be59a5f17..55d4cbf7a 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 @@ -53,12 +53,18 @@ class ModuleViewModel : CompatViewModel() { return me } - fun updateState() { - // I don't feel like bothering with moving every single item to its updated state, - // so this kind of wasteful operation helps with that - Single.fromCallable { items + itemsPending } - .map { it.order() } - .subscribeK { it.forEach { it.update() } } + fun moveToState(item: ModuleItem) { + items.removeAll { it.itemSameAs(item) } + itemsPending.removeAll { it.itemSameAs(item) } + + if (item.isModified) { + itemsPending + } else { + items + }.apply { + add(item) + sortWith(compareBy { it.item.name.toLowerCase(currentLocale) }) + } } private enum class ModuleState { diff --git a/app/src/main/res/layout/item_module_md2.xml b/app/src/main/res/layout/item_module_md2.xml index 76fac6fb2..6463a6c6c 100644 --- a/app/src/main/res/layout/item_module_md2.xml +++ b/app/src/main/res/layout/item_module_md2.xml @@ -93,7 +93,8 @@ android:alpha=".5" android:onClick="@{(v) -> item.delete(viewModel)}" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintBottom_toBottomOf="@+id/module_version_author" + app:layout_constraintTop_toTopOf="@+id/module_title" app:srcCompat="@drawable/ic_delete_restore" />