Chethan
01/27/2021, 4:56 AMScott
01/27/2021, 5:01 AMflatMapLatest
is what you're looking for. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.htmlChethan
01/27/2021, 6:14 AMval 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
val posts = _requestParams.switchMap {
repository.getGuestPostedReviews().cachedIn(viewModelScope).asLiveData()
}
Chethan
01/27/2021, 6:44 AMprivate 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
}
}