Fix setting the number of articles downloaded (#403)

This commit is contained in:
davidoskky 2022-02-05 18:17:35 +01:00 committed by GitHub
parent 4826ed0355
commit def75b6431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -217,7 +217,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
lastFetchDone = false lastFetchDone = false
handleDrawerItems() handleDrawerItems()
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
refreshFocusedItems(applicationContext, api, db) refreshFocusedItems(applicationContext, api, db, itemsNumber)
getElementsAccordingToTab() getElementsAccordingToTab()
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
@ -982,7 +982,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
if (appendResults || !SharedItems.fetchedUnread) { if (appendResults || !SharedItems.fetchedUnread) {
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
getUnreadItems(applicationContext, api, db, offset) getUnreadItems(applicationContext, api, db, itemsNumber, offset)
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
SharedItems.getUnRead() SharedItems.getUnRead()
@ -995,7 +995,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
if (appendResults || !SharedItems.fetchedAll) { if (appendResults || !SharedItems.fetchedAll) {
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
getReadItems(applicationContext, api, db, offset) getReadItems(applicationContext, api, db, itemsNumber, offset)
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
SharedItems.getAll() SharedItems.getAll()
@ -1008,7 +1008,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
if (appendResults || !SharedItems.fetchedStarred) { if (appendResults || !SharedItems.fetchedStarred) {
binding.swipeRefreshLayout.isRefreshing = true binding.swipeRefreshLayout.isRefreshing = true
getStarredItems(applicationContext, api, db, offset) getStarredItems(applicationContext, api, db, itemsNumber, offset)
binding.swipeRefreshLayout.isRefreshing = false binding.swipeRefreshLayout.isRefreshing = false
} }
SharedItems.getStarred() SharedItems.getStarred()

View File

@ -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)) { if (isNetworkAvailable(context)) {
val response = when (SharedItems.displayedItems) { val response = when (SharedItems.displayedItems) {
"read" -> api.readItems(200, 0) "read" -> api.readItems(itemsNumber, 0)
"unread" -> api.newItems(200, 0) "unread" -> api.newItems(itemsNumber, 0)
"starred" -> api.starredItems(200, 0) "starred" -> api.starredItems(itemsNumber, 0)
else -> api.readItems(200, 0) else -> api.readItems(itemsNumber, 0)
} }
if (response.isSuccessful) { 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)) { if (isNetworkAvailable(context)) {
try { try {
enqueueArticles(api.readItems( 200, offset), db, false) enqueueArticles(api.readItems( itemsNumber, offset), db, false)
SharedItems.fetchedAll = true SharedItems.fetchedAll = true
SharedItems.updateDatabase(db) SharedItems.updateDatabase(db)
} catch (e: Throwable) {} } 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)) { if (isNetworkAvailable(context)) {
try { try {
if (!SharedItems.fetchedUnread) { if (!SharedItems.fetchedUnread) {
SharedItems.clearDBItems(db) SharedItems.clearDBItems(db)
} }
enqueueArticles(api.newItems(200, offset), db, false) enqueueArticles(api.newItems(itemsNumber, offset), db, false)
SharedItems.fetchedUnread = true SharedItems.fetchedUnread = true
} catch (e: Throwable) {} } catch (e: Throwable) {}
} }
SharedItems.updateDatabase(db) 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)) { if (isNetworkAvailable(context)) {
try { try {
enqueueArticles(api.starredItems(200, offset), db, false) enqueueArticles(api.starredItems(itemsNumber, offset), db, false)
SharedItems.fetchedStarred = true SharedItems.fetchedStarred = true
SharedItems.updateDatabase(db) SharedItems.updateDatabase(db)
} catch (e: Throwable) { } catch (e: Throwable) {