Nat Strangerweather
08/03/2023, 7:59 PMNat Strangerweather
08/03/2023, 7:59 PMis Resource.Success -> {
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
database.newsFeedDao.deleteFeedsByUrl(url)
val sortedResults = resource.result.sortedByDescending { newsFeed ->
LocalDateTime.parse(newsFeed.feedItem.pubDate, dateTimeFormatter)
}
database.newsFeedDao.insertNewsFeeds(sortedResults)
}
}
Youssef Shoaib [MOD]
08/03/2023, 8:06 PMresource.results
? Maybe some example data might helpNat Strangerweather
08/03/2023, 8:08 PMYoussef Shoaib [MOD]
08/03/2023, 8:10 PMprint
statements. Also, do they already have an ID before you inset them? If so, you won't see the effect of sorting at all. Sorting impacts insertion order, which should only impact insertion if they don't have an IDNat Strangerweather
08/03/2023, 8:10 PMNat Strangerweather
08/03/2023, 8:11 PMNat Strangerweather
08/03/2023, 8:11 PMYoussef Shoaib [MOD]
08/03/2023, 8:12 PMorderBy
clause that orders the items you're reading.
You usually shouldn't care whether the database has them in order or not because that can be quite fragileNat Strangerweather
08/03/2023, 8:12 PMNat Strangerweather
08/03/2023, 8:13 PMNat Strangerweather
08/03/2023, 8:14 PM