I have to asynchronous operations. In the viewmodel, the two need to work together for the UI. How can I filter the LiveData list based on the keys in de LiveData map? (Object id's in list correspond to Map keys)
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
private val _allJourneys = MutableLiveData<List<Journey>>()
val allJourneys: LiveData<List<Journey>> get() = _allJourneys
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
private val _enrolledMap = MutableLiveData<Map<String, String>>()
val enrolledMap: LiveData<Map<String, String>> get() = _enrolledMap
fun getEnrolled() {
viewModelScope.launch {
progressRepository.getEnrolledJourneysMapOfUser().observeForever {
Timber.d("Map values: $it")
_enrolledMap.value = it
}
}
}
fun getJourneys() {
viewModelScope.launch {
journeysRepository.getAll().observeForever { it ->
_allJourneys.value = it.filter {
// enrolledMap.containsKey(it.id) ??? Nullpointer
}
}
}
}
how about something like this (based on the MediatorLiveData example from here)
the changes in the
allJourney
andenrolledMap
LiveData should trigger thecombineLatestData