Skip to content

Commit

Permalink
View sent form (getodk#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and lognaturel committed Feb 20, 2017
1 parent af54b9e commit 68dc498
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.listeners.DeleteInstancesListener;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.tasks.DeleteInstancesTask;
import org.odk.collect.android.utilities.ListViewUtils;
Expand Down Expand Up @@ -99,7 +100,8 @@ public void onClick(View v) {
}
});

Cursor c = managedQuery(InstanceColumns.CONTENT_URI, null, null, null,
String selection = InstanceColumns.DELETED_DATE + " IS NULL ";
Cursor c = managedQuery(InstanceColumns.CONTENT_URI, null, selection, null,
InstanceColumns.DISPLAY_NAME + " ASC");

String[] data = new String[]{InstanceColumns.DISPLAY_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.odk.collect.android.tasks.SavePointTask;
import org.odk.collect.android.tasks.SaveResult;
import org.odk.collect.android.tasks.SaveToDiskTask;
import org.odk.collect.android.utilities.ApplicationConstants;
import org.odk.collect.android.utilities.CompatibilityUtils;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.MediaUtils;
Expand Down Expand Up @@ -910,6 +911,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
Intent i = new Intent(this, FormHierarchyActivity.class);
i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
startActivityForResult(i, HIERARCHY_ACTIVITY);
return true;
case MENU_PREFERENCES:
Expand Down Expand Up @@ -2562,9 +2564,18 @@ public void run() {
// we've just loaded a saved form, so start in the hierarchy
// view
Intent i = new Intent(this, FormHierarchyActivity.class);
startActivity(i);
return; // so we don't show the intro screen before jumping to
// the hierarchy
if (reqIntent.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.EDIT_SAVED)) {
i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
startActivity(i);
return; // so we don't show the intro screen before jumping to
// the hierarchy
} else {
if (reqIntent.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.VIEW_SENT)) {
i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.VIEW_SENT);
startActivity(i);
}
finish();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.odk.collect.android.exception.JavaRosaException;
import org.odk.collect.android.logic.FormController;
import org.odk.collect.android.logic.HierarchyElement;
import org.odk.collect.android.utilities.ApplicationConstants;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -111,6 +112,25 @@ public void onClick(View v) {
}
});

if (getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.VIEW_SENT)) {
Collect.getInstance().getFormController().stepToOuterScreenEvent();

Button exitButton = (Button) findViewById(R.id.exitButton);
exitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logInstanceAction(this, "exit",
"click");
setResult(RESULT_OK);
finish();
}
});

exitButton.setVisibility(View.VISIBLE);
jumpBeginningButton.setVisibility(View.GONE);
jumpEndButton.setVisibility(View.GONE);
}

refreshView();

