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) {
|
fun delete(viewModel: ModuleViewModel) {
|
||||||
isRemoved = !isRemoved
|
isRemoved = !isRemoved
|
||||||
viewModel.updateState()
|
viewModel.moveToState(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun contentSameAs(other: ModuleItem): Boolean = item.version == other.item.version
|
override fun contentSameAs(other: ModuleItem): Boolean = item.version == other.item.version
|
||||||
|
@ -53,12 +53,18 @@ class ModuleViewModel : CompatViewModel() {
|
|||||||
return me
|
return me
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateState() {
|
fun moveToState(item: ModuleItem) {
|
||||||
// I don't feel like bothering with moving every single item to its updated state,
|
items.removeAll { it.itemSameAs(item) }
|
||||||
// so this kind of wasteful operation helps with that
|
itemsPending.removeAll { it.itemSameAs(item) }
|
||||||
Single.fromCallable { items + itemsPending }
|
|
||||||
.map { it.order() }
|
if (item.isModified) {
|
||||||
.subscribeK { it.forEach { it.update() } }
|
itemsPending
|
||||||
|
} else {
|
||||||
|
items
|
||||||
|
}.apply {
|
||||||
|
add(item)
|
||||||
|
sortWith(compareBy { it.item.name.toLowerCase(currentLocale) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum class ModuleState {
|
private enum class ModuleState {
|
||||||
|
@ -93,7 +93,8 @@
|
|||||||
android:alpha=".5"
|
android:alpha=".5"
|
||||||
android:onClick="@{(v) -> item.delete(viewModel)}"
|
android:onClick="@{(v) -> item.delete(viewModel)}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
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" />
|
app:srcCompat="@drawable/ic_delete_restore" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user