Skip to content

Commit

Permalink
Implemented main functionality to view sent form
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Feb 16, 2017
1 parent 07fb2ea commit 029afa3
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 36 deletions.
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 @@ -909,6 +910,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 @@ -2544,9 +2546,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,32 @@ 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, InstanceProviderAPI.STATUS_SUBMITTED_AND_DELETED};
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 + " != ? and " + InstanceColumns.STATUS + " != ?";
} else {
setTitle(getString(R.string.view_sent_forms));
selection = InstanceColumns.STATUS + " = ? or " + 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);
ViewSentListAdapter instances =
new ViewSentListAdapter(this, R.layout.two_item, c, data, view);
setListAdapter(instances);
}

Expand All @@ -102,29 +109,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
@@ -0,0 +1,84 @@
/*
* Copyright 2017 Nafundi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.odk.collect.android.adapters;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import org.odk.collect.android.R;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI;

public class ViewSentListAdapter extends SimpleCursorAdapter {
private Context mContext;

public ViewSentListAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
mContext = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
String status = getCursor().getString(getCursor().getColumnIndex(InstanceProviderAPI.InstanceColumns.STATUS));

String selection = FormsProviderAPI.FormsColumns.JR_FORM_ID + " =? ";
String[] selectionArgs = {getCursor().getString(getCursor().getColumnIndex(InstanceProviderAPI.InstanceColumns.JR_FORM_ID))};

//getting blank form record
Cursor cursor = mContext.getContentResolver().query(FormsProviderAPI.FormsColumns.CONTENT_URI, null,
selection, selectionArgs, null);

boolean formExists = false;
boolean isFormEncrypted = false;
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
int base64RSAPublicKeyColumnIndex = cursor.getColumnIndex(FormsProviderAPI.FormsColumns.BASE64_RSA_PUBLIC_KEY);
String base64RSAPublicKey = cursor.getString(base64RSAPublicKeyColumnIndex);
isFormEncrypted = base64RSAPublicKey != null && !base64RSAPublicKey.isEmpty();
formExists = true;
}
} finally {
cursor.close();
}
}

TextView visibilityOffCause = (TextView) view.findViewById(R.id.text4);
ImageView visibleOff = (ImageView) view.findViewById(R.id.visible_off);
if (status.equals(InstanceProviderAPI.STATUS_SUBMITTED_AND_DELETED) || !formExists || isFormEncrypted) {
visibilityOffCause.setVisibility(View.VISIBLE);
visibleOff.setVisibility(View.VISIBLE);

if (!status.equals(InstanceProviderAPI.STATUS_SUBMITTED_AND_DELETED)) {
if (!formExists) {
visibilityOffCause.setText(mContext.getString(R.string.deleted_form));
} else if (isFormEncrypted) {
visibilityOffCause.setText(mContext.getString(R.string.encrypted_form));
}
}
} else {
visibilityOffCause.setVisibility(View.GONE);
visibleOff.setVisibility(View.GONE);
}
return view;
}
}
9 changes: 9 additions & 0 deletions collect_app/src/main/res/layout/hierarchy_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ the License.
android:padding="12dp"
android:textSize="16sp"
android:layout_weight="1" />
<Button
android:id="@+id/exitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/exit"
android:visibility="gone"
android:padding="12dp"
android:textSize="16sp"
android:layout_weight="1" />
</LinearLayout>
<ListView
android:id="@android:id/list"
Expand Down
17 changes: 17 additions & 0 deletions collect_app/src/main/res/layout/two_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@
android:layout_below="@+id/text3"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/text4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text2"
android:gravity="center_vertical"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/visible_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/visibility_off"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:visibility="gone"/>
</RelativeLayout>
3 changes: 3 additions & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,7 @@
<string name="reset_layers_result">Offline map layers :: %s</string>
<string name="reset_cache_result">Form load cache :: %s</string>
<string name="reset_osm_tiles_result">OSM tiles :: %s</string>
<string name="encrypted_form">Encrypted form</string>
<string name="deleted_form">Deleted form</string>
<string name="exit">Exit</string>
</resources>

0 comments on commit 029afa3

Please sign in to comment.