Simplify items appending operation

This commit is contained in:
davide 2022-08-16 11:41:43 +02:00
parent edc705ec8e
commit 7fb7e45093
2 changed files with 3 additions and 4 deletions

View File

@ -893,9 +893,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
repository.displayedItems = itemType repository.displayedItems = itemType
items = if (appendResults) { items = if (appendResults) {
repository.getNewerItems()
} else {
repository.getOlderItems() repository.getOlderItems()
} else {
repository.getNewerItems()
} }
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
handleListResult() handleListResult()

View File

@ -83,8 +83,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
private fun appendItems(fetchedItems: List<SelfossModel.Item>) { private fun appendItems(fetchedItems: List<SelfossModel.Item>) {
// TODO: Store in DB if enabled by user // TODO: Store in DB if enabled by user
val fetchedIDS = fetchedItems.map { it.id } val fetchedIDS = fetchedItems.map { it.id }
val tmpItems = items val tmpItems = ArrayList(items.filterNot { it.id in fetchedIDS })
tmpItems.removeAll{ it.id in fetchedIDS }
tmpItems.addAll(fetchedItems) tmpItems.addAll(fetchedItems)
sortItems(tmpItems) sortItems(tmpItems)
items = tmpItems items = tmpItems