// kinda slow, but works.
Expand Down Expand Up @@ -423,7 +443,9 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
}
}
setResult(RESULT_OK);
finish();
if (getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.EDIT_SAVED)) {
finish();
}
return;
case CHILD:
Collect.getInstance().getActivityLogger().logInstanceAction(this, "onListItemClick",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import android.widget.TextView;

import org.odk.collect.android.R;
import org.odk.collect.android.adapters.ViewSentListAdapter;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.utilities.ApplicationConstants;

/**
* Responsible for displaying all the valid instances in the instance directory.
Expand All @@ -57,27 +59,37 @@ public void onCreate(Bundle savedInstanceState) {
}

setContentView(R.layout.chooser_list_layout);
setTitle(getString(R.string.review_data));
TextView tv = (TextView) findViewById(R.id.status_text);
tv.setVisibility(View.GONE);
String selection;
String[] selectionArgs = new String[]{InstanceProviderAPI.STATUS_SUBMITTED};
String sortOrder = InstanceColumns.STATUS + " DESC, " + InstanceColumns.DISPLAY_NAME + " ASC";

String selection = InstanceColumns.STATUS + " != ?";
String[] selectionArgs = {InstanceProviderAPI.STATUS_SUBMITTED};
String sortOrder =
InstanceColumns.STATUS + " DESC, " + InstanceColumns.DISPLAY_NAME + " ASC";
Cursor c = managedQuery(InstanceColumns.CONTENT_URI, null, selection, selectionArgs,
sortOrder);
if (getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.EDIT_SAVED)) {
setTitle(getString(R.string.review_data));
selection = InstanceColumns.STATUS + " != ? ";
} else {
setTitle(getString(R.string.view_sent_forms));
selection = InstanceColumns.STATUS + " = ? ";
}

Cursor c = managedQuery(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, sortOrder);

String[] data = new String[]{
InstanceColumns.DISPLAY_NAME, InstanceColumns.DISPLAY_SUBTEXT
InstanceColumns.DISPLAY_NAME, InstanceColumns.DISPLAY_SUBTEXT, InstanceColumns.DELETED_DATE
};
int[] view = new int[]{
R.id.text1, R.id.text2
R.id.text1, R.id.text2, R.id.text4
};

// render total instance view
SimpleCursorAdapter instances =
new SimpleCursorAdapter(this, R.layout.two_item, c, data, view);
SimpleCursorAdapter instances;
if (getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.EDIT_SAVED)) {
instances = new SimpleCursorAdapter(this, R.layout.two_item, c, data, view);
} else {
instances = new ViewSentListAdapter(this, R.layout.two_item, c, data, view);
}

setListAdapter(instances);
}

Expand All @@ -102,29 +114,38 @@ protected void onListItemClick(ListView listView, View view, int position, long
Collect.getInstance().getActivityLogger().logAction(this, "onListItemClick",
instanceUri.toString());

String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action)) {
// caller is waiting on a picked form
setResult(RESULT_OK, new Intent().setData(instanceUri));
} 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(InstanceColumns.STATUS));
String strCanEditWhenComplete =
c.getString(c.getColumnIndex(InstanceColumns.CAN_EDIT_WHEN_COMPLETE));

boolean canEdit = status.equals(InstanceProviderAPI.STATUS_INCOMPLETE)
|| Boolean.parseBoolean(strCanEditWhenComplete);
if (!canEdit) {
createErrorDialog(getString(R.string.cannot_edit_completed_form),
DO_NOT_EXIT);
return;
if (view.findViewById(R.id.visible_off).getVisibility() != View.VISIBLE) {
String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action)) {
// caller is waiting on a picked form
setResult(RESULT_OK, new Intent().setData(instanceUri));
} 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(InstanceColumns.STATUS));
String strCanEditWhenComplete =
c.getString(c.getColumnIndex(InstanceColumns.CAN_EDIT_WHEN_COMPLETE));

boolean canEdit = status.equals(InstanceProviderAPI.STATUS_INCOMPLETE)
|| Boolean.parseBoolean(strCanEditWhenComplete);
if (!canEdit) {
createErrorDialog(getString(R.string.cannot_edit_completed_form),
DO_NOT_EXIT);
return;
}
// caller wants to view/edit a form, so launch formentryactivity
Intent parentIntent = this.getIntent();
Intent intent = new Intent(Intent.ACTION_EDIT, instanceUri);
if (parentIntent.getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE).equalsIgnoreCase(ApplicationConstants.FormModes.EDIT_SAVED)) {
intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
} else {
intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.VIEW_SENT);
}
startActivity(intent);
}
// caller wants to view/edit a form, so launch formentryactivity
startActivity(new Intent(Intent.ACTION_EDIT, instanceUri));
finish();
}
finish();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.odk.collect.android.preferences.PreferencesActivity;
import org.odk.collect.android.provider.InstanceProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI.InstanceColumns;
import org.odk.collect.android.utilities.ApplicationConstants;
import org.odk.collect.android.utilities.CompatibilityUtils;

import java.io.File;
Expand Down Expand Up @@ -79,6 +80,7 @@ public class MainMenuActivity extends Activity {
private Button mEnterDataButton;
private Button mManageFilesButton;
private Button mSendDataButton;
private Button mViewSentFormsButton;
private Button mReviewDataButton;
private Button mGetFormsButton;

Expand All @@ -90,9 +92,11 @@ public class MainMenuActivity extends Activity {

private int mCompletedCount;
private int mSavedCount;
private int mViewSentCount;

private Cursor mFinalizedCursor;
private Cursor mSavedCursor;
private Cursor mViewSentCursor;

private IncomingHandler mHandler = new IncomingHandler(this);
private MyContentObserver mContentObserver = new MyContentObserver();
Expand Down Expand Up @@ -168,9 +172,9 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger()
.logAction(this, "editSavedForm", "click");
Intent i = new Intent(getApplicationContext(),
InstanceChooserList.class);
.logAction(this, ApplicationConstants.FormModes.EDIT_SAVED, "click");
Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
startActivity(i);
}
});
Expand All @@ -189,6 +193,18 @@ public void onClick(View v) {
}
});

//View sent forms
mViewSentFormsButton = (Button) findViewById(R.id.view_sent_forms);
mViewSentFormsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Collect.getInstance().getActivityLogger().logAction(this, ApplicationConstants.FormModes.VIEW_SENT, "click");
Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
i.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.VIEW_SENT);
startActivity(i);
}
});

// manage forms button. no result expected.
mGetFormsButton = (Button) findViewById(R.id.get_forms);
mGetFormsButton.setText(getString(R.string.get_forms));
Expand Down Expand Up @@ -266,8 +282,21 @@ public void onClick(View v) {
startManagingCursor(mSavedCursor);
}
mSavedCount = mSavedCursor != null ? mSavedCursor.getCount() : 0;
// don't need to set a content observer because it can't change in the
// background

//count for view sent form
String selectionViewSent = InstanceColumns.STATUS + "=?";
String selectionArgsViewSent[] = {InstanceProviderAPI.STATUS_SUBMITTED};
try {
mViewSentCursor = managedQuery(InstanceColumns.CONTENT_URI, null,
selectionViewSent, selectionArgsViewSent, null);
} catch (Exception e) {
createErrorDialog(e.getMessage(), EXIT);
return;
}
if (mViewSentCursor != null) {
startManagingCursor(mViewSentCursor);
}
mViewSentCount = mViewSentCursor != null ? mViewSentCursor.getCount() : 0;

updateButtons();
setupGoogleAnalytics();
Expand Down Expand Up @@ -297,6 +326,14 @@ protected void onResume() {
mSendDataButton.setVisibility(View.VISIBLE);
}

boolean view_sent = sharedPreferences.getBoolean(
AdminPreferencesActivity.KEY_VIEW_SENT, true);
if (!view_sent) {
mViewSentFormsButton.setVisibility(View.GONE);
} else {
mViewSentFormsButton.setVisibility(View.VISIBLE);
}

boolean get_blank = sharedPreferences.getBoolean(
AdminPreferencesActivity.KEY_GET_BLANK, true);
if (!get_blank) {
Expand Down Expand Up @@ -516,6 +553,20 @@ private void updateButtons() {
Log.w(t,
"Cannot update \"Edit Form\" button label since the database is closed. Perhaps the app is running in the background?");
}

if (mViewSentCursor != null && !mViewSentCursor.isClosed()) {
mViewSentCursor.requery();
mViewSentCount = mViewSentCursor.getCount();
if (mViewSentCount > 0) {
mViewSentFormsButton.setText(getString(R.string.view_sent_forms_button, String.valueOf(mViewSentCount)));
} else {
mViewSentFormsButton.setText(getString(R.string.view_sent_forms));
}
} else {
mViewSentFormsButton.setText(getString(R.string.view_sent_forms));
Log.w(t,
"Cannot update \"View Sent\" button label since the database is closed. Perhaps the app is running in the background?");
}
}

/**
Expand Down
Loading

0 comments on commit 68dc498

Please sign in to comment.