From 7fb7e4509354b2a3c164d9271b4aecc7fe192344 Mon Sep 17 00:00:00 2001 From: davide Date: Tue, 16 Aug 2022 11:41:43 +0200 Subject: [PATCH] Simplify items appending operation --- .../bou/amine/apps/readerforselfossv2/android/HomeActivity.kt | 4 ++-- .../apps/readerforselfossv2/repository/RepositoryImpl.kt | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 5e460e6..2d7e628 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -893,9 +893,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar binding.swipeRefreshLayout.isRefreshing = true repository.displayedItems = itemType items = if (appendResults) { - repository.getNewerItems() - } else { repository.getOlderItems() + } else { + repository.getNewerItems() } binding.swipeRefreshLayout.isRefreshing = false handleListResult() diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index bd8f552..1c5fe54 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -83,8 +83,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet private fun appendItems(fetchedItems: List) { // TODO: Store in DB if enabled by user val fetchedIDS = fetchedItems.map { it.id } - val tmpItems = items - tmpItems.removeAll{ it.id in fetchedIDS } + val tmpItems = ArrayList(items.filterNot { it.id in fetchedIDS }) tmpItems.addAll(fetchedItems) sortItems(tmpItems) items = tmpItems