Partially reverted removing "moveToState"
This commit is contained in:
parent
f941f5c0b0
commit
19fd4dd89c
@ -107,7 +107,7 @@ class ModuleItem(val item: Module) : ObservableItem<ModuleItem>(), Observable {
|
||||
|
||||
fun delete(viewModel: ModuleViewModel) {
|
||||
isRemoved = !isRemoved
|
||||
viewModel.updateState()
|
||||
viewModel.moveToState(this)
|
||||
}
|
||||
|
||||
override fun contentSameAs(other: ModuleItem): Boolean = item.version == other.item.version
|
||||
|
@ -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 {
|
||||
|
@ -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" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user