use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class SettingsUtilsTest method getFormUpdateMode_whenProtocolIsGoogleDrive_andModeNotManual_returnsManual.
@Test
public void getFormUpdateMode_whenProtocolIsGoogleDrive_andModeNotManual_returnsManual() {
Settings generalSettings = TestSettingsProvider.getUnprotectedSettings();
Context context = getApplicationContext();
generalSettings.save(ProjectKeys.KEY_PROTOCOL, ProjectKeys.PROTOCOL_GOOGLE_SHEETS);
generalSettings.save(ProjectKeys.KEY_FORM_UPDATE_MODE, FormUpdateMode.PREVIOUSLY_DOWNLOADED_ONLY.getValue(context));
FormUpdateMode formUpdateMode = SettingsUtils.getFormUpdateMode(context, generalSettings);
assertThat(formUpdateMode, is(FormUpdateMode.MANUAL));
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class WebCredentialsUtilsTest method saveCredentialsPreferencesMethod_shouldSaveNewCredentialsAndReloadPropertyManager.
@Test
public void saveCredentialsPreferencesMethod_shouldSaveNewCredentialsAndReloadPropertyManager() {
Settings generalSettings = mock(Settings.class);
WebCredentialsUtils webCredentialsUtils = new WebCredentialsUtils(generalSettings);
PropertyManager propertyManager = mock(PropertyManager.class);
webCredentialsUtils.saveCredentialsPreferences("username", "password", propertyManager);
verify(generalSettings, times(1)).save(ProjectKeys.KEY_USERNAME, "username");
verify(generalSettings, times(1)).save(ProjectKeys.KEY_PASSWORD, "password");
verify(propertyManager, times(1)).reload();
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class AdminPasswordProviderTest method when_adminPassIsSetProperly_should_isAdminPasswordSetReturnTrue.
@Test
public void when_adminPassIsSetProperly_should_isAdminPasswordSetReturnTrue() {
Settings adminSharedPreferences = mock(Settings.class);
when(adminSharedPreferences.getString(KEY_ADMIN_PW)).thenReturn("123");
AdminPasswordProvider adminPasswordProvider = new AdminPasswordProvider(adminSharedPreferences);
assertThat(adminPasswordProvider.isAdminPasswordSet(), is(true));
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class MapProvider method onMapFragmentStart.
void onMapFragmentStart(MapFragment map) {
MapConfigurator cftor = configuratorsByMap.get(map);
if (cftor != null) {
Settings generalSettings = PrefUtils.getSharedPrefs();
Settings.OnSettingChangeListener listener = key -> {
if (cftor.getPrefKeys().contains(key)) {
map.applyConfig(cftor.buildConfig(generalSettings));
}
};
map.applyConfig(cftor.buildConfig(generalSettings));
generalSettings.registerOnSettingChangeListener(listener);
listenersByMap.put(map, listener);
}
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class InstanceAutoSender method autoSendInstances.
public boolean autoSendInstances(String projectId) {
FormsRepository formsRepository = formsRepositoryProvider.get(projectId);
InstancesRepository instancesRepository = instancesRepositoryProvider.get(projectId);
Settings generalSettings = settingsProvider.getUnprotectedSettings(projectId);
InstanceSubmitter instanceSubmitter = new InstanceSubmitter(analytics, formsRepository, instancesRepository, googleAccountsManager, googleApiProvider, permissionsProvider, generalSettings);
return changeLockProvider.getInstanceLock(projectId).withLock(acquiredLock -> {
if (acquiredLock) {
try {
List<Instance> toUpload = getInstancesToAutoSend(formsRepository, instancesRepository, generalSettings);
Pair<Boolean, String> results = instanceSubmitter.submitInstances(toUpload);
notifier.onSubmission(results.first, results.second, projectId);
} catch (SubmitException e) {
switch(e.getType()) {
case GOOGLE_ACCOUNT_NOT_SET:
notifier.onSubmission(true, context.getString(R.string.google_set_account), projectId);
break;
case GOOGLE_ACCOUNT_NOT_PERMITTED:
notifier.onSubmission(true, context.getString(R.string.odk_permissions_fail), projectId);
break;
case NOTHING_TO_SUBMIT:
break;
}
}
instancesAppState.update();
return true;
} else {
return false;
}
});
}
Aggregations