From fbe042ef6bff17876cb122e2570bed98c0808e95 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 25 Oct 2023 14:19:36 +0200 Subject: [PATCH 1/4] Fixed onItemClick in InstanceChooserList --- .../org/odk/collect/android/activities/InstanceChooserList.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java index cec7850fa1a..a1729161052 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java @@ -213,6 +213,8 @@ public void onItemClick(AdapterView parent, View view, int position, long id) c.getString(c.getColumnIndex(DatabaseInstanceColumns.CAN_EDIT_WHEN_COMPLETE)); boolean canEdit = status.equals(Instance.STATUS_INCOMPLETE) + || status.equals(Instance.STATUS_INVALID) + || status.equals(Instance.STATUS_VALID) || Boolean.parseBoolean(strCanEditWhenComplete); if (!canEdit) { createErrorDialog(getString(org.odk.collect.strings.R.string.cannot_edit_completed_form), From 9c7c39d070ef8efdd3c1e40110ada4d73c52ae50 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 25 Oct 2023 14:30:28 +0200 Subject: [PATCH 2/4] Fixed logging EDIT_NON_FINALIZED_FORM events --- .../org/odk/collect/android/activities/InstanceChooserList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java index a1729161052..2f5e9726518 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java @@ -252,7 +252,7 @@ private void logFormEdit(Cursor cursor) { Form form = formsRepositoryProvider.get().getLatestByFormIdAndVersion(formId, version); String formTitle = form != null ? form.getDisplayName() : ""; - if (status.equals(Instance.STATUS_INCOMPLETE)) { + if (status.equals(Instance.STATUS_INCOMPLETE) || status.equals(Instance.STATUS_INVALID) || status.equals(Instance.STATUS_VALID)) { AnalyticsUtils.logFormEvent(AnalyticsEvents.EDIT_NON_FINALIZED_FORM, formId, formTitle); } } From e8f947f2c26fec917164757a0309c63a07e6c4ea Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 25 Oct 2023 14:44:28 +0200 Subject: [PATCH 3/4] Use when instead of if --- .../InstanceListItemView.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/instancemanagement/InstanceListItemView.kt b/collect_app/src/main/java/org/odk/collect/android/instancemanagement/InstanceListItemView.kt index 2557fca0281..78f63106b73 100644 --- a/collect_app/src/main/java/org/odk/collect/android/instancemanagement/InstanceListItemView.kt +++ b/collect_app/src/main/java/org/odk/collect/android/instancemanagement/InstanceListItemView.kt @@ -30,22 +30,26 @@ object InstanceListItemView { val pill = view.findViewById(R.id.chip) if (pill != null) { - if (instance.status == Instance.STATUS_INVALID || instance.status == Instance.STATUS_INCOMPLETE) { - pill.visibility = View.VISIBLE - pill.setIcon(R.drawable.baseline_rule_24) - pill.setText(string.draft_errors) - pill.setPillBackgroundColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorErrorContainer)) - pill.setTextColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer)) - pill.setIconTint(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer)) - } else if (instance.status == Instance.STATUS_VALID) { - pill.visibility = View.VISIBLE - pill.setIcon(R.drawable.baseline_check_24) - pill.setText(string.draft_no_errors) - pill.setPillBackgroundColor(getThemeAttributeValue(context, R.attr.colorSurfaceContainerHighest)) - pill.setTextColor(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest)) - pill.setIconTint(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest)) - } else { - pill.visibility = View.GONE + when (instance.status) { + Instance.STATUS_INVALID, Instance.STATUS_INCOMPLETE -> { + pill.visibility = View.VISIBLE + pill.setIcon(R.drawable.baseline_rule_24) + pill.setText(string.draft_errors) + pill.setPillBackgroundColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorErrorContainer)) + pill.setTextColor(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer)) + pill.setIconTint(getThemeAttributeValue(context, com.google.android.material.R.attr.colorOnErrorContainer)) + } + Instance.STATUS_VALID -> { + pill.visibility = View.VISIBLE + pill.setIcon(R.drawable.baseline_check_24) + pill.setText(string.draft_no_errors) + pill.setPillBackgroundColor(getThemeAttributeValue(context, R.attr.colorSurfaceContainerHighest)) + pill.setTextColor(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest)) + pill.setIconTint(getThemeAttributeValue(context, R.attr.colorOnSurfaceContainerHighest)) + } + else -> { + pill.visibility = View.GONE + } } } From d9ca35a0e3612edb23ea8b23e779d82f35f7ac09 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Tue, 31 Oct 2023 10:32:25 +0100 Subject: [PATCH 4/4] Removed redundant code --- .../activities/InstanceChooserList.java | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java index 2f5e9726518..57feed72413 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/InstanceChooserList.java @@ -19,7 +19,6 @@ import static org.odk.collect.android.utilities.ApplicationConstants.SortingOrder.BY_NAME_ASC; import static org.odk.collect.android.utilities.ApplicationConstants.SortingOrder.BY_NAME_DESC; -import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -32,7 +31,6 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; @@ -80,8 +78,6 @@ public class InstanceChooserList extends AppListActivity implements AdapterView. private static final String INSTANCE_LIST_ACTIVITY_SORTING_ORDER = "instanceListActivitySortingOrder"; private static final String VIEW_SENT_FORM_SORTING_ORDER = "ViewSentFormSortingOrder"; - private static final boolean DO_NOT_EXIT = false; - private boolean editMode; @Inject @@ -205,22 +201,6 @@ public void onItemClick(AdapterView parent, View view, int position, long id) setResult(RESULT_OK, new Intent().setData(instanceUri)); finish(); } else { - // the form can be edited if it is incomplete or if, when it was - // marked as complete, it was determined that it could be edited - // later. - String status = c.getString(c.getColumnIndex(DatabaseInstanceColumns.STATUS)); - String strCanEditWhenComplete = - c.getString(c.getColumnIndex(DatabaseInstanceColumns.CAN_EDIT_WHEN_COMPLETE)); - - boolean canEdit = status.equals(Instance.STATUS_INCOMPLETE) - || status.equals(Instance.STATUS_INVALID) - || status.equals(Instance.STATUS_VALID) - || Boolean.parseBoolean(strCanEditWhenComplete); - if (!canEdit) { - createErrorDialog(getString(org.odk.collect.strings.R.string.cannot_edit_completed_form), - DO_NOT_EXIT); - return; - } // caller wants to view/edit a form, so launch FormFillingActivity Intent parentIntent = this.getIntent(); Intent intent = new Intent(this, FormUriActivity.class); @@ -299,26 +279,6 @@ public void onLoaderReset(@NonNull Loader loader) { listAdapter.swapCursor(null); } - private void createErrorDialog(String errorMsg, final boolean shouldExit) { - AlertDialog alertDialog = new MaterialAlertDialogBuilder(this).create(); - alertDialog.setMessage(errorMsg); - DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int i) { - switch (i) { - case DialogInterface.BUTTON_POSITIVE: - if (shouldExit) { - finish(); - } - break; - } - } - }; - alertDialog.setCancelable(false); - alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(org.odk.collect.strings.R.string.ok), errorListener); - alertDialog.show(); - } - protected String getSortingOrder() { String sortingOrder = DatabaseInstanceColumns.DISPLAY_NAME + " COLLATE NOCASE ASC, " + DatabaseInstanceColumns.STATUS + " DESC"; switch (getSelectedSortingOrder()) {