Skip to content

Commit

Permalink
Merge pull request getodk#1953 from lognaturel/collect-1952
Browse files Browse the repository at this point in the history
Use auto-send attribute instead of auto-submit
  • Loading branch information
yanokwa authored Mar 2, 2018
2 parents 3c34e83 + dda4218 commit cc455c3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static android.provider.BaseColumns._ID;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.AUTO_DELETE;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.AUTO_SUBMIT;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.AUTO_SEND;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.BASE64_RSA_PUBLIC_KEY;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.DATE;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.DESCRIPTION;
Expand Down Expand Up @@ -260,7 +260,7 @@ private boolean upgradeToVersion5(SQLiteDatabase db) {
.begin(db)
.alter()
.table(FORMS_TABLE_NAME)
.addColumn(AUTO_SUBMIT, "text")
.addColumn(AUTO_SEND, "text")
.end();

CustomSQLiteQueryBuilder
Expand Down Expand Up @@ -292,7 +292,7 @@ private void createFormsTable(SQLiteDatabase db, String tableName) {
+ SUBMISSION_URI + " text, "
+ BASE64_RSA_PUBLIC_KEY + " text, "
+ JRCACHE_FILE_PATH + " text not null, "
+ AUTO_SUBMIT + " text,"
+ AUTO_SEND + " text,"
+ AUTO_DELETE + " text);");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,6 @@ public int update(Uri uri, ContentValues values, String where,
sFormsProjectionMap.put(FormsColumns.JRCACHE_FILE_PATH, FormsColumns.JRCACHE_FILE_PATH);
sFormsProjectionMap.put(FormsColumns.LANGUAGE, FormsColumns.LANGUAGE);
sFormsProjectionMap.put(FormsColumns.AUTO_DELETE, FormsColumns.AUTO_DELETE);
sFormsProjectionMap.put(FormsColumns.AUTO_SUBMIT, FormsColumns.AUTO_SUBMIT);
sFormsProjectionMap.put(FormsColumns.AUTO_SEND, FormsColumns.AUTO_SEND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private FormsColumns() {
public static final String SUBMISSION_URI = "submissionUri"; // can be null
public static final String BASE64_RSA_PUBLIC_KEY = "base64RsaPublicKey"; // can be null
public static final String AUTO_DELETE = "autoDelete"; // can be null
public static final String AUTO_SUBMIT = "autoSubmit"; // can be null
// Column is called autoSubmit for legacy support but the attribute is auto-send
public static final String AUTO_SEND = "autoSubmit"; // can be null

// these are generated for you (but you can insert something else if you want)
public static final String DISPLAY_SUBTEXT = "displaySubtext";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.Iterator;
import java.util.Set;

import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.AUTO_SUBMIT;
import static org.odk.collect.android.provider.FormsProviderAPI.FormsColumns.AUTO_SEND;

public class NetworkReceiver extends BroadcastReceiver implements InstanceUploaderListener {

Expand Down Expand Up @@ -158,20 +158,20 @@ private void uploadForms(Context context, boolean isFormAutoSendOptionEnabled) {
/**
* @param isFormAutoSendOptionEnabled represents whether the auto-send option is enabled at the app level
*
* If the form explicitly sets the auto-submit property, then it overrides the preferences.
* If the form explicitly sets the auto-send property, then it overrides the preferences.
*/
private boolean isFormAutoSendEnabled(String jrFormId, boolean isFormAutoSendOptionEnabled) {
Cursor cursor = new FormsDao().getFormsCursorForFormId(jrFormId);
String autoSubmit = null;
String autoSend = null;
if (cursor != null && cursor.moveToFirst()) {
try {
int autoSubmitColumnIndex = cursor.getColumnIndex(AUTO_SUBMIT);
autoSubmit = cursor.getString(autoSubmitColumnIndex);
int autoSendColumnIndex = cursor.getColumnIndex(AUTO_SEND);
autoSend = cursor.getString(autoSendColumnIndex);
} finally {
cursor.close();
}
}
return autoSubmit == null ? isFormAutoSendOptionEnabled : Boolean.valueOf(autoSubmit);
return autoSend == null ? isFormAutoSendOptionEnabled : Boolean.valueOf(autoSend);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private ContentValues buildContentValues(File formDefFile) throws IllegalArgumen
updateValues.put(FormsColumns.BASE64_RSA_PUBLIC_KEY, base64RsaPublicKey);
}
updateValues.put(FormsColumns.AUTO_DELETE, fields.get(FileUtils.AUTO_DELETE));
updateValues.put(FormsColumns.AUTO_SUBMIT, fields.get(FileUtils.AUTO_SUBMIT));
updateValues.put(FormsColumns.AUTO_SEND, fields.get(FileUtils.AUTO_SEND));

// Note, the path doesn't change here, but it needs to be included so the
// update will automatically update the .md5 and the cache path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private Uri saveNewForm(Map<String, String> formInfo, File formFile, String medi
v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI));
v.put(FormsColumns.BASE64_RSA_PUBLIC_KEY, formInfo.get(FileUtils.BASE64_RSA_PUBLIC_KEY));
v.put(FormsColumns.AUTO_DELETE, formInfo.get(FileUtils.AUTO_DELETE));
v.put(FormsColumns.AUTO_SUBMIT, formInfo.get(FileUtils.AUTO_SUBMIT));
v.put(FormsColumns.AUTO_SEND, formInfo.get(FileUtils.AUTO_SEND));
Uri uri = formsDao.saveForm(v);
Collect.getInstance().getActivityLogger().logAction(this, "insert",
formFile.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class FileUtils {
public static final String SUBMISSIONURI = "submission";
public static final String BASE64_RSA_PUBLIC_KEY = "base64RsaPublicKey";
public static final String AUTO_DELETE = "autoDelete";
public static final String AUTO_SUBMIT = "autoSubmit";
public static final String AUTO_SEND = "autoSend";
static int bufSize = 16 * 1024; // May be set by unit test

private FileUtils() {
Expand Down Expand Up @@ -369,13 +369,14 @@ public static HashMap<String, String> parseXML(File xmlFile) {
final Element submission = model.getElement(xforms, "submission");
final String base64RsaPublicKey = submission.getAttributeValue(null, "base64RsaPublicKey");
final String autoDelete = submission.getAttributeValue(null, "auto-delete");
final String autoSubmit = submission.getAttributeValue(null, "auto-submit");
final String autoSend = submission.getAttributeValue(null, "auto-send");

fields.put(SUBMISSIONURI, submission.getAttributeValue(null, "action"));
fields.put(BASE64_RSA_PUBLIC_KEY,
(base64RsaPublicKey == null || base64RsaPublicKey.trim().length() == 0)
? null : base64RsaPublicKey.trim());
fields.put(AUTO_DELETE, autoDelete);
fields.put(AUTO_SUBMIT, autoSubmit);
fields.put(AUTO_SEND, autoSend);
} catch (Exception e) {
Timber.i("XML file %s does not have a submission element", xmlFile.getAbsolutePath());
// and that's totally fine.
Expand Down

0 comments on commit cc455c3

Please sign in to comment.