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 c31c857..7e4aa89 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 @@ -122,6 +122,7 @@ class HomeActivity : lastFetchDone = false CountingIdlingResourceSingleton.increment() CoroutineScope(Dispatchers.Main).launch { + items.clear() getElementsAccordingToTab() binding.swipeRefreshLayout.isRefreshing = false CountingIdlingResourceSingleton.decrement() @@ -462,19 +463,23 @@ class HomeActivity : appendResults: Boolean, itemType: ItemType, ) { - CountingIdlingResourceSingleton.increment() - CoroutineScope(Dispatchers.Main).launch { - binding.swipeRefreshLayout.isRefreshing = true - repository.displayedItems = itemType - items = - if (appendResults) { - repository.getOlderItems() - } else { - repository.getNewerItems() - } - binding.swipeRefreshLayout.isRefreshing = false + if ((appendResults && items.size > 0) || (!appendResults && items.size == 0)) { + CountingIdlingResourceSingleton.increment() + CoroutineScope(Dispatchers.Main).launch { + binding.swipeRefreshLayout.isRefreshing = true + repository.displayedItems = itemType + items = + if (appendResults) { + repository.getOlderItems() + } else { + repository.getNewerItems() + } + binding.swipeRefreshLayout.isRefreshing = false + handleListResult() + CountingIdlingResourceSingleton.decrement() + } + } else { handleListResult() - CountingIdlingResourceSingleton.decrement() } } 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() }