mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
app: add local cache busting
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
0ecf21467b
commit
837970147c
1 changed files with 11 additions and 2 deletions
|
@ -33,13 +33,22 @@ class LobstersViewModel @ViewModelInject constructor(
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
dao.loadPosts().collectLatest { _posts.value = it }
|
dao.loadPosts().collectLatest { _posts.value = it }
|
||||||
}
|
}
|
||||||
getMorePosts()
|
getMorePostsInternal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMorePosts() {
|
fun getMorePosts() {
|
||||||
|
getMorePostsInternal(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getMorePostsInternal(firstLoad: Boolean) {
|
||||||
viewModelScope.launch(coroutineExceptionHandler) {
|
viewModelScope.launch(coroutineExceptionHandler) {
|
||||||
val newPosts = lobstersApi.getHottestPosts(apiPage)
|
val newPosts = lobstersApi.getHottestPosts(apiPage)
|
||||||
_posts.value += newPosts
|
if (firstLoad) {
|
||||||
|
_posts.value = newPosts
|
||||||
|
dao.deleteAllPosts()
|
||||||
|
} else {
|
||||||
|
_posts.value += newPosts
|
||||||
|
}
|
||||||
apiPage += 1
|
apiPage += 1
|
||||||
dao.insertPosts(*_posts.value.toTypedArray())
|
dao.insertPosts(*_posts.value.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue