Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #82 from lakshyagupta21/SHARE_81
Browse files Browse the repository at this point in the history
Added UUID to forms so that forms can be identified uniquely
  • Loading branch information
lognaturel authored Aug 13, 2018
2 parents c8491ab + 41b69d3 commit 7d0b99d
Show file tree
Hide file tree
Showing 20 changed files with 640 additions and 74 deletions.
5 changes: 4 additions & 1 deletion share_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@
android:stateNotNeeded="true"
tools:replace="android:screenOrientation" />
<activity android:name=".activities.InstanceManagerTabs" />
<activity android:name=".activities.ReviewFormActivity" />

<provider
android:name=".provider.TransferProvider"
android:authorities="org.odk.share.provider.odk.instances" />

<activity android:name=".activities.ReviewFormActivity" />
<provider
android:name=".provider.InstanceMapProvider"
android:authorities="org.odk.share.provider.odk.map" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.odk.share.adapters.InstanceAdapter;
import org.odk.share.dao.InstancesDao;
import org.odk.share.provider.InstanceProviderAPI;
import org.odk.share.utilities.ApplicationConstants;
import org.odk.share.utilities.ArrayUtils;

import java.util.LinkedHashSet;
Expand All @@ -25,6 +26,8 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

import static org.odk.share.fragments.ReviewedInstancesFragment.MODE;

