use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class FormUpdateAndInstanceSubmitScheduler method scheduleUpdates.
@Override
public void scheduleUpdates(String projectId) {
Settings generalSettings = settingsProvider.getUnprotectedSettings(projectId);
String protocol = generalSettings.getString(KEY_PROTOCOL);
if (protocol.equals(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
scheduler.cancelDeferred(getMatchExactlyTag(projectId));
scheduler.cancelDeferred(getAutoUpdateTag(projectId));
return;
}
String period = generalSettings.getString(KEY_PERIODIC_FORM_UPDATES_CHECK);
long periodInMilliseconds = getPeriodInMilliseconds(period, application);
switch(getFormUpdateMode(application, generalSettings)) {
case MANUAL:
scheduler.cancelDeferred(getMatchExactlyTag(projectId));
scheduler.cancelDeferred(getAutoUpdateTag(projectId));
break;
case PREVIOUSLY_DOWNLOADED_ONLY:
scheduler.cancelDeferred(getMatchExactlyTag(projectId));
scheduleAutoUpdate(periodInMilliseconds, projectId);
break;
case MATCH_EXACTLY:
scheduler.cancelDeferred(getAutoUpdateTag(projectId));
scheduleMatchExactly(periodInMilliseconds, projectId);
break;
}
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class FormManagementPreferencesFragment method updateDisabledPrefs.
private void updateDisabledPrefs() {
Settings generalSettings = settingsProvider.getUnprotectedSettings();
// Might be null if disabled in Protected settings
@Nullable Preference updateFrequency = findPreference(KEY_PERIODIC_FORM_UPDATES_CHECK);
@Nullable CheckBoxPreference automaticDownload = findPreference(KEY_AUTOMATIC_UPDATE);
if (generalSettings.getString(KEY_PROTOCOL).equals(ProjectKeys.PROTOCOL_GOOGLE_SHEETS)) {
displayDisabled(findPreference(KEY_FORM_UPDATE_MODE), getString(R.string.manual));
if (automaticDownload != null) {
displayDisabled(automaticDownload, false);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(false);
}
} else {
switch(getFormUpdateMode(requireContext(), generalSettings)) {
case MANUAL:
if (automaticDownload != null) {
displayDisabled(automaticDownload, false);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(false);
}
break;
case PREVIOUSLY_DOWNLOADED_ONLY:
if (automaticDownload != null) {
automaticDownload.setEnabled(true);
automaticDownload.setChecked(generalSettings.getBoolean(KEY_AUTOMATIC_UPDATE));
}
if (updateFrequency != null) {
updateFrequency.setEnabled(true);
}
break;
case MATCH_EXACTLY:
if (automaticDownload != null) {
displayDisabled(automaticDownload, true);
}
if (updateFrequency != null) {
updateFrequency.setEnabled(true);
}
break;
}
}
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class PrefUtils method ensurePrefHasValidValue.
private static void ensurePrefHasValidValue(String key, String[] validValues) {
Settings prefs = getSharedPrefs();
String value = prefs.getString(key);
if (Arrays.asList(validValues).indexOf(value) < 0) {
if (validValues.length > 0) {
prefs.save(key, validValues[0]);
} else {
prefs.remove(key);
}
}
}
use of org.odk.collect.shared.settings.Settings in project collect by opendatakit.
the class ServerAuthDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
ServerAuthDialogBinding binding = ServerAuthDialogBinding.inflate(requireActivity().getLayoutInflater());
dialogView = binding.getRoot();
Settings generalSettings = settingsProvider.getUnprotectedSettings();
binding.usernameEdit.setText(generalSettings.getString(ProjectKeys.KEY_USERNAME));
binding.passwordEdit.setText(generalSettings.getString(ProjectKeys.KEY_PASSWORD));
return new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.server_requires_auth).setMessage(requireContext().getString(R.string.server_auth_credentials, generalSettings.getString(ProjectKeys.KEY_SERVER_URL))).setView(dialogView).setPositiveButton(R.string.ok, (dialogInterface, i) -> {
generalSettings.save(ProjectKeys.KEY_USERNAME, binding.usernameEdit.getText().toString());
generalSettings.save(ProjectKeys.KEY_PASSWORD, binding.passwordEdit.getText().toString());
}).create();
}
Aggregations