From bdf2bb8b31ede1e118626535740f7d46aa6a3592 Mon Sep 17 00:00:00 2001 From: Amine Date: Sun, 23 Mar 2025 21:10:03 +0100 Subject: [PATCH] fix: do not reload items on resume. --- .../android/HomeActivity.kt | 33 +++++++++++-------- .../android/adapters/ItemCardAdapter.kt | 2 +- .../android/adapters/ItemListAdapter.kt | 2 +- .../android/adapters/ItemsAdapter.kt | 5 ++- 4 files changed, 23 insertions(+), 19 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 77df999..7daea1e 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 @@ -120,6 +120,7 @@ class HomeActivity : binding.swipeRefreshLayout.setOnRefreshListener { repository.offlineOverride = false lastFetchDone = false + items.clear() getElementsAccordingToTab() binding.swipeRefreshLayout.isRefreshing = false } @@ -458,23 +459,27 @@ class HomeActivity : appendResults: Boolean, itemType: ItemType, ) { - CountingIdlingResourceSingleton.increment() - binding.swipeRefreshLayout.isRefreshing = true - CoroutineScope(Dispatchers.IO).launch { - repository.displayedItems = itemType - items = - if (appendResults) { - repository.getOlderItems() - } else { - repository.getNewerItems() - } + if ((appendResults && items.size > 0) || (!appendResults && items.size == 0)) { CountingIdlingResourceSingleton.increment() - launch(Dispatchers.Main) { - binding.swipeRefreshLayout.isRefreshing = false - handleListResult() + binding.swipeRefreshLayout.isRefreshing = true + CoroutineScope(Dispatchers.IO).launch { + repository.displayedItems = itemType + items = + if (appendResults) { + repository.getOlderItems() + } else { + repository.getNewerItems() + } + CountingIdlingResourceSingleton.increment() + launch(Dispatchers.Main) { + binding.swipeRefreshLayout.isRefreshing = false + handleListResult() + CountingIdlingResourceSingleton.decrement() + } CountingIdlingResourceSingleton.decrement() } - CountingIdlingResourceSingleton.decrement() + } else { + handleListResult() } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index bb3fab0..4c8c276 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -30,7 +30,7 @@ import org.kodein.di.instance class ItemCardAdapter( override val app: Activity, - override val items: ArrayList, + override var items: ArrayList, override val updateHomeItems: (ArrayList) -> Unit, ) : ItemsAdapter() { override lateinit var binding: CardItemBinding diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index d096e34..0c3c0e7 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -21,7 +21,7 @@ import org.kodein.di.instance class ItemListAdapter( override val app: Activity, - override val items: ArrayList, + override var items: ArrayList, override val updateHomeItems: (ArrayList) -> Unit, ) : ItemsAdapter() { override lateinit var binding: ListItemBinding diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index 79391a6..c19ebd9 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -21,7 +21,7 @@ import org.kodein.di.DIAware abstract class ItemsAdapter : RecyclerView.Adapter(), DIAware { - abstract val items: ArrayList + abstract var items: ArrayList abstract val repository: Repository abstract val binding: ViewBinding abstract val appSettingsService: AppSettingsService @@ -31,8 +31,7 @@ abstract class ItemsAdapter : protected val c: Context get() = app.baseContext fun updateAllItems(items: ArrayList) { - this.items.clear() - this.items.addAll(items) + this.items = items updateHomeItems(items) notifyDataSetChanged() }