Skip to content

Commit

Permalink
Added prefillAndOpenForm method to ODKInteractor.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmoy12c committed Mar 17, 2023
1 parent 3856173 commit fff278d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ class ODKHandler @Inject constructor(
}
}

override fun prefillAndOpenForm(formId: String, tagValueMap: HashMap<String, String>, context: Context) {
CoroutineScope(Job()).launch {
val compositeDisposable = CompositeDisposable()
compositeDisposable.add(FormEventBus.getState().subscribe { event ->
when (event) {
is FormStateEvent.OnFormSaved -> {
if (event.formId == formId) {
val prefilledInstance = formInstanceInteractor.getInstanceByPath(event.instancePath)
if (prefilledInstance != null) {
formInstanceInteractor.openInstance(prefilledInstance, context)
}
else {
FormEventBus.formOpenFailed(formId, "Form instance cannot be found!")
}
compositeDisposable.clear()
}
}
is FormStateEvent.OnFormOpenFailed -> if (event.formId == formId) compositeDisposable.clear()
is FormStateEvent.OnFormSaveError -> if (event.formId == formId) compositeDisposable.clear()
else -> {}
}
})
formsInteractor.prefillForm(formId, tagValueMap)
}
}

private fun downloadAndOpenForm(formId: String, context: Context) {
formsNetworkInteractor.downloadFormById(formId, object : FileDownloadListener {
override fun onComplete(downloadedFile: File) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ interface ODKInteractor {

/** Opens a saved form. If no saved instance is found, opens a new form. */
fun openSavedForm(formId: String, context: Context)

fun prefillAndOpenForm(formId: String, tagValueMap: HashMap<String, String>, context: Context)
}

0 comments on commit fff278d

Please sign in to comment.