Updates to task list to handle editing, creating, deleting.

pull/14/head
Tim Su 17 years ago
parent 81cd7de0df
commit 3c09c367dc

@ -117,6 +117,7 @@
<string name="taskList_tagsPrefix">Tags:</string> <string name="taskList_tagsPrefix">Tags:</string>
<string name="taskList_notesPrefix">Notes:</string> <string name="taskList_notesPrefix">Notes:</string>
<string name="taskList_createdPrefix">Created:</string> <string name="taskList_createdPrefix">Created:</string>
<string name="taskList_deleted">Deleted</string>
<!-- menu items --> <!-- menu items -->
<string name="taskList_menu_insert">Add</string> <string name="taskList_menu_insert">Add</string>
@ -274,6 +275,7 @@ Wish me luck!\n
<!-- Dialog Boxes --> <!-- Dialog Boxes -->
<skip /> <skip />
<string name="loading">Loading...</string> <string name="loading">Loading...</string>
<string name="updating">Updating List...</string>
<string name="information_title">Information</string> <string name="information_title">Information</string>
<string name="question_title">Question</string> <string name="question_title">Question</string>
<string name="notify_yes">View Task</string> <string name="notify_yes">View Task</string>

@ -540,7 +540,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private void discardButtonClick() { private void discardButtonClick() {
shouldSaveState = false; shouldSaveState = false;
setResult(RESULT_CANCELED); setResult(Constants.RESULT_DISCARD);
finish(); finish();
} }

