From ef0f32607348806780057904a9752f7724479e4f Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 20 Aug 2022 12:37:11 +0200 Subject: [PATCH] Prepare the repository functions for DB implementation --- .../repository/RepositoryImpl.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 2ea43c4..d2d6600 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 @@ -62,8 +62,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails suspend fun getNewerItems(): ArrayList { // TODO: Use the updatedSince parameter + var fetchedItems: List? = null if (isNetworkAvailable()) { - val fetchedItems = api.getItems( + fetchedItems = api.getItems( displayedItems.type, settings.getString("prefer_api_items_number", "200").toInt(), offset = 0, @@ -72,20 +73,21 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails searchFilter, null ) - - if (fetchedItems != null) { - items = ArrayList(fetchedItems) - } } else { // TODO: Get items from the database } + + if (fetchedItems != null) { + items = ArrayList(fetchedItems) + } return items } suspend fun getOlderItems(): ArrayList { + var fetchedItems: List? = null if (isNetworkAvailable()) { val offset = items.size - val fetchedItems = api.getItems( + fetchedItems = api.getItems( displayedItems.type, settings.getString("prefer_api_items_number", "200").toInt(), offset, @@ -94,13 +96,13 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails searchFilter, null ) - - if (fetchedItems != null) { - appendItems(fetchedItems) - } } else { // TODO: Get items from the database } + + if (fetchedItems != null) { + appendItems(fetchedItems) + } return items }