Only sort if the data is from the DB. This speeds things a little bit.
This commit is contained in:
parent
fb8f81a4c8
commit
0f000ea359
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user