use of org.odk.collect.android.preferences.GeneralSharedPreferences in project collect by opendatakit.
the class NetworkReceiver method uploadForms.
/**
* @param isFormAutoSendOptionEnabled represents whether the auto-send option is enabled at the app level
*/
private void uploadForms(Context context, boolean isFormAutoSendOptionEnabled) {
if (!running) {
running = true;
ArrayList<Long> toUpload = new ArrayList<>();
Cursor c = new InstancesDao().getFinalizedInstancesCursor();
try {
if (c != null && c.getCount() > 0) {
c.move(-1);
String formId;
while (c.moveToNext()) {
formId = c.getString(c.getColumnIndex(InstanceColumns.JR_FORM_ID));
if (isFormAutoSendEnabled(formId, isFormAutoSendOptionEnabled)) {
Long l = c.getLong(c.getColumnIndex(InstanceColumns._ID));
toUpload.add(l);
}
}
}
} finally {
if (c != null) {
c.close();
}
}
if (toUpload.size() < 1) {
running = false;
return;
}
Long[] toSendArray = new Long[toUpload.size()];
toUpload.toArray(toSendArray);
GeneralSharedPreferences settings = GeneralSharedPreferences.getInstance();
String protocol = (String) settings.get(PreferenceKeys.KEY_PROTOCOL);
if (protocol.equals(context.getString(R.string.protocol_google_sheets))) {
String googleUsername = (String) settings.get(PreferenceKeys.KEY_SELECTED_GOOGLE_ACCOUNT);
if (googleUsername == null || googleUsername.isEmpty()) {
// just quit if there's no username
running = false;
return;
}
GoogleAccountsManager accountsManager = new GoogleAccountsManager(Collect.getInstance());
accountsManager.getCredential().setSelectedAccountName(googleUsername);
instanceGoogleSheetsUploader = new InstanceGoogleSheetsUploader(accountsManager);
instanceGoogleSheetsUploader.setUploaderListener(this);
instanceGoogleSheetsUploader.execute(toSendArray);
} else {
// get the username, password, and server from preferences
String storedUsername = (String) settings.get(PreferenceKeys.KEY_USERNAME);
String storedPassword = (String) settings.get(PreferenceKeys.KEY_PASSWORD);
String server = (String) settings.get(PreferenceKeys.KEY_SERVER_URL);
String url = server + settings.get(PreferenceKeys.KEY_FORMLIST_URL);
Uri u = Uri.parse(url);
WebUtils.addCredentials(storedUsername, storedPassword, u.getHost());
instanceServerUploader = new InstanceServerUploader();
instanceServerUploader.setUploaderListener(this);
instanceServerUploader.execute(toSendArray);
}
}
}
use of org.odk.collect.android.preferences.GeneralSharedPreferences in project collect by opendatakit.
the class SharedPreferencesTest method generalSharedPreferencesUpgradeTest.
@Test
public void generalSharedPreferencesUpgradeTest() {
GeneralSharedPreferences.getInstance().save(KEY_COMPLETED_DEFAULT, false);
GeneralSharedPreferences.getInstance().reloadPreferences();
HashMap<String, Object> defaultValues = PreferenceKeys.GENERAL_KEYS;
GeneralSharedPreferences generalSharedPreferences = GeneralSharedPreferences.getInstance();
for (String key : SharedPreferencesUtils.getAllGeneralKeys()) {
if (key.equals(KEY_COMPLETED_DEFAULT)) {
assertEquals(generalSharedPreferences.get(key), false);
} else {
assertEquals(generalSharedPreferences.get(key), defaultValues.get(key));
}
}
}
use of org.odk.collect.android.preferences.GeneralSharedPreferences in project collect by opendatakit.
the class SharedPreferencesTest method generalDefaultSharedPreferencesTest.
@Test
public void generalDefaultSharedPreferencesTest() {
GeneralSharedPreferences.getInstance().loadDefaultPreferences();
HashMap<String, Object> defaultValues = PreferenceKeys.GENERAL_KEYS;
GeneralSharedPreferences generalSharedPreferences = GeneralSharedPreferences.getInstance();
for (String key : SharedPreferencesUtils.getAllGeneralKeys()) {
assertEquals(generalSharedPreferences.get(key), defaultValues.get(key));
}
}
Aggregations