Skip to content

Commit

Permalink
Merge pull request #2192 from dimagi/fix-missing-attachment
Browse files Browse the repository at this point in the history
Fix mismatched attachments while editing a saved form
  • Loading branch information
ShivamPokhriyal authored Mar 5, 2020
2 parents 9f67708 + 6cb574e commit 30b3711
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/src/org/commcare/activities/FormEntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ private void resetPendingCalloutIndex() {
public void saveImageWidgetAnswer(String imagePath) {
uiController.questionsView.setBinaryData(imagePath, mFormController);
saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS);
onExternalAttachmentUpdated();
uiController.refreshView();
}

Expand All @@ -370,6 +371,7 @@ private void processChooserResponse(Intent intent) {
uiController.questionsView.setBinaryData(media, mFormController);
}
saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS);
onExternalAttachmentUpdated();
uiController.refreshView();
}

Expand Down Expand Up @@ -701,6 +703,21 @@ private void saveIncompleteFormToDisk() {
saveDataToDisk(FormEntryConstants.EXIT, false, null, true);
}

/**
* Attempts to update the form in the disk when user changes the attachment.
* NOTE:- This fixes the mismatch in attachments while trying to update attachments in a saved form.
*/
protected void onExternalAttachmentUpdated() {
FormRecord formRecord = FormRecord.getFormRecord(formRecordStorage, FormEntryInstanceState.mFormRecordPath);
if (formRecord == null) {
return;
}
String formStatus = formRecord.getStatus();
if (FormRecord.STATUS_INCOMPLETE.equals(formStatus)) {
saveDataToDisk(false, false, null, true);
}
}

private void showSaveErrorAndExit() {
Toast.makeText(this, Localization.get("form.entry.save.error"), Toast.LENGTH_SHORT).show();
hasSaved = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.commcare.views.dialogs.HorizontalPaneledChoiceDialog;
import org.commcare.views.dialogs.PaneledChoiceDialog;
import org.commcare.views.media.AudioController;
import org.commcare.views.widgets.ImageWidget;
import org.commcare.views.widgets.IntentWidget;
import org.commcare.views.widgets.QuestionWidget;
import org.javarosa.core.model.Constants;
Expand Down Expand Up @@ -737,6 +738,13 @@ protected void updateFormRelevancies() {
shouldRemoveFromView.add(i);
continue;
}

if (oldWidgets.get(i) instanceof ImageWidget) {
// If there was change(in particular image-remove) in an image widget,
// only then update the form to disk.
activity.onExternalAttachmentUpdated();
}

FormEntryPrompt oldPrompt = oldWidgets.get(i).getPrompt();
String priorQuestionTextForThisWidget = oldQuestionTexts.get(i);
Vector<SelectChoice> priorSelectChoicesForThisWidget = oldSelectChoices.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.commcare.views.widgets.QuestionWidget;
import org.javarosa.core.model.SelectChoice;
import org.javarosa.core.model.data.IAnswerData;
import org.javarosa.form.api.FormEntryPrompt;

import java.util.ArrayList;
Expand Down
1 change: 1 addition & 0 deletions app/src/org/commcare/views/widgets/ImageWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public ImageWidget(final Context context, FormEntryPrompt prompt, PendingCallout
!mPrompt.isReadOnly());
mDiscardButton.setOnClickListener(v -> {
deleteMedia();
widgetEntryChanged();
});
mDiscardButton.setVisibility(View.GONE);

Expand Down

0 comments on commit 30b3711

Please sign in to comment.