Bug fixes in modules fragment

- Progress is not updated in upgradable modules (and can cause crash)
- EndlessRecyclerScrollListener is not reset on new query
This commit is contained in:
topjohnwu 2020-07-08 01:40:08 -07:00
parent 01a43b03bd
commit dc8f0f6feb
1 changed files with 7 additions and 3 deletions

View File

@ -256,6 +256,7 @@ class ModuleViewModel(
}
override fun query() {
EndlessRecyclerScrollListener.ResetState().publish()
queryJob = viewModelScope.launch {
val searched = queryInternal(query, 0)
val diff = withContext(Dispatchers.Default) {
@ -277,10 +278,13 @@ class ModuleViewModel(
// ---
private fun update(repo: Repo, progress: Int) = viewModelScope.launch {
val item = withContext(Dispatchers.Default) {
(itemsRemote + itemsSearch).first { it.item.id == repo.id }
val items = withContext(Dispatchers.Default) {
val predicate = { it: RepoItem -> it.item.id == repo.id }
itemsUpdatable.filter(predicate) +
itemsRemote.filter(predicate) +
itemsSearch.filter(predicate)
}
item.progress.value = progress
items.forEach { it.progress.value = progress }
}
// ---