diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 31d807a..b3e1c40 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -217,7 +217,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { lastFetchDone = false handleDrawerItems() CoroutineScope(Dispatchers.Main).launch { - refreshFocusedItems(applicationContext, api, db) + refreshFocusedItems(applicationContext, api, db, itemsNumber) getElementsAccordingToTab() binding.swipeRefreshLayout.isRefreshing = false } @@ -982,7 +982,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { CoroutineScope(Dispatchers.Main).launch { if (appendResults || !SharedItems.fetchedUnread) { binding.swipeRefreshLayout.isRefreshing = true - getUnreadItems(applicationContext, api, db, offset) + getUnreadItems(applicationContext, api, db, itemsNumber, offset) binding.swipeRefreshLayout.isRefreshing = false } SharedItems.getUnRead() @@ -995,7 +995,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { CoroutineScope(Dispatchers.Main).launch { if (appendResults || !SharedItems.fetchedAll) { binding.swipeRefreshLayout.isRefreshing = true - getReadItems(applicationContext, api, db, offset) + getReadItems(applicationContext, api, db, itemsNumber, offset) binding.swipeRefreshLayout.isRefreshing = false } SharedItems.getAll() @@ -1008,7 +1008,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { CoroutineScope(Dispatchers.Main).launch { if (appendResults || !SharedItems.fetchedStarred) { binding.swipeRefreshLayout.isRefreshing = true - getStarredItems(applicationContext, api, db, offset) + getStarredItems(applicationContext, api, db, itemsNumber, offset) binding.swipeRefreshLayout.isRefreshing = false } SharedItems.getStarred() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossFetching.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossFetching.kt index ff14180..0d38b57 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossFetching.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossFetching.kt @@ -39,13 +39,13 @@ suspend fun updateItems(context: Context, api: SelfossApi, db: AppDatabase) = co } } -suspend fun refreshFocusedItems(context: Context, api: SelfossApi, db: AppDatabase) = withContext(Dispatchers.IO) { +suspend fun refreshFocusedItems(context: Context, api: SelfossApi, db: AppDatabase, itemsNumber: Int) = withContext(Dispatchers.IO) { if (isNetworkAvailable(context)) { val response = when (SharedItems.displayedItems) { - "read" -> api.readItems(200, 0) - "unread" -> api.newItems(200, 0) - "starred" -> api.starredItems(200, 0) - else -> api.readItems(200, 0) + "read" -> api.readItems(itemsNumber, 0) + "unread" -> api.newItems(itemsNumber, 0) + "starred" -> api.starredItems(itemsNumber, 0) + else -> api.readItems(itemsNumber, 0) } if (response.isSuccessful) { @@ -55,33 +55,33 @@ suspend fun refreshFocusedItems(context: Context, api: SelfossApi, db: AppDataba } } -suspend fun getReadItems(context: Context, api: SelfossApi, db: AppDatabase, offset: Int) = withContext(Dispatchers.IO) { +suspend fun getReadItems(context: Context, api: SelfossApi, db: AppDatabase, itemsNumber: Int, offset: Int) = withContext(Dispatchers.IO) { if (isNetworkAvailable(context)) { try { - enqueueArticles(api.readItems( 200, offset), db, false) + enqueueArticles(api.readItems( itemsNumber, offset), db, false) SharedItems.fetchedAll = true SharedItems.updateDatabase(db) } catch (e: Throwable) {} } } -suspend fun getUnreadItems(context: Context, api: SelfossApi, db: AppDatabase, offset: Int) = withContext(Dispatchers.IO) { +suspend fun getUnreadItems(context: Context, api: SelfossApi, db: AppDatabase, itemsNumber: Int, offset: Int) = withContext(Dispatchers.IO) { if (isNetworkAvailable(context)) { try { if (!SharedItems.fetchedUnread) { SharedItems.clearDBItems(db) } - enqueueArticles(api.newItems(200, offset), db, false) + enqueueArticles(api.newItems(itemsNumber, offset), db, false) SharedItems.fetchedUnread = true } catch (e: Throwable) {} } SharedItems.updateDatabase(db) } -suspend fun getStarredItems(context: Context, api: SelfossApi, db: AppDatabase, offset: Int) = withContext(Dispatchers.IO) { +suspend fun getStarredItems(context: Context, api: SelfossApi, db: AppDatabase, itemsNumber: Int, offset: Int) = withContext(Dispatchers.IO) { if (isNetworkAvailable(context)) { try { - enqueueArticles(api.starredItems(200, offset), db, false) + enqueueArticles(api.starredItems(itemsNumber, offset), db, false) SharedItems.fetchedStarred = true SharedItems.updateDatabase(db) } catch (e: Throwable) {