Skip to content

Commit

Permalink
Cancel Google sheet form upload when activity destroyed (getodk#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshyagupta21 authored and lognaturel committed Apr 30, 2018
1 parent b53d492 commit 735f6f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ protected void onStop() {
@Override
protected void onDestroy() {
if (instanceGoogleSheetsUploader != null) {
if (!instanceGoogleSheetsUploader.isCancelled()) {
instanceGoogleSheetsUploader.cancel(true);
}
instanceGoogleSheetsUploader.setUploaderListener(null);
}
finish();
super.onDestroy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ private void insertRow(TreeElement element, String parentKey, String key, File i
List<Object> columnTitles = getColumnTitles(element);
ensureNumberOfColumnsIsValid(columnTitles.size());

if (isCancelled()) {
throw new UploadException(Collect.getInstance().getString(R.string.instance_upload_cancelled));
}

try {
List<List<Object>> sheetCells = getSheetCells(sheetTitle);
if (sheetCells != null && !sheetCells.isEmpty()) { // we are editing an existed sheet
Expand All @@ -264,6 +268,11 @@ private void insertRow(TreeElement element, String parentKey, String key, File i
}

HashMap<String, String> answers = getAnswers(element, instanceFile, parentKey, key);

if (isCancelled()) {
throw new UploadException(Collect.getInstance().getString(R.string.instance_upload_cancelled));
}

if (shouldRowBeInserted(answers)) {
sheetsHelper.insertRow(spreadsheet.getSpreadsheetId(), sheetTitle,
new ValueRange().setValues(Collections.singletonList(prepareListOfValues(sheetCells.get(0), columnTitles, answers))));
Expand Down
1 change: 1 addition & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,5 @@
<string name="no_columns_to_upload">No columns found in the form to upload.</string>
<string name="cannot_create_directory">Cannot create directory: %s</string>
<string name="not_a_directory">%s exists, but is not a directory</string>
<string name="instance_upload_cancelled">Instance upload cancelled</string>
</resources>

0 comments on commit 735f6f8

Please sign in to comment.