Skip to content

Commit

Permalink
Merge pull request #5801 from grzesiek2010/improvements_for_v2023.3
Browse files Browse the repository at this point in the history
Improvements around new statuses used by drafts in v2023.3
  • Loading branch information
seadowg authored Oct 31, 2023
2 parents da182e4 + d9ca35a commit 47e4329
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -205,20 +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)
|| 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);
Expand Down Expand Up @@ -250,7 +232,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);
}
}
Expand Down Expand Up @@ -297,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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ object InstanceListItemView {

val pill = view.findViewById<MaterialPill>(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
}
}
}

Expand Down

0 comments on commit 47e4329

Please sign in to comment.