Fixed messages on modules screen replicating indefinitely

This commit is contained in:
Viktor De Pasquale 2020-01-27 15:33:12 +01:00 committed by John Wu
parent 7bf7bfb9c6
commit 9c4c310f46

View File

@ -155,24 +155,12 @@ class ModuleViewModel(
}
itemsInstalled.addOnListChangedCallback(
onItemRangeInserted = { _, _, _ ->
itemsInstalledHelpers.clear()
},
onItemRangeRemoved = { sender, _, _ ->
if (sender.isEmpty() && itemsInstalledHelpers.isEmpty()) {
itemsInstalledHelpers.add(itemNoneInstalled)
}
}
onItemRangeInserted = { _, _, _ -> itemsInstalledHelpers.clear() },
onItemRangeRemoved = { _, _, _ -> addInstalledEmptyMessage() }
)
itemsUpdatable.addOnListChangedCallback(
onItemRangeInserted = { _, _, _ ->
itemsUpdatableHelpers.clear()
},
onItemRangeRemoved = { sender, _, _ ->
if (sender.isEmpty() && itemsUpdatableHelpers.isEmpty()) {
itemsUpdatableHelpers.add(itemNoneUpdatable)
}
}
onItemRangeInserted = { _, _, _ -> itemsUpdatableHelpers.clear() },
onItemRangeRemoved = { _, _, _ -> addUpdatableEmptyMessage() }
)
}
@ -201,8 +189,8 @@ class ModuleViewModel(
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess { itemsUpdatable.update(it.first, it.second) }
.doOnSuccess {
if (itemsInstalled.isEmpty()) itemsInstalledHelpers.add(itemNoneInstalled)
if (itemsUpdatable.isEmpty()) itemsUpdatableHelpers.add(itemNoneUpdatable)
addInstalledEmptyMessage()
addUpdatableEmptyMessage()
}
.ignoreElement()!!
@ -287,6 +275,20 @@ class ModuleViewModel(
.subscribeK { it.progress.value = progress }
.add()
// ---
private fun addInstalledEmptyMessage() {
if (itemsInstalled.isEmpty() && itemsInstalledHelpers.isEmpty()) {
itemsInstalledHelpers.add(itemNoneInstalled)
}
}
private fun addUpdatableEmptyMessage() {
if (itemsUpdatable.isEmpty() && itemsUpdatableHelpers.isEmpty()) {
itemsUpdatableHelpers.add(itemNoneUpdatable)
}
}
private fun updateCoreOnlyWarning() {
if (Config.coreOnly) {
if (itemsCoreOnly.isNotEmpty()) return