Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Mar 31, 2023
2 parents 67b5139 + 15b2688 commit af19f11
Show file tree
Hide file tree
Showing 91 changed files with 938 additions and 202 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/dependencies/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Dependencies {
const val androidx_multidex = "androidx.multidex:multidex:2.0.1"
const val androidx_preference_ktx = "androidx.preference:preference-ktx:1.2.0"
const val androidx_fragment_ktx = "androidx.fragment:fragment-ktx:${Versions.androidx_fragment}"
const val android_material = "com.google.android.material:material:1.8.0"
const val android_material = "com.google.android.material:material:1.7.0"
const val android_flexbox = "com.google.android.flexbox:flexbox:3.0.0"
const val google_api_client_android = "com.google.api-client:google-api-client-android:2.2.0"
const val google_api_services_drive = "com.google.apis:google-api-services-drive:v3-rev20230212-2.0.0"
Expand All @@ -43,7 +43,7 @@ object Dependencies {
const val rarepebble_colorpicker = "com.github.martin-stone:hsv-alpha-color-picker-android:3.0.1"
const val commons_io = "commons-io:commons-io:2.5" // Commons 2.6+ introduce java.nio usage that we can't access until our minSdkVersion >= 26 (https://developer.android.com/reference/java/io/File#toPath())
const val opencsv = "com.opencsv:opencsv:5.7.1"
const val javarosa = "org.getodk:javarosa:4.0.1-SNAPSHOT"
const val javarosa = "org.getodk:javarosa:4.1.0"
const val javarosa_local = "org.getodk:javarosa:local"
const val karumi_dexter = "com.karumi:dexter:6.2.3"
const val zxing_android_embedded = "com.journeyapps:zxing-android-embedded:4.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void saveIgnoreDialog_ShouldUseBothOptions() {
.clickOnId(R.id.simple_button)
.waitForRotationToEnd()
.pressBack(new SaveOrIgnoreDialog<>("Sketch Image", new FormEntryPage("All widgets")))
.clickDiscardForm()
.clickDiscardChanges()
.waitForRotationToEnd()
.clickOnId(R.id.simple_button)
.waitForRotationToEnd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void saveIgnoreDialog_ShouldUseBothOptions() {
.pressBack(new SaveOrIgnoreDialog<>("Gather Signature", new FormEntryPage("All widgets")))
.checkIsTranslationDisplayed("Exit Gather Signature", "Salir Adjuntar firma")
.assertText(R.string.keep_changes)
.clickDiscardForm()
.clickDiscardChanges()
.waitForRotationToEnd()
.clickWidgetButton()
.waitForRotationToEnd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ private void manageGoogleDriveDeprecationBanner() {
unprotectedSettings.save(ProjectKeys.GOOGLE_DRIVE_DEPRECATION_BANNER_DISMISSED, true);
});
}
} else {
findViewById(R.id.google_drive_deprecation_banner).setVisibility(View.GONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ object AnalyticsEvents {

const val INSTANCE_PROVIDER_DELETE = "InstanceProviderDelete"

/**
* Tracks how many forms include an accuracy threshold for the default `geopoint` question
*/
const val ACCURACY_THRESHOLD = "AccuracyThreshold"

/**
* Tracks how many forms use default accuracy thresholds for the default `geopoint` question
*/
const val ACCURACY_THRESHOLD_DEFAULT = "AccuracyThresholdDefault"

/**
* Tracks how often "cellular_only" option is used in auto send
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package org.odk.collect.android.application

import org.odk.collect.android.analytics.AnalyticsUtils
import org.odk.collect.android.backgroundwork.FormUpdateScheduler
import org.odk.collect.android.formmanagement.matchexactly.SyncStatusAppState
import org.odk.collect.android.logic.PropertyManager
import org.odk.collect.settings.importing.SettingsChangeHandler
import org.odk.collect.settings.keys.ProjectKeys

class CollectSettingsChangeHandler(
private val propertyManager: PropertyManager,
private val formUpdateScheduler: FormUpdateScheduler
private val formUpdateScheduler: FormUpdateScheduler,
private val syncStatusAppState: SyncStatusAppState
) : SettingsChangeHandler {

override fun onSettingChanged(projectId: String, newValue: Any?, changedKey: String) {
propertyManager.reload()

if (changedKey == ProjectKeys.KEY_SERVER_URL || changedKey == ProjectKeys.KEY_PROTOCOL) {
syncStatusAppState.clear(projectId)
}

if (changedKey == ProjectKeys.KEY_FORM_UPDATE_MODE ||
changedKey == ProjectKeys.KEY_PERIODIC_FORM_UPDATES_CHECK ||
changedKey == ProjectKeys.KEY_PROTOCOL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.CursorWindow;
import android.database.sqlite.SQLiteBlobTooBigException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;

Expand All @@ -16,6 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand All @@ -39,6 +42,8 @@
import static org.odk.collect.android.database.forms.DatabaseFormColumns.MD5_HASH;
import static org.odk.collect.shared.PathUtils.getRelativeFilePath;

import timber.log.Timber;

public class DatabaseFormsRepository implements FormsRepository {

private final DatabaseConnection databaseConnection;
Expand Down Expand Up @@ -246,17 +251,31 @@ private void deleteForms(String selection, String[] selectionArgs) {
private static List<Form> getFormsFromCursor(Cursor cursor, String formsPath, String cachePath) {
List<Form> forms = new ArrayList<>();
if (cursor != null) {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
Form form = getFormFromCurrentCursorPosition(cursor, formsPath, cachePath);

forms.add(form);
try {
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
Form form = getFormFromCurrentCursorPosition(cursor, formsPath, cachePath);
forms.add(form);
}
} catch (SQLiteBlobTooBigException e) {
logSQLiteBlobTooBigException();
throw e;
}

}
return forms;
}

private static void logSQLiteBlobTooBigException() {
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
Object size = field.get(null);
Timber.w("SQLiteBlobTooBigException, sCursorWindowSize: %sB", size);
} catch (Throwable t) {
// ignore;
}
}

private void deleteFilesForForm(Form form) {
// Delete form file
if (form.getFormFilePath() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void createQuitDrawDialog() {

List<IconMenuItem> items;
items = ImmutableList.of(new IconMenuItem(R.drawable.ic_save, R.string.keep_changes),
new IconMenuItem(R.drawable.ic_delete, R.string.do_not_save));
new IconMenuItem(R.drawable.ic_delete, R.string.discard_changes));

final IconMenuListAdapter adapter = new IconMenuListAdapter(this, items);
listView.setAdapter(adapter);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.odk.collect.android.formentry;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -35,6 +38,11 @@ private void init(Context context, boolean instanceComplete) {
((TextView) findViewById(R.id.description)).setText(context.getString(R.string.save_enter_data_description, formTitle));

EditText saveAs = findViewById(R.id.save_name);
saveAs.setOnFocusChangeListener((view, isFocused) -> {
if (isFocused) {
findViewById(R.id.manual_name_warning).setVisibility(View.VISIBLE);
}
});

// disallow carriage returns in the name
InputFilter returnFilter = (source, start, end, dest, dstart, dend) -> FormNameUtils.normalizeFormName(source.toString().substring(start, end), true);
Expand Down Expand Up @@ -62,6 +70,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
findViewById(R.id.save_exit_button).setOnClickListener(v -> {
listener.onSaveClicked(markAsFinalized.isChecked());
});

findViewById(R.id.instance_name_learn_more).setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("https://forum.getodk.org/t/collect-manual-instance-naming-will-be-removed-in-v2023-2/40313"));
context.startActivity(intent);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import org.odk.collect.android.external.FormsContract
import org.odk.collect.androidshared.data.AppState
import org.odk.collect.forms.FormSourceException
import javax.inject.Singleton

@Singleton
class SyncStatusAppState(private val context: Context) {

private val syncing = mutableMapOf<String, MutableLiveData<Boolean>>()
private val lastSyncFailure = mutableMapOf<String, MutableLiveData<FormSourceException?>>()
class SyncStatusAppState(private val appState: AppState, private val context: Context) {

fun isSyncing(projectId: String): LiveData<Boolean> {
return getSyncingLiveData(projectId)
Expand All @@ -32,8 +28,18 @@ class SyncStatusAppState(private val context: Context) {
}

private fun getSyncingLiveData(projectId: String) =
syncing.getOrPut(projectId) { MutableLiveData(false) }
appState.get("$KEY_PREFIX_SYNCING:$projectId", MutableLiveData(false))

private fun getSyncErrorLiveData(projectId: String) =
lastSyncFailure.getOrPut(projectId) { MutableLiveData(null) }
appState.get("$KEY_PREFIX_ERROR:$projectId", MutableLiveData<FormSourceException>(null))

fun clear(projectId: String) {
getSyncingLiveData(projectId).value = false
getSyncErrorLiveData(projectId).value = null
}

companion object {
const val KEY_PREFIX_SYNCING = "syncStatusSyncing"
const val KEY_PREFIX_ERROR = "syncStatusError"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ private static class PolygonFeature implements MapFeature {
.addAll(markers.stream().map(Marker::getPosition).collect(Collectors.toList()))
.strokeColor(strokeLineColor)
.strokeWidth(5)
.fillColor(ColorUtils.setAlphaComponent(strokeLineColor, 150))
.fillColor(ColorUtils.setAlphaComponent(strokeLineColor, 68))
.clickable(true)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.odk.collect.android.injection.config;

import static androidx.core.content.FileProvider.getUriForFile;
import static org.odk.collect.androidshared.data.AppStateKt.getState;
import static org.odk.collect.settings.keys.MetaKeys.KEY_INSTALL_ID;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -97,7 +98,6 @@
import org.odk.collect.android.utilities.FileProvider;
import org.odk.collect.android.utilities.FormsDirDiskFormsSynchronizer;
import org.odk.collect.android.utilities.FormsRepositoryProvider;
import org.odk.collect.androidshared.bitmap.ImageCompressor;
import org.odk.collect.android.utilities.ImageCompressionController;
import org.odk.collect.android.utilities.InstancesRepositoryProvider;
import org.odk.collect.android.utilities.MediaUtils;
Expand All @@ -107,6 +107,7 @@
import org.odk.collect.android.utilities.WebCredentialsUtils;
import org.odk.collect.android.version.VersionInformation;
import org.odk.collect.android.views.BarcodeViewDecoder;
import org.odk.collect.androidshared.bitmap.ImageCompressor;
import org.odk.collect.androidshared.network.ConnectivityProvider;
import org.odk.collect.androidshared.network.NetworkStateProvider;
import org.odk.collect.androidshared.system.IntentLauncher;
Expand Down Expand Up @@ -180,11 +181,7 @@ UserAgentProvider providesUserAgent() {
@Provides
@Singleton
public OpenRosaHttpInterface provideHttpInterface(MimeTypeMap mimeTypeMap, UserAgentProvider userAgentProvider, Application application, VersionInformation versionInformation) {
String cacheDir = null;
if (!versionInformation.isRelease() || BuildConfig.DEBUG) {
cacheDir = application.getCacheDir().getAbsolutePath();
}

String cacheDir = application.getCacheDir().getAbsolutePath();
return new OkHttpConnection(
new OkHttpOpenRosaServerClientProvider(new OkHttpClient(), cacheDir),
new CollectThenSystemContentTypeMapper(mimeTypeMap),
Expand Down Expand Up @@ -313,8 +310,8 @@ public PropertyManager providesPropertyManager(PermissionsProvider permissionsPr
}

@Provides
public SettingsChangeHandler providesSettingsChangeHandler(PropertyManager propertyManager, FormUpdateScheduler formUpdateScheduler) {
return new CollectSettingsChangeHandler(propertyManager, formUpdateScheduler);
public SettingsChangeHandler providesSettingsChangeHandler(PropertyManager propertyManager, FormUpdateScheduler formUpdateScheduler, SyncStatusAppState syncStatusAppState) {
return new CollectSettingsChangeHandler(propertyManager, formUpdateScheduler, syncStatusAppState);
}

@Provides
Expand Down Expand Up @@ -353,9 +350,8 @@ public QRCodeDecoder providesQRCodeDecoder() {
}

@Provides
@Singleton
public SyncStatusAppState providesServerFormSyncRepository(Context context) {
return new SyncStatusAppState(context);
public SyncStatusAppState providesServerFormSyncRepository(Application application) {
return new SyncStatusAppState(getState(application), application);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import org.kxml2.kdom.Element
import org.odk.collect.forms.FormListItem
import org.odk.collect.forms.MediaFile
import org.odk.collect.shared.strings.StringUtils.isBlank
import java.util.ArrayList

class OpenRosaResponseParserImpl : OpenRosaResponseParser {

override fun parseFormList(document: Document): List<FormListItem>? {
// Attempt OpenRosa 1.0 parsing
val xformsElement = document.rootElement
val xformsElement = try {
document.rootElement
} catch (e: RuntimeException) {
return null
}

if (xformsElement.name != "xforms") {
return null
}
Expand Down Expand Up @@ -122,7 +126,12 @@ class OpenRosaResponseParserImpl : OpenRosaResponseParser {

override fun parseManifest(document: Document): List<MediaFile>? {
// Attempt OpenRosa 1.0 parsing
val manifestElement = document.rootElement
val manifestElement = try {
document.rootElement
} catch (e: RuntimeException) {
return null
}

if (manifestElement.name != "manifest") {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ public void clickImage(String context) {
private void launchDrawActivity() {
Intent i = new Intent(getContext(), DrawActivity.class);
i.putExtra(DrawActivity.OPTION, drawOption);
if (binaryName != null) {
i.putExtra(DrawActivity.REF_IMAGE, Uri.fromFile(getFile()));
File file = getFile();
if (file != null) {
i.putExtra(DrawActivity.REF_IMAGE, Uri.fromFile(file));
}

i.putExtra(DrawActivity.EXTRA_OUTPUT, Uri.fromFile(new File(tmpImageFilePath)));
Expand Down Expand Up @@ -279,9 +280,18 @@ protected void launchActivityForResult(Intent intent, final int resourceCode, fi

@Nullable
private File getFile() {
if (binaryName == null) {
return null;
}

File file = questionMediaManager.getAnswerFile(binaryName);
if ((file == null || !file.exists()) && doesSupportDefaultValues()) {
file = new File(getDefaultFilePath());
String filePath = getDefaultFilePath();
if (filePath != null) {
return new File(getDefaultFilePath());
} else {
return null;
}
}

return file;
Expand All @@ -294,7 +304,7 @@ private String getDefaultFilePath() {
Timber.w(e);
}

return "";
return null;
}

protected abstract boolean doesSupportDefaultValues();
Expand Down
Loading

0 comments on commit af19f11

Please sign in to comment.