Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds 'Undo Complete' action for completed items

Closes #66, closes #87
  • Loading branch information...
commit 96a4892f0349a45a25a2e1199c82e16490c8f381 1 parent bd4027e
@AdamZaloudek AdamZaloudek authored ginatrapani committed
View
5 res/menu/context_completed.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:title="@string/unComplete" android:id="@+id/unComplete" />
+ <item android:title="@string/delete" android:id="@+id/delete" />
+</menu>
View
1  res/values/strings.xml
@@ -20,6 +20,7 @@
<string name="priority">Prioritize</string>
<string name="update">Update</string>
<string name="delete">Delete</string>
+ <string name="unComplete">Undo Complete</string>
<string name="context">Context</string>
<string name="project">Project</string>
<string name="tag">Tag</string>
View
62 src/com/todotxt/todotxttouch/TodoTxtTouch.java
@@ -265,7 +265,19 @@ public boolean onCreateOptionsMenu(Menu menu) {
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.main_long, menu);
+ AdapterView.AdapterContextMenuInfo menuInfoAdap = (AdapterView.AdapterContextMenuInfo) menuInfo;
+ final int pos;
+ if (m_pos != Constants.INVALID_POSITION) {
+ pos = m_pos;
+ } else {
+ pos = menuInfoAdap.position;
+ }
+ final Task task = m_adapter.getItem(pos);
+ if (task.text.startsWith(TaskHelper.COMPLETED)) {
+ inflater.inflate(R.menu.context_completed, menu);
+ } else {
+ inflater.inflate(R.menu.main_long, menu);
+ }
}
@Override
@@ -387,6 +399,54 @@ protected void onPostExecute(Boolean result) {
}
};
Util.showConfirmationDialog(this, R.string.areyousure, listener);
+ } else if (menuid == R.id.unComplete) {
+ Log.v(TAG, "undo Complete");
+ OnClickListener listener = new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final Task task = m_adapter.getItem(pos);
+ new AsyncTask<Void, Void, Boolean>() {
+ protected void onPreExecute() {
+ m_ProgressDialog = ProgressDialog.show(
+ TodoTxtTouch.this,
+ "Removing Complete Status",
+ "Please wait...", true);
+ }
+
+ @Override
+ protected Boolean doInBackground(Void... params) {
+ try {
+ if (!task.text.startsWith(TaskHelper.COMPLETED)) {
+ return true;
+ } else {
+ String text = task.text.substring(13);
+ Log.v(TAG,
+ "Marking as incomplete task with this text: "
+ + text);
+ return m_app.m_util.updateTask(
+ TaskHelper.NONE, text, task);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, e.getMessage(), e);
+ }
+ return false;
+ }
+
+ protected void onPostExecute(Boolean result) {
+ m_ProgressDialog.dismiss();
+ if (result) {
+ Util.showToastLong(TodoTxtTouch.this,
+ "Task marked as not completed");
+ } else {
+ Util.showToastLong(TodoTxtTouch.this,
+ "Could not mark task as not completed");
+ }
+ setFilteredTasks(true);
+ }
+ }.execute();
+ }
+ };
+ Util.showConfirmationDialog(this, R.string.areyousure, listener);
} else if (menuid == R.id.priority) {
Log.v(TAG, "priority");
final String[] prioArr = { "" + TaskHelper.NONE, "A", "B", "C",
Please sign in to comment.
Something went wrong with that request. Please try again.