Partially reverted removing "moveToState"

This commit is contained in:
Viktor De Pasquale 2019-11-06 18:52:58 +01:00
parent f941f5c0b0
commit 19fd4dd89c
3 changed files with 15 additions and 8 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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>