enhancement/too-many-calls #68

Merged
AmineB merged 6 commits from enhancement/too-many-calls into master 2022-09-26 18:26:23 +00:00
Showing only changes of commit 0f000ea359 - Show all commits

View File

@ -48,6 +48,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
// TODO: Use the updatedSince parameter
var fetchedItems: SelfossModel.StatusAndData<List<SelfossModel.Item>> = SelfossModel.StatusAndData.error()
var fromDB = false
if (isNetworkAvailable()) {
fetchedItems = api.getItems(
displayedItems.type,
@ -59,6 +60,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
)
} else {
if (appSettingsService.isItemCachingEnabled()) {
fromDB = true
fetchedItems = SelfossModel.StatusAndData.succes(
getDBItems().filter {
displayedItems == ItemType.ALL ||
@ -71,7 +73,9 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
if (fetchedItems.success && fetchedItems.data != null) {
items = ArrayList(fetchedItems.data!!)
sortItems()
if (fromDB) {
items.sortByDescending { dateUtils.parseDate(it.datetime) }
}
}
return items
}
@ -92,7 +96,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
if (fetchedItems.success && fetchedItems.data != null) {
items.addAll(fetchedItems.data!!)
sortItems()
}
return items
}
@ -118,10 +121,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
}
}
private fun sortItems() {
items.sortByDescending { dateUtils.parseDate(it.datetime) }
}
suspend fun reloadBadges(): Boolean {
var success = false
if (isNetworkAvailable()) {