Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) {
super.onViewCreated(view, savedInstanceState)
if (savedInstanceState != null) {
orchestratorVm.requestProcessed = savedInstanceState.getBoolean(KEY_REQUEST_PROCESSED)
savedInstanceState.getString(KEY_ACTION_REQUEST)
?.run(orchestratorVm::setActionRequestFromJson)
}
observeLoginCheckVm()
observeClientApiVm()
Expand Down Expand Up @@ -180,6 +182,10 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) {
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putBoolean(KEY_REQUEST_PROCESSED, orchestratorVm.requestProcessed)
// [MS-405] Saving the action request in the bundle, since ViewModels don't survive the
// process death. ActionRequest is important in mapping the correct SID response, hence it
// is important for it to be able to survive both configuration changes and process death.
outState.putString(KEY_ACTION_REQUEST, orchestratorVm.getActionRequestJson())
}

override fun onResume() {
Expand All @@ -201,5 +207,6 @@ internal class OrchestratorFragment : Fragment(R.layout.fragment_orchestrator) {

companion object {
private const val KEY_REQUEST_PROCESSED = "requestProcessed"
private const val KEY_ACTION_REQUEST = "actionRequest"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.simprints.core.livedata.LiveDataEventWithContent
import com.simprints.core.livedata.send
import com.simprints.core.tools.json.JsonHelper
import com.simprints.face.capture.FaceCaptureResult
import com.simprints.feature.orchestrator.cache.OrchestratorCache
import com.simprints.feature.orchestrator.model.OrchestratorResult
Expand Down Expand Up @@ -161,4 +162,20 @@ internal class OrchestratorViewModel @Inject constructor(
}
}
}
fun setActionRequestFromJson(json: String) {
try {
actionRequest = JsonHelper.fromJson<ActionRequest>(json)
} catch (e: Exception) {
Simber.e(e)
}
}

fun getActionRequestJson(): String? {
return try {
actionRequest?.run(JsonHelper::toJson)
} catch (e: Exception) {
Simber.e(e)
null
}
}
}