|
|
|
|
@ -18,6 +18,7 @@
|
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
package com.timsu.astrid.activities;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
@ -148,6 +149,7 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
TagModelForView filterTag = null;
|
|
|
|
|
CharSequence windowTitle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Handler handler = null;
|
|
|
|
|
Long selectedTaskId = null;
|
|
|
|
|
Runnable reLoadRunnable = null;
|
|
|
|
|
@ -159,16 +161,18 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
private static SortMode sortMode = SortMode.AUTO;
|
|
|
|
|
private static boolean sortReverse = false;
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
|
/*
|
|
|
|
|
* ======================================================================
|
|
|
|
|
* ======================================================= initialization
|
|
|
|
|
* ====================================================================== */
|
|
|
|
|
* ======================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public TaskListSubActivity(TaskList parent, int code, View view) {
|
|
|
|
|
super(parent, code, view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
/** Called when loading up the activity */
|
|
|
|
|
/* Called when loading up the activity */
|
|
|
|
|
public void onDisplay(final Bundle variables) {
|
|
|
|
|
// process task that's selected, if any
|
|
|
|
|
if (variables != null && variables.containsKey(LOAD_INSTANCE_TOKEN)) {
|
|
|
|
|
@ -184,7 +188,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
public void run() {
|
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
loadingText.setText(getParent().getResources().getString(R.string.updating));
|
|
|
|
|
loadingText.setText(getParent().getResources()
|
|
|
|
|
.getString(R.string.updating));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -206,16 +211,21 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
if (selectedTaskId == null)
|
|
|
|
|
context.selectedTask = null;
|
|
|
|
|
|
|
|
|
|
// process tag to filter, if any (intercept UNTAGGED identifier, if applicable)
|
|
|
|
|
// process tag to filter, if any (intercept UNTAGGED identifier, if
|
|
|
|
|
// applicable)
|
|
|
|
|
if (variables != null && variables.containsKey(TAG_TOKEN)) {
|
|
|
|
|
TagIdentifier identifier = new TagIdentifier(variables.getLong(TAG_TOKEN));
|
|
|
|
|
TagIdentifier identifier = new TagIdentifier(variables
|
|
|
|
|
.getLong(TAG_TOKEN));
|
|
|
|
|
context.tagMap = getTagController().getAllTagsAsMap();
|
|
|
|
|
if (context.tagMap.containsKey(identifier))
|
|
|
|
|
context.filterTag = context.tagMap.get(identifier);
|
|
|
|
|
else if (identifier.equals(TagModelForView.UNTAGGED_IDENTIFIER))
|
|
|
|
|
context.filterTag = TagModelForView.getUntaggedModel();
|
|
|
|
|
else
|
|
|
|
|
Toast.makeText(getParent(), R.string.missing_tag, Toast.LENGTH_SHORT).show();
|
|
|
|
|
Toast.makeText(getParent(), R.string.missing_tag,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
|
|
FlurryAgent.onEvent("filter-by-tag");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// time to go! creates a thread that loads the task list, then
|
|
|
|
|
@ -232,8 +242,9 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
fillData();
|
|
|
|
|
|
|
|
|
|
// open up reminder box
|
|
|
|
|
if(variables != null && variables.containsKey(NOTIF_FLAGS_TOKEN) &&
|
|
|
|
|
context.selectedTask != null) {
|
|
|
|
|
if (variables != null
|
|
|
|
|
&& variables.containsKey(NOTIF_FLAGS_TOKEN)
|
|
|
|
|
&& context.selectedTask != null) {
|
|
|
|
|
FlurryAgent.onEvent("open-notification");
|
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
@ -241,7 +252,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
|
|
if (variables.containsKey(NOTIF_REPEAT_TOKEN))
|
|
|
|
|
repeatInterval = variables.getLong(NOTIF_REPEAT_TOKEN);
|
|
|
|
|
repeatInterval = variables
|
|
|
|
|
.getLong(NOTIF_REPEAT_TOKEN);
|
|
|
|
|
flags = variables.getInt(NOTIF_FLAGS_TOKEN);
|
|
|
|
|
showNotificationAlert(context.selectedTask,
|
|
|
|
|
repeatInterval, flags);
|
|
|
|
|
@ -260,16 +272,15 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
listView = (ListView) findViewById(R.id.tasklist);
|
|
|
|
|
loadingText = (TextView) findViewById(R.id.loading);
|
|
|
|
|
addButton = (Button) findViewById(R.id.addtask);
|
|
|
|
|
addButton.setOnClickListener(new
|
|
|
|
|
View.OnClickListener() {
|
|
|
|
|
addButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
createTask(null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
layout = getView();
|
|
|
|
|
layout.setOnCreateContextMenuListener(
|
|
|
|
|
new OnCreateContextMenuListener() {
|
|
|
|
|
layout
|
|
|
|
|
.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
|
|
|
|
ContextMenuInfo menuInfo) {
|
|
|
|
|
if (menu.hasVisibleItems())
|
|
|
|
|
@ -280,7 +291,7 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
/** Create options menu (displayed when user presses menu key) */
|
|
|
|
|
/* Create options menu (displayed when user presses menu key) */
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
MenuItem item;
|
|
|
|
|
|
|
|
|
|
@ -350,7 +361,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
ALPHA {
|
|
|
|
|
@Override
|
|
|
|
|
int compareTo(TaskModelForList arg0, TaskModelForList arg1) {
|
|
|
|
|
return arg0.getName().toLowerCase().compareTo(arg1.getName().toLowerCase());
|
|
|
|
|
return arg0.getName().toLowerCase().compareTo(
|
|
|
|
|
arg1.getName().toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
DUEDATE {
|
|
|
|
|
@ -368,6 +380,7 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
else
|
|
|
|
|
return new Date(2020, 1, 1).getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
int compareTo(TaskModelForList arg0, TaskModelForList arg1) {
|
|
|
|
|
return (int) ((getDueDate(arg0) - getDueDate(arg1)) / 1000);
|
|
|
|
|
@ -383,10 +396,11 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
abstract int compareTo(TaskModelForList arg0, TaskModelForList arg1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
|
/*
|
|
|
|
|
* ======================================================================
|
|
|
|
|
* ======================================================== notifications
|
|
|
|
|
* ====================================================================== */
|
|
|
|
|
* ======================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Called when user clicks on a notification to get here */
|
|
|
|
|
private void showNotificationAlert(final TaskModelForList task,
|
|
|
|
|
@ -394,7 +408,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
Resources r = getResources();
|
|
|
|
|
|
|
|
|
|
// clear notifications
|
|
|
|
|
Notifications.clearAllNotifications(getParent(), task.getTaskIdentifier());
|
|
|
|
|
Notifications.clearAllNotifications(getParent(), task
|
|
|
|
|
.getTaskIdentifier());
|
|
|
|
|
|
|
|
|
|
String response;
|
|
|
|
|
if (Preferences.shouldShowNags(getParent())) {
|
|
|
|
|
@ -402,25 +417,29 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
response = responses[new Random().nextInt(responses.length)];
|
|
|
|
|
} else
|
|
|
|
|
response = r.getString(R.string.taskList_nonag_reminder);
|
|
|
|
|
new AlertDialog.Builder(getParent())
|
|
|
|
|
.setTitle(R.string.taskView_notifyTitle)
|
|
|
|
|
.setMessage(task.getName() + "\n\n" + response)
|
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
|
new AlertDialog.Builder(getParent()).setTitle(
|
|
|
|
|
R.string.taskView_notifyTitle).setMessage(
|
|
|
|
|
task.getName() + "\n\n" + response).setIcon(
|
|
|
|
|
android.R.drawable.ic_dialog_alert)
|
|
|
|
|
|
|
|
|
|
// yes, i will do it: just closes this dialog
|
|
|
|
|
.setPositiveButton(R.string.notify_yes, null)
|
|
|
|
|
|
|
|
|
|
// no, i will ignore: quits application
|
|
|
|
|
.setNegativeButton(R.string.notify_no, new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
.setNegativeButton(R.string.notify_no,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
|
int which) {
|
|
|
|
|
TaskList.shouldCloseInstance = true;
|
|
|
|
|
closeActivity();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// snooze: sets a new temporary alert, closes application
|
|
|
|
|
.setNeutralButton(R.string.notify_snooze, new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
.setNeutralButton(R.string.notify_snooze,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
|
int which) {
|
|
|
|
|
snoozeAlert(task, repeatInterval, flags);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -428,8 +447,9 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Helper method to "snooze" an alert (i.e. set a new one for some time
|
|
|
|
|
* from now.
|
|
|
|
|
/**
|
|
|
|
|
* Helper method to "snooze" an alert (i.e. set a new one for some time from
|
|
|
|
|
* now.
|
|
|
|
|
*
|
|
|
|
|
* @param task
|
|
|
|
|
* @param repeatInterval
|
|
|
|
|
@ -437,13 +457,12 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
*/
|
|
|
|
|
private void snoozeAlert(final TaskModelForList task,
|
|
|
|
|
final long repeatInterval, final int flags) {
|
|
|
|
|
DialogUtilities.hourMinutePicker(getParent(),
|
|
|
|
|
getResources().getString(R.string.notify_snooze_title),
|
|
|
|
|
new OnNNumberPickedListener() {
|
|
|
|
|
DialogUtilities.hourMinutePicker(getParent(), getResources().getString(
|
|
|
|
|
R.string.notify_snooze_title), new OnNNumberPickedListener() {
|
|
|
|
|
public void onNumbersPicked(int[] values) {
|
|
|
|
|
int snoozeSeconds = values[0] * 3600 + values[1] * 60;
|
|
|
|
|
Notifications.createSnoozeAlarm(getParent(),
|
|
|
|
|
task.getTaskIdentifier(), snoozeSeconds, flags,
|
|
|
|
|
Notifications.createSnoozeAlarm(getParent(), task
|
|
|
|
|
.getTaskIdentifier(), snoozeSeconds, flags,
|
|
|
|
|
repeatInterval);
|
|
|
|
|
|
|
|
|
|
TaskList.shouldCloseInstance = true;
|
|
|
|
|
@ -452,9 +471,11 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
|
/*
|
|
|
|
|
* ======================================================================
|
|
|
|
|
* ====================================================== populating list
|
|
|
|
|
* ====================================================================== */
|
|
|
|
|
* ======================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Helper method returns true if the task is considered 'hidden' */
|
|
|
|
|
private boolean isTaskHidden(TaskModelForList task) {
|
|
|
|
|
@ -465,7 +486,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (context.filterTag == null) {
|
|
|
|
|
if(context.taskTags.get(task).contains(TagModelForView.HIDDEN_FROM_MAIN_LIST_PREFIX))
|
|
|
|
|
if (context.taskTags.get(task).contains(
|
|
|
|
|
TagModelForView.HIDDEN_FROM_MAIN_LIST_PREFIX))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -505,15 +527,17 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
tasksCursor = getTaskController().getActiveTaskListCursor();
|
|
|
|
|
}
|
|
|
|
|
startManagingCursor(tasksCursor);
|
|
|
|
|
context.taskArray = Collections.synchronizedList(getTaskController().
|
|
|
|
|
createTaskListFromCursor(tasksCursor));
|
|
|
|
|
context.taskArray = Collections
|
|
|
|
|
.synchronizedList(getTaskController()
|
|
|
|
|
.createTaskListFromCursor(tasksCursor));
|
|
|
|
|
|
|
|
|
|
// read tags and apply filters
|
|
|
|
|
context.tagMap = getTagController().getAllTagsAsMap();
|
|
|
|
|
context.taskTags = new HashMap<TaskModelForList, String>();
|
|
|
|
|
StringBuilder tagBuilder = new StringBuilder();
|
|
|
|
|
context.tasksById = new HashMap<Long, TaskModelForList>();
|
|
|
|
|
for(Iterator<TaskModelForList> i = context.taskArray.iterator(); i.hasNext();) {
|
|
|
|
|
for (Iterator<TaskModelForList> i = context.taskArray.iterator(); i
|
|
|
|
|
.hasNext();) {
|
|
|
|
|
if (Thread.interrupted())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
@ -526,13 +550,14 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(selectedTaskId != null && task.getTaskIdentifier().getId() == selectedTaskId) {
|
|
|
|
|
if (selectedTaskId != null
|
|
|
|
|
&& task.getTaskIdentifier().getId() == selectedTaskId) {
|
|
|
|
|
context.selectedTask = task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get list of tags
|
|
|
|
|
LinkedList<TagIdentifier> tagIds = getTagController().getTaskTags(
|
|
|
|
|
task.getTaskIdentifier());
|
|
|
|
|
LinkedList<TagIdentifier> tagIds = getTagController()
|
|
|
|
|
.getTaskTags(task.getTaskIdentifier());
|
|
|
|
|
tagBuilder.delete(0, tagBuilder.length());
|
|
|
|
|
for (Iterator<TagIdentifier> j = tagIds.iterator(); j.hasNext();) {
|
|
|
|
|
TagModelForView tag = context.tagMap.get(j.next());
|
|
|
|
|
@ -567,8 +592,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
Log.w("astrid", "StaleDataException", e);
|
|
|
|
|
return;
|
|
|
|
|
} catch (final IllegalStateException e) {
|
|
|
|
|
FlurryAgent.onError("task-list-error", e.toString(),
|
|
|
|
|
e.getClass().getSimpleName());
|
|
|
|
|
FlurryAgent.onError("task-list-error", e.toString(), e.getClass()
|
|
|
|
|
.getSimpleName());
|
|
|
|
|
|
|
|
|
|
// happens when you run out of memory usually
|
|
|
|
|
Log.e("astrid", "Error loading task list", e);
|
|
|
|
|
@ -576,14 +601,14 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
public void run() {
|
|
|
|
|
if (!e.getMessage().contains("Couldn't init cursor window"))
|
|
|
|
|
return;
|
|
|
|
|
DialogUtilities.okDialog(getParent(), "Ran out of memory! " +
|
|
|
|
|
"Try restarting Astrid...", null);
|
|
|
|
|
DialogUtilities.okDialog(getParent(), "Ran out of memory! "
|
|
|
|
|
+ "Try restarting Astrid...", null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
FlurryAgent.onError("task-list-error", e.toString(),
|
|
|
|
|
e.getClass().getSimpleName());
|
|
|
|
|
FlurryAgent.onError("task-list-error", e.toString(), e.getClass()
|
|
|
|
|
.getSimpleName());
|
|
|
|
|
|
|
|
|
|
Log.e("astrid", "Error loading task list", e);
|
|
|
|
|
return;
|
|
|
|
|
@ -606,26 +631,36 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
Resources r = getResources();
|
|
|
|
|
StringBuilder title = new StringBuilder().
|
|
|
|
|
append(r.getString(R.string.taskList_titlePrefix)).append(" ");
|
|
|
|
|
StringBuilder title = new StringBuilder().append(
|
|
|
|
|
r.getString(R.string.taskList_titlePrefix)).append(" ");
|
|
|
|
|
if (context.filterTag != null) {
|
|
|
|
|
if(TagModelForView.UNTAGGED_IDENTIFIER.equals(context.filterTag.getTagIdentifier())) {
|
|
|
|
|
title.append(r.getString(R.string.taskList_titleUntagged)).append(" ");
|
|
|
|
|
if (TagModelForView.UNTAGGED_IDENTIFIER
|
|
|
|
|
.equals(context.filterTag.getTagIdentifier())) {
|
|
|
|
|
title.append(
|
|
|
|
|
r.getString(R.string.taskList_titleUntagged))
|
|
|
|
|
.append(" ");
|
|
|
|
|
} else {
|
|
|
|
|
title.append(r.getString(R.string.taskList_titleTagPrefix,
|
|
|
|
|
context.filterTag.getName())).append(" ");
|
|
|
|
|
title.append(
|
|
|
|
|
r.getString(R.string.taskList_titleTagPrefix,
|
|
|
|
|
context.filterTag.getName())).append(
|
|
|
|
|
" ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (finalCompleted > 0)
|
|
|
|
|
title.append(r.getQuantityString(R.plurals.NactiveTasks,
|
|
|
|
|
finalActive, finalActive, context.taskArray.size()));
|
|
|
|
|
title
|
|
|
|
|
.append(r.getQuantityString(R.plurals.NactiveTasks,
|
|
|
|
|
finalActive, finalActive, context.taskArray
|
|
|
|
|
.size()));
|
|
|
|
|
else
|
|
|
|
|
title.append(r.getQuantityString(R.plurals.Ntasks,
|
|
|
|
|
context.taskArray.size(), context.taskArray.size()));
|
|
|
|
|
title
|
|
|
|
|
.append(r.getQuantityString(R.plurals.Ntasks,
|
|
|
|
|
context.taskArray.size(), context.taskArray
|
|
|
|
|
.size()));
|
|
|
|
|
if (finalHidden > 0)
|
|
|
|
|
title.append(" (+").append(finalHidden).append(" ").
|
|
|
|
|
append(r.getString(R.string.taskList_hiddenSuffix)).append(")");
|
|
|
|
|
title.append(" (+").append(finalHidden).append(" ").append(
|
|
|
|
|
r.getString(R.string.taskList_hiddenSuffix))
|
|
|
|
|
.append(")");
|
|
|
|
|
context.windowTitle = title;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -639,8 +674,7 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
public void run() {
|
|
|
|
|
// hide "add" button if we have too many tasks
|
|
|
|
|
int threshold = HIDE_ADD_BTN_PORTRAIT;
|
|
|
|
|
if(getParent().getResources().getConfiguration().orientation ==
|
|
|
|
|
Configuration.ORIENTATION_LANDSCAPE)
|
|
|
|
|
if (getParent().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
|
|
|
|
|
threshold = HIDE_ADD_BTN_LANDSCPE;
|
|
|
|
|
|
|
|
|
|
if (context.taskArray.size() > threshold)
|
|
|
|
|
@ -721,19 +755,21 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
|
|
|
|
|
if (context.selectedTask != null) {
|
|
|
|
|
try {
|
|
|
|
|
int selectedPosition = context.listAdapter.getPosition(context.selectedTask);
|
|
|
|
|
int selectedPosition = context.listAdapter
|
|
|
|
|
.getPosition(context.selectedTask);
|
|
|
|
|
View v = listView.getChildAt(selectedPosition);
|
|
|
|
|
context.listAdapter.setExpanded(v, context.selectedTask, true);
|
|
|
|
|
listView.setSelection(selectedPosition);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
FlurryAgent.onError("task-list-selected", e.toString(),
|
|
|
|
|
e.getClass().getSimpleName());
|
|
|
|
|
FlurryAgent.onError("task-list-selected", e.toString(), e
|
|
|
|
|
.getClass().getSimpleName());
|
|
|
|
|
Log.e("astrid", "error with selected task", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// filters context menu
|
|
|
|
|
listView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
|
|
|
|
listView
|
|
|
|
|
.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
|
|
|
|
ContextMenuInfo menuInfo) {
|
|
|
|
|
if (menu.hasVisibleItems())
|
|
|
|
|
@ -741,36 +777,40 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
Resources r = getResources();
|
|
|
|
|
menu.setHeaderTitle(R.string.taskList_filter_title);
|
|
|
|
|
|
|
|
|
|
MenuItem item = menu.add(Menu.NONE, CONTEXT_FILTER_HIDDEN,
|
|
|
|
|
Menu.NONE, R.string.taskList_filter_hidden);
|
|
|
|
|
MenuItem item = menu.add(Menu.NONE,
|
|
|
|
|
CONTEXT_FILTER_HIDDEN, Menu.NONE,
|
|
|
|
|
R.string.taskList_filter_hidden);
|
|
|
|
|
item.setCheckable(true);
|
|
|
|
|
item.setChecked(filterShowHidden);
|
|
|
|
|
|
|
|
|
|
item = menu.add(Menu.NONE, CONTEXT_FILTER_DONE, Menu.NONE,
|
|
|
|
|
R.string.taskList_filter_done);
|
|
|
|
|
item = menu.add(Menu.NONE, CONTEXT_FILTER_DONE,
|
|
|
|
|
Menu.NONE, R.string.taskList_filter_done);
|
|
|
|
|
item.setCheckable(true);
|
|
|
|
|
item.setChecked(filterShowDone);
|
|
|
|
|
|
|
|
|
|
if (context.filterTag != null) {
|
|
|
|
|
item = menu.add(Menu.NONE, CONTEXT_FILTER_TAG, Menu.NONE,
|
|
|
|
|
r.getString(R.string.taskList_filter_tagged,
|
|
|
|
|
item = menu.add(Menu.NONE, CONTEXT_FILTER_TAG,
|
|
|
|
|
Menu.NONE, r.getString(
|
|
|
|
|
R.string.taskList_filter_tagged,
|
|
|
|
|
context.filterTag.getName()));
|
|
|
|
|
item.setCheckable(true);
|
|
|
|
|
item.setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_AUTO, Menu.NONE,
|
|
|
|
|
R.string.taskList_sort_auto);
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_AUTO,
|
|
|
|
|
Menu.NONE, R.string.taskList_sort_auto);
|
|
|
|
|
item.setChecked(sortMode == SortMode.AUTO);
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_ALPHA, Menu.NONE,
|
|
|
|
|
R.string.taskList_sort_alpha);
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_ALPHA,
|
|
|
|
|
Menu.NONE, R.string.taskList_sort_alpha);
|
|
|
|
|
item.setChecked(sortMode == SortMode.ALPHA);
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_DUEDATE, Menu.NONE,
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP,
|
|
|
|
|
CONTEXT_SORT_DUEDATE, Menu.NONE,
|
|
|
|
|
R.string.taskList_sort_duedate);
|
|
|
|
|
item.setChecked(sortMode == SortMode.DUEDATE);
|
|
|
|
|
menu.setGroupCheckable(CONTEXT_SORT_GROUP, true, true);
|
|
|
|
|
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP, CONTEXT_SORT_REVERSE, Menu.NONE,
|
|
|
|
|
item = menu.add(CONTEXT_SORT_GROUP,
|
|
|
|
|
CONTEXT_SORT_REVERSE, Menu.NONE,
|
|
|
|
|
R.string.taskList_sort_reverse);
|
|
|
|
|
item.setCheckable(true);
|
|
|
|
|
item.setChecked(sortReverse);
|
|
|
|
|
@ -789,9 +829,11 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
context.loadingThread.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
|
/*
|
|
|
|
|
* ======================================================================
|
|
|
|
|
* ======================================================= event handlers
|
|
|
|
|
* ====================================================================== */
|
|
|
|
|
* ======================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Object onRetainNonConfigurationInstance() {
|
|
|
|
|
@ -843,9 +885,9 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
SynchronizationService.stop();
|
|
|
|
|
SynchronizationService.start();
|
|
|
|
|
|
|
|
|
|
} else if (context.taskArray != null &&
|
|
|
|
|
context.taskArray.size() > 0 &&
|
|
|
|
|
context.taskArray.size() < AUTO_REFRESH_MAX_LIST_SIZE) {
|
|
|
|
|
} else if (context.taskArray != null
|
|
|
|
|
&& context.taskArray.size() > 0
|
|
|
|
|
&& context.taskArray.size() < AUTO_REFRESH_MAX_LIST_SIZE) {
|
|
|
|
|
|
|
|
|
|
// invalidate caches
|
|
|
|
|
for (TaskModelForList task : context.taskArray)
|
|
|
|
|
@ -865,8 +907,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
sync.synchronize(getParent(), new SynchronizerListener() {
|
|
|
|
|
public void onSynchronizerFinished(int numServicesSynced) {
|
|
|
|
|
if (numServicesSynced == 0) {
|
|
|
|
|
DialogUtilities.okDialog(getParent(), getResources().getString(
|
|
|
|
|
R.string.sync_no_synchronizers), null);
|
|
|
|
|
DialogUtilities.okDialog(getParent(), getResources()
|
|
|
|
|
.getString(R.string.sync_no_synchronizers), null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
reloadList();
|
|
|
|
|
@ -887,7 +929,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
private void createTask(Character startCharacter) {
|
|
|
|
|
Intent intent = new Intent(getParent(), TaskEdit.class);
|
|
|
|
|
if (context.filterTag != null)
|
|
|
|
|
intent.putExtra(TaskEdit.TAG_NAME_TOKEN, context.filterTag.getName());
|
|
|
|
|
intent.putExtra(TaskEdit.TAG_NAME_TOKEN, context.filterTag
|
|
|
|
|
.getName());
|
|
|
|
|
if (startCharacter != null)
|
|
|
|
|
intent.putExtra(TaskEdit.START_CHAR_TOKEN, startCharacter);
|
|
|
|
|
launchActivity(intent, ACTIVITY_CREATE);
|
|
|
|
|
@ -895,27 +938,27 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
|
|
|
|
|
/** Show a dialog box and delete the task specified */
|
|
|
|
|
private void deleteTask(final TaskModelForList task) {
|
|
|
|
|
new AlertDialog.Builder(getParent())
|
|
|
|
|
.setTitle(R.string.delete_title)
|
|
|
|
|
.setMessage(R.string.delete_this_task_title)
|
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
|
.setPositiveButton(android.R.string.ok,
|
|
|
|
|
new AlertDialog.Builder(getParent()).setTitle(R.string.delete_title)
|
|
|
|
|
.setMessage(R.string.delete_this_task_title).setIcon(
|
|
|
|
|
android.R.drawable.ic_dialog_alert).setPositiveButton(
|
|
|
|
|
android.R.string.ok,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
|
int which) {
|
|
|
|
|
context.listAdapter.remove(task);
|
|
|
|
|
context.taskArray.remove(task);
|
|
|
|
|
getTaskController().deleteTask(task.getTaskIdentifier());
|
|
|
|
|
getTaskController().deleteTask(
|
|
|
|
|
task.getTaskIdentifier());
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
}).setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Take you to the task edit page */
|
|
|
|
|
private void editTask(TaskModelForList task) {
|
|
|
|
|
Intent intent = new Intent(getParent(), TaskEdit.class);
|
|
|
|
|
intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN,
|
|
|
|
|
task.getTaskIdentifier().getId());
|
|
|
|
|
intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN, task.getTaskIdentifier()
|
|
|
|
|
.getId());
|
|
|
|
|
launchActivity(intent, ACTIVITY_EDIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -929,7 +972,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
task.stopTimerAndUpdateElapsedTime();
|
|
|
|
|
}
|
|
|
|
|
getTaskController().saveTask(task);
|
|
|
|
|
context.listAdapter.refreshItem(listView, context.taskArray.indexOf(task));
|
|
|
|
|
context.listAdapter.refreshItem(listView, context.taskArray
|
|
|
|
|
.indexOf(task));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Show the tags view */
|
|
|
|
|
@ -977,10 +1021,10 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
private Date computePostponeDate(Date input, long postponeMillis,
|
|
|
|
|
boolean shiftFromTodayIfPast) {
|
|
|
|
|
if (input != null) {
|
|
|
|
|
if(shiftFromTodayIfPast && input.getTime() < System.currentTimeMillis())
|
|
|
|
|
if (shiftFromTodayIfPast
|
|
|
|
|
&& input.getTime() < System.currentTimeMillis())
|
|
|
|
|
input = new Date();
|
|
|
|
|
input = new Date(input.getTime() +
|
|
|
|
|
postponeMillis);
|
|
|
|
|
input = new Date(input.getTime() + postponeMillis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return input;
|
|
|
|
|
@ -991,16 +1035,17 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
final Resources r = getResources();
|
|
|
|
|
new NumberPickerDialog(getParent(), new OnNumberPickedListener() {
|
|
|
|
|
public void onNumberPicked(NumberPicker view, int number) {
|
|
|
|
|
Date date = new Date(System.currentTimeMillis() - 24L*3600*1000*number);
|
|
|
|
|
int deleted = getTaskController().deleteCompletedTasksOlderThan(date);
|
|
|
|
|
DialogUtilities.okDialog(getParent(), r.getQuantityString(R.plurals.Ntasks,
|
|
|
|
|
deleted, deleted) + " " + r.getString(R.string.taskList_deleted),
|
|
|
|
|
null);
|
|
|
|
|
Date date = new Date(System.currentTimeMillis() - 24L * 3600
|
|
|
|
|
* 1000 * number);
|
|
|
|
|
int deleted = getTaskController()
|
|
|
|
|
.deleteCompletedTasksOlderThan(date);
|
|
|
|
|
DialogUtilities.okDialog(getParent(), r.getQuantityString(
|
|
|
|
|
R.plurals.Ntasks, deleted, deleted)
|
|
|
|
|
+ " " + r.getString(R.string.taskList_deleted), null);
|
|
|
|
|
if (TaskListSubActivity.filterShowDone)
|
|
|
|
|
reloadList();
|
|
|
|
|
}
|
|
|
|
|
}, r.getString(R.string.taskList_cleanup_dialog),
|
|
|
|
|
30, 5, 0, 999).show();
|
|
|
|
|
}, r.getString(R.string.taskList_cleanup_dialog), 30, 5, 0, 999).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Show a dialog box to postpone your tasks */
|
|
|
|
|
@ -1008,7 +1053,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
FlurryAgent.onEvent("postpone-task");
|
|
|
|
|
|
|
|
|
|
final Resources r = getResources();
|
|
|
|
|
DialogUtilities.dayHourPicker(getParent(), r.getString(R.string.taskList_postpone_dialog),
|
|
|
|
|
DialogUtilities.dayHourPicker(getParent(), r
|
|
|
|
|
.getString(R.string.taskList_postpone_dialog),
|
|
|
|
|
new OnNNumberPickedListener() {
|
|
|
|
|
public void onNumbersPicked(int[] values) {
|
|
|
|
|
long postponeMillis = (values[0] * 24 + values[1]) * 3600L * 1000;
|
|
|
|
|
@ -1016,30 +1062,34 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
task.setPreferredDueDate(computePostponeDate(task
|
|
|
|
|
.getPreferredDueDate(), postponeMillis,
|
|
|
|
|
true));
|
|
|
|
|
task.setDefiniteDueDate(computePostponeDate(
|
|
|
|
|
task.getDefiniteDueDate(), postponeMillis, true));
|
|
|
|
|
task.setHiddenUntil(computePostponeDate(task.
|
|
|
|
|
getHiddenUntil(), postponeMillis, false));
|
|
|
|
|
.getPreferredDueDate(), postponeMillis, true));
|
|
|
|
|
task.setDefiniteDueDate(computePostponeDate(task
|
|
|
|
|
.getDefiniteDueDate(), postponeMillis, true));
|
|
|
|
|
task.setHiddenUntil(computePostponeDate(task
|
|
|
|
|
.getHiddenUntil(), postponeMillis, false));
|
|
|
|
|
|
|
|
|
|
// show nag
|
|
|
|
|
int postponeCount = getTaskController().fetchTaskPostponeCount(
|
|
|
|
|
int postponeCount = getTaskController()
|
|
|
|
|
.fetchTaskPostponeCount(
|
|
|
|
|
task.getTaskIdentifier()) + 1;
|
|
|
|
|
if (Preferences.shouldShowNags(getParent())) {
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
final String nagText;
|
|
|
|
|
if(postponeCount > 1 && random.nextFloat() < POSTPONE_STAT_PCT) {
|
|
|
|
|
nagText = r.getString(R.string.taskList_postpone_count,
|
|
|
|
|
if (postponeCount > 1
|
|
|
|
|
&& random.nextFloat() < POSTPONE_STAT_PCT) {
|
|
|
|
|
nagText = r.getString(
|
|
|
|
|
R.string.taskList_postpone_count,
|
|
|
|
|
postponeCount);
|
|
|
|
|
} else {
|
|
|
|
|
String[] nags = r.getStringArray(R.array.postpone_nags);
|
|
|
|
|
String[] nags = r
|
|
|
|
|
.getStringArray(R.array.postpone_nags);
|
|
|
|
|
nagText = nags[random.nextInt(nags.length)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.post(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
Toast.makeText(getParent(), nagText, Toast.LENGTH_LONG).show();
|
|
|
|
|
Toast.makeText(getParent(), nagText,
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -1070,7 +1120,8 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
showTagsView();
|
|
|
|
|
return true;
|
|
|
|
|
case SYNC_ID:
|
|
|
|
|
onActivityResult(ACTIVITY_SYNCHRONIZE, Constants.RESULT_SYNCHRONIZE, null);
|
|
|
|
|
onActivityResult(ACTIVITY_SYNCHRONIZE,
|
|
|
|
|
Constants.RESULT_SYNCHRONIZE, null);
|
|
|
|
|
return true;
|
|
|
|
|
case MORE_ID:
|
|
|
|
|
layout.showContextMenu();
|
|
|
|
|
@ -1086,13 +1137,13 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
launchActivity(new Intent(getParent(), EditPreferences.class), 0);
|
|
|
|
|
return true;
|
|
|
|
|
case OPTIONS_HELP_ID:
|
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
|
|
|
|
|
Uri.parse(Constants.HELP_URL));
|
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
|
|
|
|
|
.parse(Constants.HELP_URL));
|
|
|
|
|
launchActivity(browserIntent, 0);
|
|
|
|
|
return true;
|
|
|
|
|
case OPTIONS_QUICK_TIPS:
|
|
|
|
|
DialogUtilities.okDialog(getParent(),
|
|
|
|
|
getResources().getString(R.string.quick_tips), null);
|
|
|
|
|
DialogUtilities.okDialog(getParent(), getResources().getString(
|
|
|
|
|
R.string.quick_tips), null);
|
|
|
|
|
return true;
|
|
|
|
|
case OPTIONS_CLEANUP_ID:
|
|
|
|
|
cleanOldTasks();
|
|
|
|
|
@ -1164,9 +1215,11 @@ public class TaskListSubActivity extends SubActivity {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ======================================================================
|
|
|
|
|
/*
|
|
|
|
|
* ======================================================================
|
|
|
|
|
* ===================================================== getters / setters
|
|
|
|
|
* ====================================================================== */
|
|
|
|
|
* ======================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public TagModelForView getFilterTag() {
|
|
|
|
|
return context.filterTag;
|
|
|
|
|
|