I have a problem with MediatorLiveData
. I want to get data from database, in class which is not ViewModel. I would like to point that methods which downloads data works in ViewModel, but when I want to invoke it in other class it doesn't work. This is a code:
class MyReceiver: BroadcastReceiver() {
@Inject
lateinit var jobsRepository: jobsRepository
private val _jobStatusDone = MediatorLiveData<Boolean>()
val jobStatusDone: LiveData<Boolean>
get() = _jobStatusDone
private val _counterparties = MediatorLiveData<List<Counterparty>>()
override fun onReceive(context: Context?, intent: Intent?) {
AndroidInjection.inject(this, context)
val source = jobsRepository.getFulljobs()
_jobStatusDone.addSource(source) {
System.out.println("IT NEVER REACHES THIS PLACE.")
}
}
}
}
It's interesting because updating/inserting works.
EDIT: I would like to point that code I posted here, works in ViewModel's classes.