Search in sources :

Example 16 with Settings

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;
    }
}
Also used : Settings(org.odk.collect.shared.settings.Settings)

Example 17 with Settings

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;
        }
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) Preference(androidx.preference.Preference) ListPreference(androidx.preference.ListPreference) CheckBoxPreference(androidx.preference.CheckBoxPreference) Settings(org.odk.collect.shared.settings.Settings) Nullable(androidx.annotation.Nullable)

Example 18 with Settings

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);
        }
    }
}
Also used : Settings(org.odk.collect.shared.settings.Settings)

Example 19 with Settings

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();
}
Also used : Context(android.content.Context) ProjectKeys(org.odk.collect.settings.keys.ProjectKeys) Bundle(android.os.Bundle) SettingsProvider(org.odk.collect.settings.SettingsProvider) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Dialog(android.app.Dialog) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Nullable(androidx.annotation.Nullable) ServerAuthDialogBinding(org.odk.collect.android.databinding.ServerAuthDialogBinding) R(org.odk.collect.android.R) View(android.view.View) Settings(org.odk.collect.shared.settings.Settings) DialogFragment(androidx.fragment.app.DialogFragment) ServerAuthDialogBinding(org.odk.collect.android.databinding.ServerAuthDialogBinding) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Settings(org.odk.collect.shared.settings.Settings) NonNull(androidx.annotation.NonNull)

Aggregations

Settings (org.odk.collect.shared.settings.Settings)19 Test (org.junit.Test)8 Context (android.content.Context)3 Nullable (androidx.annotation.Nullable)3 R (org.odk.collect.android.R)3 Bundle (android.os.Bundle)2 View (android.view.View)2 NonNull (androidx.annotation.NonNull)2 Style (com.mapbox.mapboxsdk.maps.Style)2 Inject (javax.inject.Inject)2 DaggerUtils (org.odk.collect.android.injection.DaggerUtils)2 SettingsProvider (org.odk.collect.settings.SettingsProvider)2 Dialog (android.app.Dialog)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 DialogFragment (androidx.fragment.app.DialogFragment)1 Fragment (androidx.fragment.app.Fragment)1 CheckBoxPreference (androidx.preference.CheckBoxPreference)1 ListPreference (androidx.preference.ListPreference)1