Sudhir Singh Khanger
09/08/2020, 3:58 AMMehul Kabaria
09/08/2020, 4:00 AMSudhir Singh Khanger
09/08/2020, 4:04 AMYashovardhan
09/08/2020, 5:12 AMFlow<List<T>>
you can just use map
to apply a filter on the list.
However, if you are collecting it in the ViewModel itself, you can simply filter it after collection - before assigning to LiveData.Yashovardhan
09/08/2020, 5:13 AMFlow<T>
instead, you can even call filter directly on itrkeazor
09/08/2020, 12:16 PMrkeazor
09/08/2020, 12:17 PMSudhir Singh Khanger
09/10/2020, 7:14 AMfun getCountries(): Flow<CountriesResponse> = flow { emit(networkSampleService.countries()) }
ViewModel
private fun fetchCountries() {
viewModelScope.launch {
repository.getCountries()
.onStart { _countriesViewEffects.postValue(Event(Resource.loading(null))) }
.catch { _countriesViewEffects.postValue(Event(Resource.error(it.message ?: "", null))) }
.collect {
it.data?.let { list -> countries.addAll(list) }
_countriesLiveData.postValue(Resource.success(it))
}
}
}
Sudhir Singh Khanger
09/10/2020, 7:50 AMrkeazor
09/11/2020, 3:02 AMsuspend fun countries() { networkSampleService.countries()}
rkeazor
09/11/2020, 3:07 AMval countriesLiveData = liveData { emit (Event(Resource.loading(null))) ... emit (Event(Resource.Success(it)) }
rkeazor
09/11/2020, 3:08 AM