@ -98,6 +98,7 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
private int resource; private int resource;
private LayoutInflater inflater; private LayoutInflater inflater;
private TaskListAdapterHooks hooks; private TaskListAdapterHooks hooks;
private TextView deletedItemView = new TextView(getContext());
private Integer fontSizePreference; private Integer fontSizePreference;
private AlertController alarmController; private AlertController alarmController;
@ -191,6 +192,9 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView; View view = convertView;
if(objects.get(position) == null)
return deletedItemView;
if(view == null) { if(view == null) {
view = inflater.inflate(resource, parent, false); view = inflater.inflate(resource, parent, false);
initializeView(view); initializeView(view);
@ -211,6 +215,7 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
final TextView name = ((TextView)view.findViewById(R.id.task_name)); final TextView name = ((TextView)view.findViewById(R.id.task_name));
if(fontSizePreference != null && fontSizePreference > 0) if(fontSizePreference != null && fontSizePreference > 0)
name.setTextSize(fontSizePreference); name.setTextSize(fontSizePreference);
deletedItemView.setText(getContext().getResources().getString(R.string.taskList_deleted));
} }
/** /**
@ -222,12 +227,13 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
private void setupView(View view, final TaskModelForList task) { private void setupView(View view, final TaskModelForList task) {
Resources r = activity.getResources(); Resources r = activity.getResources();
if(task == null)
return;
view.setTag(task); view.setTag(task);
setFieldContentsAndVisibility(view, task); setFieldContentsAndVisibility(view, task);
if(task == null) {
return;
}
final CheckBox progress = ((CheckBox)view.findViewById(R.id.cb1)); final CheckBox progress = ((CheckBox)view.findViewById(R.id.cb1));
progress.setChecked(task.isTaskCompleted()); progress.setChecked(task.isTaskCompleted());
@ -266,6 +272,11 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
/** Helper method to set the contents and visibility of each field */ /** Helper method to set the contents and visibility of each field */
private void setFieldContentsAndVisibility(View view, TaskModelForList task) { private void setFieldContentsAndVisibility(View view, TaskModelForList task) {
if(task == null) {
view.setVisibility(View.GONE);
return;
}
Resources r = getContext().getResources(); Resources r = getContext().getResources();
TaskFieldsVisibility visibleFields = Preferences.getTaskFieldsVisibility(activity); TaskFieldsVisibility visibleFields = Preferences.getTaskFieldsVisibility(activity);
boolean isExpanded = CACHE_TRUE.equals(task.getCachedLabel(KEY_EXPANDED)); boolean isExpanded = CACHE_TRUE.equals(task.getCachedLabel(KEY_EXPANDED));
@ -542,19 +553,6 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
} }
/**
* Removes the item at the specified position in the list (not reltaed
* to task identifier number
*
* @param listView parent view to refresh
* @param position the index of the item
*/
public void removeItem(ListView listView, int position) {
View view = listView.getChildAt(position);
view.setVisibility(View.GONE);
objects.set(position, null);
}
/** /**
* Refresh the item given at the specified position in the list (not * Refresh the item given at the specified position in the list (not
* related to task identifier number) * related to task identifier number)
@ -630,11 +628,11 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
TaskModelForList task = (TaskModelForList)v.getTag(); TaskModelForList task = (TaskModelForList)v.getTag();
int position = objects.indexOf(task); int id = (int)task.getTaskIdentifier().getId();
menu.add(position, CONTEXT_EDIT_ID, Menu.NONE, menu.add(id, CONTEXT_EDIT_ID, Menu.NONE,
R.string.taskList_context_edit); R.string.taskList_context_edit);
menu.add(position, CONTEXT_DELETE_ID, Menu.NONE, menu.add(id, CONTEXT_DELETE_ID, Menu.NONE,
R.string.taskList_context_delete); R.string.taskList_context_delete);
int timerTitle; int timerTitle;
@ -642,11 +640,11 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
timerTitle = R.string.taskList_context_startTimer; timerTitle = R.string.taskList_context_startTimer;
else else
timerTitle = R.string.taskList_context_stopTimer; timerTitle = R.string.taskList_context_stopTimer;
menu.add(position, CONTEXT_TIMER_ID, Menu.NONE, timerTitle); menu.add(id, CONTEXT_TIMER_ID, Menu.NONE, timerTitle);
if(task.getDefiniteDueDate() != null || if(task.getDefiniteDueDate() != null ||
task.getPreferredDueDate() != null) task.getPreferredDueDate() != null)
menu.add(position, CONTEXT_POSTPONE_ID, Menu.NONE, menu.add(id, CONTEXT_POSTPONE_ID, Menu.NONE,
R.string.taskList_context_postpone); R.string.taskList_context_postpone);
menu.setHeaderTitle(task.getName()); menu.setHeaderTitle(task.getName());
@ -664,8 +662,8 @@ public class TaskListAdapter extends ArrayAdapter<TaskModelForList> {
} }
}); });
Button deleteButton = (Button)view.findViewById(R.id.timer); Button toggleTimerButton = (Button)view.findViewById(R.id.timer);
deleteButton.setOnClickListener(new View.OnClickListener() { toggleTimerButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
View parent = (View)v.getParent().getParent().getParent().getParent(); View parent = (View)v.getParent().getParent().getParent().getParent();

@ -127,6 +127,7 @@ public class TaskListSubActivity extends SubActivity {
// other instance variables // other instance variables
private Map<TagIdentifier, TagModelForView> tagMap; private Map<TagIdentifier, TagModelForView> tagMap;
private ArrayList<TaskModelForList> taskArray; private ArrayList<TaskModelForList> taskArray;
private HashMap<Long, TaskModelForList> tasksById;
private HashMap<TaskModelForList, String> taskTags; private HashMap<TaskModelForList, String> taskTags;
private Long selectedTaskId = null; private Long selectedTaskId = null;
private TaskModelForList selectedTask = null; private TaskModelForList selectedTask = null;
@ -141,7 +142,6 @@ public class TaskListSubActivity extends SubActivity {
private static SortMode sortMode = SortMode.AUTO; private static SortMode sortMode = SortMode.AUTO;
private static boolean sortReverse = false; private static boolean sortReverse = false;
private TagModelForView filterTag = null; private TagModelForView filterTag = null;
private int editedObjectPosition = -1;
/* ====================================================================== /* ======================================================================
* ======================================================= initialization * ======================================================= initialization
@ -177,6 +177,7 @@ public class TaskListSubActivity extends SubActivity {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
loadingText.setText(getParent().getResources().getString(R.string.updating));
loadingText.setVisibility(View.VISIBLE); loadingText.setVisibility(View.VISIBLE);
} }
}); });
@ -451,6 +452,7 @@ public class TaskListSubActivity extends SubActivity {
tagMap = getTagController().getAllTagsAsMap(getParent()); tagMap = getTagController().getAllTagsAsMap(getParent());
taskTags = new HashMap<TaskModelForList, String>(); taskTags = new HashMap<TaskModelForList, String>();
StringBuilder tagBuilder = new StringBuilder(); StringBuilder tagBuilder = new StringBuilder();
tasksById = new HashMap<Long, TaskModelForList>();
for(Iterator<TaskModelForList> i = taskArray.iterator(); i.hasNext();) { for(Iterator<TaskModelForList> i = taskArray.iterator(); i.hasNext();) {
TaskModelForList task = i.next(); TaskModelForList task = i.next();
@ -486,6 +488,8 @@ public class TaskListSubActivity extends SubActivity {
} }
} }
tasksById.put(task.getTaskIdentifier().getId(), task);
if(task.isTaskCompleted()) if(task.isTaskCompleted())
completedTasks++; completedTasks++;
} }
@ -729,13 +733,11 @@ public class TaskListSubActivity extends SubActivity {
}); });
} else if(requestCode == ACTIVITY_TAGS) { } else if(requestCode == ACTIVITY_TAGS) {
switchToActivity(TaskList.AC_TAG_LIST, null); switchToActivity(TaskList.AC_TAG_LIST, null);
} else if(requestCode == ACTIVITY_EDIT && editedObjectPosition != -1) { } else if((requestCode == ACTIVITY_EDIT || requestCode == ACTIVITY_CREATE) &&
resultCode != Constants.RESULT_DISCARD) {
// refresh, since stuff might have changed... // refresh, since stuff might have changed...
loadingThread = new Thread(reLoadRunnable);
// TODO reload task & tags from database loadingThread.start();
listAdapter.refreshItem(listView, editedObjectPosition);
editedObjectPosition = -1;
} }
} }
@ -750,7 +752,7 @@ public class TaskListSubActivity extends SubActivity {
} }
/** Show a dialog box and delete the task specified */ /** Show a dialog box and delete the task specified */
private void deleteTask(final TaskModelForList task, final int position) { private void deleteTask(final TaskModelForList task) {
new AlertDialog.Builder(getParent()) new AlertDialog.Builder(getParent())
.setTitle(R.string.delete_title) .setTitle(R.string.delete_title)
.setMessage(R.string.delete_this_task_title) .setMessage(R.string.delete_this_task_title)
@ -759,7 +761,8 @@ public class TaskListSubActivity extends SubActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
listAdapter.refreshItem(listView, position); listAdapter.remove(task);
taskArray.remove(task);
getTaskController().deleteTask(task.getTaskIdentifier()); getTaskController().deleteTask(task.getTaskIdentifier());
} }
}) })
@ -769,8 +772,6 @@ public class TaskListSubActivity extends SubActivity {
/** Take you to the task edit page */ /** Take you to the task edit page */
private void editTask(TaskModelForList task) { private void editTask(TaskModelForList task) {
editedObjectPosition = taskArray.indexOf(task);
Intent intent = new Intent(getParent(), TaskEdit.class); Intent intent = new Intent(getParent(), TaskEdit.class);
intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN, intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN,
task.getTaskIdentifier().getId()); task.getTaskIdentifier().getId());
@ -890,19 +891,19 @@ public class TaskListSubActivity extends SubActivity {
// --- list context menu items // --- list context menu items
case TaskListAdapter.CONTEXT_EDIT_ID: case TaskListAdapter.CONTEXT_EDIT_ID:
task = taskArray.get(item.getGroupId()); task = tasksById.get((long)item.getGroupId());
editTask(task); editTask(task);
return true; return true;
case TaskListAdapter.CONTEXT_DELETE_ID: case TaskListAdapter.CONTEXT_DELETE_ID:
task = taskArray.get(item.getGroupId()); task = tasksById.get((long)item.getGroupId());
deleteTask(task, item.getGroupId()); deleteTask(task);
return true; return true;
case TaskListAdapter.CONTEXT_TIMER_ID: case TaskListAdapter.CONTEXT_TIMER_ID:
task = taskArray.get(item.getGroupId()); task = tasksById.get((long)item.getGroupId());
toggleTimer(task); toggleTimer(task);
return true; return true;
case TaskListAdapter.CONTEXT_POSTPONE_ID: case TaskListAdapter.CONTEXT_POSTPONE_ID:
task = taskArray.get(item.getGroupId()); task = tasksById.get((long)item.getGroupId());
DialogUtilities.dayHourPicker(getParent(), DialogUtilities.dayHourPicker(getParent(),
r.getString(R.string.taskList_postpone_dialog), r.getString(R.string.taskList_postpone_dialog),
new OnNNumberPickedListener() { new OnNNumberPickedListener() {

@ -20,7 +20,10 @@ public class Constants {
/** Return to the task list view */ /** Return to the task list view */
public static final int RESULT_GO_HOME = Activity.RESULT_FIRST_USER; public static final int RESULT_GO_HOME = Activity.RESULT_FIRST_USER;
/** Discard changes */
public static final int RESULT_DISCARD = Activity.RESULT_FIRST_USER + 1;
/** Callback to force synchronization */ /** Callback to force synchronization */
public static final int RESULT_SYNCHRONIZE = Activity.RESULT_FIRST_USER + 1; public static final int RESULT_SYNCHRONIZE = Activity.RESULT_FIRST_USER + 2;
} }

@ -18,7 +18,7 @@ public class StartupReceiver extends BroadcastReceiver {
} }
/** Called when this application is started up */ /** Called when this application is started up */
public static void onStartupApplication(Context context) { public static void onStartupApplication(final Context context) {
if(hasStartedUp) if(hasStartedUp)
return; return;
@ -34,9 +34,18 @@ public class StartupReceiver extends BroadcastReceiver {
// if we just got upgraded, set the alarms // if we just got upgraded, set the alarms
boolean justUpgraded = latestSetVersion != version; boolean justUpgraded = latestSetVersion != version;
final int finalVersion = version;
if(justUpgraded) { if(justUpgraded) {
Notifications.scheduleAllAlarms(context); new Thread(new Runnable() {
Preferences.setCurrentVersion(context, version); @Override
public void run() {
Notifications.scheduleAllAlarms(context);
// do this after all alarms are scheduled, so if we're
// interrupted, the thread will resume later
Preferences.setCurrentVersion(context, finalVersion);
}
}).start();
} }
Preferences.setPreferenceDefaults(context); Preferences.setPreferenceDefaults(context);

Loading…
Cancel
Save