Search in sources :

Example 11 with Settings

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));
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) FormUpdateMode(org.odk.collect.android.preferences.utilities.FormUpdateMode) Settings(org.odk.collect.shared.settings.Settings) Test(org.junit.Test)

Example 12 with Settings

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

Example 13 with Settings

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

Example 14 with Settings

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);
    }
}
Also used : Context(android.content.Context) NonNull(androidx.annotation.NonNull) Singleton(javax.inject.Singleton) PrefUtils(org.odk.collect.android.preferences.PrefUtils) KEY_BASEMAP_SOURCE(org.odk.collect.settings.keys.ProjectKeys.KEY_BASEMAP_SOURCE) MapFragmentFactory(org.odk.collect.geo.maps.MapFragmentFactory) Map(java.util.Map) R(org.odk.collect.android.R) KEY_USGS_MAP_STYLE(org.odk.collect.settings.keys.ProjectKeys.KEY_USGS_MAP_STYLE) WeakHashMap(java.util.WeakHashMap) KEY_MAPBOX_MAP_STYLE(org.odk.collect.settings.keys.ProjectKeys.KEY_MAPBOX_MAP_STYLE) MapFragment(org.odk.collect.geo.maps.MapFragment) BASEMAP_SOURCE_STAMEN(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_STAMEN) WmsOption(org.odk.collect.android.geo.OsmDroidMapConfigurator.WmsOption) BASEMAP_SOURCE_GOOGLE(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_GOOGLE) GoogleMapTypeOption(org.odk.collect.android.geo.GoogleMapConfigurator.GoogleMapTypeOption) MapboxUrlOption(org.odk.collect.android.geo.MapboxMapConfigurator.MapboxUrlOption) BASEMAP_SOURCE_OSM(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_OSM) KEY_GOOGLE_MAP_STYLE(org.odk.collect.settings.keys.ProjectKeys.KEY_GOOGLE_MAP_STYLE) Style(com.mapbox.mapboxsdk.maps.Style) BASEMAP_SOURCE_USGS(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_USGS) KEY_CARTO_MAP_STYLE(org.odk.collect.settings.keys.ProjectKeys.KEY_CARTO_MAP_STYLE) GoogleMap(com.google.android.gms.maps.GoogleMap) Settings(org.odk.collect.shared.settings.Settings) BASEMAP_SOURCE_MAPBOX(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_MAPBOX) BASEMAP_SOURCE_CARTO(org.odk.collect.settings.keys.ProjectKeys.BASEMAP_SOURCE_CARTO) Settings(org.odk.collect.shared.settings.Settings)

Example 15 with Settings

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

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