It is not serving my purpose, flatMapLatest calls every time when I come back to list fragment from detail fragment although there is no value change in _requestParams
Copy code
val pendingReviewList: Flow<PagingData<PendingReview>> =
_requestParams.flatMapLatest {
Timber.i("Current value : $it")
providerRepository.getPendingReviewList(limit = 10).cachedIn(viewModelScope)
}
but this is not happening in case Mutable live data
Copy code
val posts = _requestParams.switchMap {
repository.getGuestPostedReviews().cachedIn(viewModelScope).asLiveData()
}
Chethan
01/27/2021, 6:44 AM
I fixed this with below code
Copy code
private val _refreshCall = MutableLiveData<Boolean>(false)
val pendingReviewList: Flow<PagingData<PendingReview>> =
_refreshCall.switchMap {
providerRepository.getPendingReviewList(limit = 10).cachedIn(viewModelScope)
.asLiveData()
}.asFlow()
fun refresh() {
_refreshCall.value?.let {
_refreshCall.value = !it
}
}