Hi,
In Android MVVM architecture, I am trying to @Inject ISuspendable through ViewModelModule, as I cannot pass this to my VMModel constructor.
@Module
abstract class ViewModelModule {
@Singleton
@Binds
abstract fun getSuspendable(aSuspendable: ACMSuspendableImpl): ISuspendable
@Binds
@IntoMap
@ViewModelKey(MonitorViewModel::class)
abstract fun bindsMonitorViewModell(monitorViewModel: MonitorViewModel): ViewModel
}
@Singleton
class ACMSuspendableImpl @Inject constructor() : ISuspendable {
override fun decrementSuspend() {
}
override fun suspendUpdates(): IUpdateSuspender {
TODO("not implemented")
}
override fun getIsSuspended(): Boolean {
TODO("not implemented")
}
override fun resumeUpdates(p0: IUpdateSuspender?) {
}
}
whereas my MonitorViewModel class as,
class MonitorViewModel @Inject constructor(context: Context) : BaseViewModel() {
@Inject
lateinit var acmSuspend: ISuspendable
private fun loadMonitorData() {
UpdateSuspender.using(acmSuspend) { //<! NULL ->
iapDataSeries.append(Timestamp.valueOf(mData100Hz.getRtcTimeStamp().toString()), mData100Hz.emr.iap)
uoColumnDataSeries.append(
Timestamp.valueOf(mData100Hz.getRtcTimeStamp().toString()),
mData100Hz.emr.totalVolume
)
}
}
How should I @Inject ISuspendable so that it should not be NULL. Please provide me some example snipped to work.
FYI,
I tried to follow the ECGViewModel but this sample used some custom solution and there is no use of DI.
BR,
Praween
- Praween Kumar asked 5 years ago
- last active 5 years ago