use of org.odk.collect.android.formentry.ODKView in project collect by opendatakit.
the class FormEntryActivity method onDataChanged.
private void onDataChanged(Object data) {
ODKView odkView = getCurrentViewIfODKView();
if (odkView != null) {
QuestionWidget widgetGettingNewValue = getWidgetWaitingForBinaryData();
setWidgetData(data);
widgetValueChanged(widgetGettingNewValue);
}
}
use of org.odk.collect.android.formentry.ODKView in project collect by opendatakit.
the class FormEntryActivity method setWidgetData.
public void setWidgetData(Object data) {
ODKView currentViewIfODKView = getCurrentViewIfODKView();
if (currentViewIfODKView != null) {
boolean set = false;
for (QuestionWidget widget : currentViewIfODKView.getWidgets()) {
if (widget instanceof WidgetDataReceiver) {
if (waitingForDataRegistry.isWaitingForData(widget.getFormEntryPrompt().getIndex())) {
try {
((WidgetDataReceiver) widget).setData(data);
waitingForDataRegistry.cancelWaitingForData();
} catch (Exception e) {
Timber.e(e);
ToastUtils.showLongToast(this, currentViewIfODKView.getContext().getString(R.string.error_attaching_binary_file, e.getMessage()));
}
set = true;
break;
}
}
}
if (!set) {
Timber.e("Attempting to return data to a widget or set of widgets not looking for data");
}
}
}
use of org.odk.collect.android.formentry.ODKView in project collect by opendatakit.
the class FormEntryActivity method createODKView.
@NotNull
private ODKView createODKView(boolean advancingPage, FormEntryPrompt[] prompts, FormEntryCaption[] groups) {
odkViewLifecycle.start();
AudioClipViewModel.Factory factory = new AudioClipViewModel.Factory(MediaPlayer::new, scheduler);
ViewModelAudioPlayer viewModelAudioPlayer = new ViewModelAudioPlayer(ViewModelProviders.of(this, factory).get(AudioClipViewModel.class), odkViewLifecycle);
return new ODKView(this, prompts, groups, advancingPage, formSaveViewModel, waitingForDataRegistry, viewModelAudioPlayer, audioRecorder, formEntryViewModel, internalRecordingRequester, externalAppRecordingRequester);
}
use of org.odk.collect.android.formentry.ODKView in project collect by opendatakit.
the class FormEntryActivity method saveAnswersForCurrentScreen.
// The method saves questions one by one in order to support calculations in field-list groups
private void saveAnswersForCurrentScreen(FormEntryPrompt[] mutableQuestionsBeforeSave, List<ImmutableDisplayableQuestion> immutableQuestionsBeforeSave) {
FormController formController = getFormController();
ODKView currentView = getCurrentViewIfODKView();
if (formController == null || currentView == null) {
return;
}
int index = 0;
for (Map.Entry<FormIndex, IAnswerData> answer : currentView.getAnswers().entrySet()) {
// Questions with calculates will have their answers updated as the questions they depend on are saved
if (!isQuestionRecalculated(mutableQuestionsBeforeSave[index], immutableQuestionsBeforeSave.get(index))) {
try {
formController.saveOneScreenAnswer(answer.getKey(), answer.getValue(), false);
} catch (JavaRosaException e) {
Timber.e(e);
}
}
index++;
}
}
use of org.odk.collect.android.formentry.ODKView in project collect by opendatakit.
the class FormEntryActivity method updateSelectedItems.
/*
*TODO: this is not an ideal way to solve communication between a dialog created by a widget and the widget.
* Instead we should use viewmodels: https://github.com/getodk/collect/pull/3964#issuecomment-670155433
*/
@Override
public void updateSelectedItems(List<Selection> items) {
ODKView odkView = getCurrentViewIfODKView();
if (odkView != null) {
QuestionWidget widgetGettingNewValue = getWidgetWaitingForBinaryData();
setWidgetData(items);
widgetValueChanged(widgetGettingNewValue);
}
}
Aggregations