public class InstancesList extends InstanceListActivity implements LoaderManager.LoaderCallbacks<Cursor> {

@BindView(R.id.recyclerview) RecyclerView recyclerView;
Expand Down Expand Up @@ -112,6 +115,7 @@ public void send() {
Long[] arr = selectedInstances.toArray(new Long[selectedInstances.size()]);
long[] a = ArrayUtils.toPrimitive(arr);
intent.putExtra(INSTANCE_IDS, a);
intent.putExtra(MODE, ApplicationConstants.ASK_REVIEW_MODE);
startActivity(intent);
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public void acceptForm() {

@OnClick(R.id.bReject)
public void rejectForm() {
String feedback = description.getText().toString();
String feedbackText = feedback.getText().toString();
if (feedback != null) {
ContentValues values = new ContentValues();
values.put(TransferInstance.INSTRUCTIONS, feedback);
values.put(TransferInstance.INSTRUCTIONS, feedbackText);
values.put(TransferInstance.REVIEW_STATUS, TransferInstance.STATUS_REJECTED);
Long now = System.currentTimeMillis();
values.put(LAST_STATUS_CHANGE_DATE, now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

import static android.view.View.VISIBLE;
import static org.odk.share.activities.InstancesList.INSTANCE_IDS;
import static org.odk.share.fragments.ReviewedInstancesFragment.MODE;
import static org.odk.share.utilities.ApplicationConstants.ASK_REVIEW_MODE;

/**
* Created by laksh on 6/9/2018.
Expand Down Expand Up @@ -75,6 +77,7 @@ public class SendActivity extends InjectableActivity {
private String alertMsg;
private int port;
private long[] instancesIds;
private int mode;

private WifiManager.LocalOnlyHotspotReservation hotspotReservation;
private WifiConfiguration currentConfig;
Expand All @@ -89,6 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);

instancesIds = getIntent().getLongArrayExtra(INSTANCE_IDS);
mode = getIntent().getIntExtra(MODE, ASK_REVIEW_MODE);

port = SocketUtils.getPort();

Expand Down Expand Up @@ -273,7 +277,7 @@ private Disposable addUploadEventSubscription() {
case FINISHED:
hideDialog(PROGRESS_DIALOG);
String result = uploadEvent.getResult();
createAlertDialog(getString(R.string.transfer_result), getString(R.string.send_success, result));
createAlertDialog(getString(R.string.transfer_result), result);
break;
case ERROR:
hideDialog(PROGRESS_DIALOG);
Expand Down Expand Up @@ -325,7 +329,7 @@ protected void onPause() {
}

private void startSending() {
senderService.startUploading(instancesIds, port);
senderService.startUploading(instancesIds, port, mode);
}

@RequiresApi(api = Build.VERSION_CODES.O)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private Disposable addDownloadEventSubscription() {
case FINISHED:
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
String result = downloadEvent.getResult();
createAlertDialog(getString(R.string.transfer_result), getString(R.string.receive_success, result));
createAlertDialog(getString(R.string.transfer_result), result);
break;
case ERROR:
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ public void onBindViewHolder(ViewHolder holder, int position) {
String statusChangeTime = dateFormat.format(date);

if (instance.getTransferStatus().equalsIgnoreCase(context.getString(R.string.sent))) {
holder.subtitle.setText(context.getString(R.string.sent_on, statusChangeTime));
if (instance.getReceivedReviewStatus() == TransferInstance.STATUS_ACCEPTED ||
instance.getReceivedReviewStatus() == TransferInstance.STATUS_REJECTED) {
StringBuilder sb = new StringBuilder();
sb.append(context.getString(R.string.form_received_by_reviewer,
instance.getReceivedReviewStatus() == TransferInstance.STATUS_ACCEPTED ?
context.getString(R.string.accepted) : context.getString(R.string.rejected)));
if (instance.getInstructions() != null && instance.getInstructions().length() > 0) {
sb.append(context.getString(R.string.feedback_sent, instance.getInstructions()));
} else {
sb.append(context.getString(R.string.no_feedback_sent));
}
holder.subtitle.setText(sb.toString());
} else {
holder.subtitle.setText(context.getString(R.string.sent_on, statusChangeTime));
}
} else if (instance.getReviewed() == TransferInstance.STATUS_ACCEPTED) {
holder.subtitle.setText(context.getString(R.string.approved_on, statusChangeTime));
} else if (instance.getReviewed() == TransferInstance.STATUS_REJECTED) {
Expand Down
5 changes: 3 additions & 2 deletions share_app/src/main/java/org/odk/share/application/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public static Share getInstance() {
}

public static final String ODK_ROOT = Environment.getExternalStorageDirectory() + File.separator + "share";
public static final String FORMS_PATH = ODK_ROOT + File.separator + "forms";
public static final String INSTANCES_PATH = ODK_ROOT + File.separator + "instances";
public static final String ODK_COLLECT_ROOT = Environment.getExternalStorageDirectory() + File.separator + "odk";
public static final String FORMS_PATH = ODK_COLLECT_ROOT + File.separator + "forms";
public static final String INSTANCES_PATH = ODK_COLLECT_ROOT + File.separator + "instances";
public static final String METADATA_PATH = ODK_ROOT + File.separator + "metadata";

@Override
Expand Down
87 changes: 87 additions & 0 deletions share_app/src/main/java/org/odk/share/dao/InstanceMapDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.odk.share.dao;

import android.content.ContentValues;
import android.database.Cursor;

import org.odk.share.application.Share;

import java.util.HashMap;

import timber.log.Timber;

import static org.odk.share.dto.InstanceMap.INSTANCE_ID;
import static org.odk.share.dto.InstanceMap.INSTANCE_UUID;
import static org.odk.share.provider.InstanceMapProvider.CONTENT_URI;


/**
* Created by laksh on 8/2/2018.
*/

public class InstanceMapDao {

public int updateInstance(ContentValues values, String where, String[] whereArgs) {
return Share.getInstance().getContentResolver().update(CONTENT_URI, values, where, whereArgs);
}

public HashMap<Long, String> getInstanceMap() {
Cursor cursor = getInstancesCursor(null, null, null, null);

HashMap<Long, String> instanceMap = new HashMap<>();
if (cursor != null) {
Timber.d("CUrsor " + cursor.getCount());
try {
while (cursor.moveToNext()) {
long instanceId = cursor.getLong(cursor.getColumnIndex(INSTANCE_ID));
String uuid = cursor.getString(cursor.getColumnIndex(INSTANCE_UUID));
instanceMap.put(instanceId, uuid);
}
} finally {
cursor.close();
}
}
return instanceMap;
}

public HashMap<String, Long> getInstanceUUIDMap() {
Cursor cursor = getInstancesCursor(null, null, null, null);

HashMap<String, Long> instanceMap = new HashMap<>();
if (cursor != null) {
try {
while (cursor.moveToNext()) {
long instanceId = cursor.getLong(cursor.getColumnIndex(INSTANCE_ID));
String uuid = cursor.getString(cursor.getColumnIndex(INSTANCE_UUID));
instanceMap.put(uuid, instanceId);
}
} finally {
cursor.close();
}
}
return instanceMap;
}

public Cursor getInstancesCursor(String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return Share.getInstance().getContentResolver()
.query(CONTENT_URI, projection, selection, selectionArgs, sortOrder);
}

public long getInstanceId(String uuid) {
String selection = INSTANCE_UUID + "=?";
String[] selectionArgs = {uuid};

Cursor cursor = getInstancesCursor(null, selection, selectionArgs, null);
long id = -1;

if (cursor != null) {
try {
if (cursor.moveToNext()) {
id = cursor.getLong(cursor.getColumnIndex(INSTANCE_ID));
}
} finally {
cursor.close();
}
}
return id;
}
}
29 changes: 29 additions & 0 deletions share_app/src/main/java/org/odk/share/dao/TransferDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public Cursor getUnreviewedInstancesCursor() {
return getInstancesCursor(null, selection, selectionArgs, null);
}

public Cursor getSentInstanceInstanceCursorUsingId(long id) {
String selection = TransferInstance.TRANSFER_STATUS + " =? AND " + TransferInstance.INSTANCE_ID + " =?";
String[] selectionArgs = {TransferInstance.STATUS_FORM_SENT, String.valueOf(id)};
return getInstancesCursor(null, selection, selectionArgs, null);
}

public CursorLoader getSentInstancesCursorLoader() {
String selection = TransferInstance.TRANSFER_STATUS + " =? ";
String[] selectionArgs = {TransferInstance.STATUS_FORM_SENT};
Expand Down Expand Up @@ -84,6 +90,27 @@ public int updateInstance(ContentValues values, String where, String[] whereArgs
return Share.getInstance().getContentResolver().update(CONTENT_URI, values, where, whereArgs);
}

public TransferInstance getReceivedTransferInstanceFromInstanceId(long instanceId) {
String selection = TransferInstance.INSTANCE_ID + " =? AND " + TransferInstance.TRANSFER_STATUS + " =?";
String[] selectionArgs = {String.valueOf(instanceId), TransferInstance.STATUS_FORM_RECEIVE};
Cursor cursor = getInstancesCursor(null, selection, selectionArgs, null);
List<TransferInstance> transferInstanceList = getInstancesFromCursor(cursor);
if (transferInstanceList.size() > 0) {
return transferInstanceList.get(0);
}
return null;
}

public TransferInstance getSentTransferInstanceFromInstanceId(long instanceId) {
String selection = TransferInstance.INSTANCE_ID + " =? AND " + TransferInstance.TRANSFER_STATUS + " =?";
String[] selectionArgs = {String.valueOf(instanceId), TransferInstance.STATUS_FORM_SENT};
Cursor cursor = getInstancesCursor(null, selection, selectionArgs, null);
List<TransferInstance> transferInstanceList = getInstancesFromCursor(cursor);
if (transferInstanceList.size() > 0) {
return transferInstanceList.get(0);
}
return null;
}

public List<TransferInstance> getInstancesFromCursor(Cursor cursor) {
List<TransferInstance> instances = new ArrayList<>();
Expand All @@ -96,6 +123,7 @@ public List<TransferInstance> getInstancesFromCursor(Cursor cursor) {
int instanceIdColumnIndex = cursor.getColumnIndex(TransferInstance.INSTANCE_ID);
int transferStatusColumnIndex = cursor.getColumnIndex(TransferInstance.TRANSFER_STATUS);
int lastStatusChangeDateColumnIndex = cursor.getColumnIndex(TransferInstance.LAST_STATUS_CHANGE_DATE);
int receivedReviewStatusColumnIndex = cursor.getColumnIndex(TransferInstance.RECEIVED_REVIEW_STATUS);

TransferInstance transferInstance = new TransferInstance();
transferInstance.setId(cursor.getLong(idColumnIndex));
Expand All @@ -104,6 +132,7 @@ public List<TransferInstance> getInstancesFromCursor(Cursor cursor) {
transferInstance.setInstanceId(cursor.getLong(instanceIdColumnIndex));
transferInstance.setTransferStatus(cursor.getString(transferStatusColumnIndex));
transferInstance.setLastStatusChangeDate(cursor.getLong(lastStatusChangeDateColumnIndex));
transferInstance.setReceivedReviewStatus(cursor.getInt(receivedReviewStatusColumnIndex));

instances.add(transferInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

import timber.log.Timber;

import static org.odk.share.dto.InstanceMap.INSTANCE_UUID;
import static org.odk.share.dto.TransferInstance.ID;
import static org.odk.share.dto.TransferInstance.INSTANCE_ID;
import static org.odk.share.dto.TransferInstance.INSTRUCTIONS;
import static org.odk.share.dto.TransferInstance.LAST_STATUS_CHANGE_DATE;
import static org.odk.share.dto.TransferInstance.RECEIVED_REVIEW_STATUS;
import static org.odk.share.dto.TransferInstance.REVIEW_STATUS;
import static org.odk.share.dto.TransferInstance.STATUS_UNREVIEWED;
import static org.odk.share.dto.TransferInstance.TRANSFER_STATUS;
Expand All @@ -26,6 +28,7 @@ public class ShareDatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "share.db";
public static final String SHARE_TABLE_NAME = "transfers";
public static final String SHARE_INSTANCE_TABLE = "map_instance";

private static final int DATABASE_VERSION = 1;

Expand Down Expand Up @@ -53,9 +56,15 @@ private void createInstancesTable(SQLiteDatabase db) {
+ INSTRUCTIONS + " text, "
+ INSTANCE_ID + " integer not null, "
+ TRANSFER_STATUS + " text not null, "
+ RECEIVED_REVIEW_STATUS + " integer,"
+ VISITED_COUNT + " integer, "
+ LAST_STATUS_CHANGE_DATE + " date not null ); ");

db.execSQL("CREATE TABLE " + SHARE_INSTANCE_TABLE + " ("
+ ID + " integer primary key, "
+ INSTANCE_UUID + " text not null, "
+ INSTANCE_ID + " integer not null ); ");

}

public long insertInstance(ContentValues values) {
Expand All @@ -74,4 +83,13 @@ public long insertInstance(ContentValues values) {
sqLiteDatabase.close();
return id;
}

public long insertMapping(ContentValues values) {
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();

long id = sqLiteDatabase.insert(SHARE_INSTANCE_TABLE, null, values);
sqLiteDatabase.close();

return id;
}
}
39 changes: 39 additions & 0 deletions share_app/src/main/java/org/odk/share/dto/InstanceMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.odk.share.dto;

/**
* Created by laksh on 8/2/2018.
*/

public class InstanceMap {
public static final String INSTANCE_UUID = "instance_uuid";
public static final String ID = "_id";
public static final String INSTANCE_ID = "instanceId";

long id;
String uuid;
long transferId;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public long getTransferId() {
return transferId;
}

public void setTransferId(long transferId) {
this.transferId = transferId;
}
}
Loading

0 comments on commit 7d0b99d

Please sign in to comment.