Skip to content

Instantly share code, notes, and snippets.

@hafizrahman
Created April 20, 2020 08:03
Show Gist options
  • Save hafizrahman/52afaee41a02497e48f77086b28f78c9 to your computer and use it in GitHub Desktop.
Save hafizrahman/52afaee41a02497e48f77086b28f78c9 to your computer and use it in GitHub Desktop.
Methods inside ViewModel to grab two LiveData from repository and put them into one MediatorLiveData
fun getSubjects(): LiveData<List<Subject>>? {
return sroRepository.getSubjects()
}
fun getReminders(): LiveData<List<Reminder>>? {
return sroRepository.getReminders()
}
fun getAllData(): CombinedSubjectReminders? {
var ldSubjects = getSubjects()
var ldReminders = getReminders()
if (ldSubjects != null && ldReminders != null) {
return CombinedSubjectReminders(ldSubjects, ldReminders)
}
return null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment