fix:reload

This commit is contained in:
86152
2024-03-02 20:29:56 +08:00
parent c28b73edf8
commit 6296ef6348
@@ -96,28 +96,28 @@ class MainViewModel(private val repository: PostRepository, context: Context):Vi
}
private fun fetchNewPost(){
private fun fetchNewPost() {
fetchJob?.cancel()
fetchJob = viewModelScope.launch(Dispatchers.IO) {
_uiState.value.isRefreshing.postValue(true)
try {
_postList.postValue(repository.fetchPostData(
val newPosts = repository.fetchPostData(
_uiState.value.nowSearchText.value,
_uiState.value.isSafe,
_uiState.value.nowPage
))
}catch (e:NetworkErrorException){
)
val currentPosts = _postList.value ?: arrayListOf()
currentPosts.addAll(0,newPosts)
_postList.postValue(currentPosts)
} catch (e: NetworkErrorException) {
postNewToast(e.message.toString())
}
_uiState.value.isRefreshing.postValue(false)
}
}
fun fetchPostByRefresh(){
_uiState.update {
it.copy(nowPage = 1)