This is my vide Model :
class Rove2LiveVideoViewModelImpl @Inject constructor(
override val stateLiveData: MutableLiveData<CameraR2Status>,
private val roveR2UseCase: RoveR2UseCase,
private val roveR2LiveVideoUseCase: RoveR2LiveVideoUseCase,
private val appPreference: AppPreference
) : Rove2LiveVideoViewModel(), RoveR2UseCase.Callback, RoveR2LiveVideoUseCase.Callback {
init {
roveR2UseCase.setCallback(this)
roveR2LiveVideoUseCase.setCallback(this)
}
override fun onSuccessAudioMode(response: CardStatusResponse?) {
stateLiveData.value = AudioModeStatus(response?.status.toString())
}
override fun onSuccessUpdatedRecordingStatus(response: CardStatusResponse?) {
stateLiveData.value = RecordingStatus(response?.status.toString())
}
override fun onSuccessSettingResponse(response: SettingsResponse?) {
response?.let {
it.cmd.forEachIndexed { index, item ->
if (item == "2007") {
stateLiveData.value = AudioModeStatus(it.status[index])
}
}
it.cmd.forEachIndexed { index, item ->
if (item == "2001") {
stateLiveData.value = RecordingStatus(it.status[index])
}
}
}
}
}
This is my fragment i am observing like this
rove2LiveVideoViewModel.apply {
getR2CameraConnectedOrNot()
observe(stateLiveData, ::onRoveR2CameraResponse)
}
private fun onRoveR2CameraResponse(state: BaseViewModel.CameraR2Status) {
when (state) {
is BaseViewModel.CameraR2Status.AudioModeStatus -> {
r2VideoControlWidget.showAudioStatusIcon(state.data)
}
is BaseViewModel.CameraR2Status.RecordingStatus -> {
showLiveVideoWhenR2Connected()
when (state.data) {
"1" -> {
r2VideoControlWidget.showPlayStopButton(true)
}
"0" -> r2VideoControlWidget.showPlayStopButton(false)
}
}
}
}
firs time when we call function i am getting call back in fragment onRoveR2CameraResponse method but when i call function again second i am getting call back in viewmodel from API but mutable live data not sending call back to fragment so that i can update view can any one help me in this what i am doing wrong do we need to create different live data for each method please suggest
from Mutable Live Data not sending value in Fragment second time in Android
No comments:
Post a Comment