Ниже мой код, я использую две функции в mvvm и хочу вызывать одну за другой ........................
ViewModel
fun getRefillDevicesForFirstTime() {
pull = DBConnector.getPullReplecation(database, couch_db_url.plus("/----").plus(db_id))
pull?.addChangeListener { event ->
if (pull?.status == Replication.ReplicationStatus.REPLICATION_IDLE && event.completedChangeCount == event.changeCount) {
val query = database?.createAllDocumentsQuery()
query?.allDocsMode = Query.AllDocsMode.ALL_DOCS
query?.run()
refillDeviceList()
}
}
}
fun refillDeviceList()
{ progressBarVisibility.postValue(1)
val obj = JSONObject(database?.getDocument("refill-device")?.properties)
val gson = Gson()
refillDeviceListModel = gson.fromJson<RefillDeviceListModel>(
obj.toString(),
RefillDeviceListModel::class.java
)
refillDevicesList.postValue(refillDeviceListModel.data?.devices)
progressBarVisibility.postValue(0)
}
и фрагмент кода;
viewModel.getRefillDevicesForFirstTime()
viewModel.refillDevicesList.observe(viewLifecycleOwner, Observer { it ->
layoutActiveRefillDeviceBinding.rvRefillDeviceList.layoutManager = LinearLayoutManager(
layoutActiveRefillDeviceBinding.rvRefillDeviceList.context, RecyclerView.VERTICAL, false
)
layoutActiveRefillDeviceBinding.rvRefillDeviceList.adapter =
RefillDeviceAdapter(it, refillDeviceListViewModel)
})
Как позвонить refillDeviceList()
после завершения вызова sh из refillDeviceList()
?