Merge with 1/16 updates to koxx3 provider branch.

------------------------------------------------------------
Use --include-merges or -n0 to see merged revisions.
pull/14/head
Tim Su 16 years ago
parent 219f39dd39
commit d4920d6118

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timsu.astrid" package="com.timsu.astrid"
android:versionCode="123" android:versionName="2.10.2"> android:versionCode="124" android:versionName="2.10.3">
<!-- ============================ Metadata ============================ --> <!-- ============================ Metadata ============================ -->

@ -88,8 +88,8 @@ import com.timsu.astrid.widget.TimeDurationControlSet.TimeDurationType;
/** /**
* This activity is responsible for creating new tasks and editing existing * This activity is responsible for creating new tasks and editing existing
* ones. It saves a task when it is paused (screen rotated, back button pressed) * ones. It saves a task when it is paused (screen rotated, back button
* as long as the task has a title. * pressed) as long as the task has a title.
* *
* @author timsu * @author timsu
* *
@ -192,11 +192,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
return controller.createNewTaskForEdit(); return controller.createNewTaskForEdit();
} }
/* /* ======================================================================
* ======================================================================
* =============================================== model reading / saving * =============================================== model reading / saving
* ====================================================================== * ====================================================================== */
*/
/** Populate UI component values from the model */ /** Populate UI component values from the model */
private void populateFields() { private void populateFields() {
@ -216,8 +214,10 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
if(model.getName().length() > 0) if(model.getName().length() > 0)
setTitle(new StringBuilder().append(r.getString(R.string.taskEdit_titlePrefix)).append(" ").append( setTitle(new StringBuilder().
model.getName())); append(r.getString(R.string.taskEdit_titlePrefix)).
append(" ").
append(model.getName()));
estimatedDuration.setTimeDuration(model.getEstimatedSeconds()); estimatedDuration.setTimeDuration(model.getEstimatedSeconds());
elapsedDuration.setTimeDuration(model.getElapsedSeconds()); elapsedDuration.setTimeDuration(model.getElapsedSeconds());
importance.setImportance(model.getImportance()); importance.setImportance(model.getImportance());
@ -241,7 +241,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
if(model.getTaskIdentifier() != null) { if(model.getTaskIdentifier() != null) {
taskTags = tagController.getTaskTags(model.getTaskIdentifier()); taskTags = tagController.getTaskTags(model.getTaskIdentifier());
if(taskTags.size() > 0) { if(taskTags.size() > 0) {
Map<TagIdentifier, TagModelForView> tagsMap = new HashMap<TagIdentifier, TagModelForView>(); Map<TagIdentifier, TagModelForView> tagsMap =
new HashMap<TagIdentifier, TagModelForView>();
for(TagModelForView tag : tags) for(TagModelForView tag : tags)
tagsMap.put(tag.getTagIdentifier(), tag); tagsMap.put(tag.getTagIdentifier(), tag);
for(TagIdentifier id : taskTags) { for(TagIdentifier id : taskTags) {
@ -326,11 +327,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
/** /**
* Displays a Toast reporting that the selected task has been saved and is * Displays a Toast reporting that the selected task has been saved and is
* due in 'x' amount of time, to 2 time-units of precision (e.g. Days + * due in 'x' amount of time, to 2 time-units of precision (e.g. Days + Hours).
* Hours). * @param dueDate the Date when the task is due
*
* @param dueDate
* the Date when the task is due
*/ */
private void showSaveToast(Date dueDate) { private void showSaveToast(Date dueDate) {
int stringResource; int stringResource;
@ -338,19 +336,20 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
int timeInSeconds = (int)((dueDate.getTime() - System.currentTimeMillis())/1000L); int timeInSeconds = (int)((dueDate.getTime() - System.currentTimeMillis())/1000L);
if (timeInSeconds < 0) { if (timeInSeconds < 0) {
timeInSeconds *= -1; // DateUtilities.getDurationString() requires timeInSeconds *= -1; // DateUtilities.getDurationString() requires positive integer
// positive integer
stringResource = R.string.taskEdit_onTaskSave_Overdue; stringResource = R.string.taskEdit_onTaskSave_Overdue;
} else { } else {
stringResource = R.string.taskEdit_onTaskSave_Due; stringResource = R.string.taskEdit_onTaskSave_Due;
} }
String formattedDate = DateUtilities.getDurationString(getResources(), timeInSeconds, 2); String formattedDate = DateUtilities.getDurationString(getResources(), timeInSeconds, 2);
Toast.makeText(this, getResources().getString(stringResource, formattedDate), Toast.LENGTH_SHORT).show(); Toast.makeText(this,
getResources().getString(stringResource, formattedDate),
Toast.LENGTH_SHORT).show();
} }
/** /**
* Displays a Toast reporting that the selected task has been saved. Use * Displays a Toast reporting that the selected task has been saved.
* this version when no due Date has been set. * Use this version when no due Date has been set.
*/ */
private void showSaveToast() { private void showSaveToast() {
Toast.makeText(this, R.string.taskEdit_onTaskSave_notDue, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.taskEdit_onTaskSave_notDue, Toast.LENGTH_SHORT).show();
@ -404,48 +403,53 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
alertController.removeAlerts(model.getTaskIdentifier()); alertController.removeAlerts(model.getTaskIdentifier());
for(int i = 0; i < alertsContainer.getChildCount(); i++) { for(int i = 0; i < alertsContainer.getChildCount(); i++) {
DateControlSet dateControlSet = (DateControlSet) alertsContainer.getChildAt(i).getTag(); DateControlSet dateControlSet = (DateControlSet)alertsContainer.
getChildAt(i).getTag();
Date date = dateControlSet.getDate(); Date date = dateControlSet.getDate();
alertController.addAlert(model.getTaskIdentifier(), date); alertController.addAlert(model.getTaskIdentifier(), date);
} }
} }
/* /* ======================================================================
* ======================================================================
* ==================================================== UI initialization * ==================================================== UI initialization
* ====================================================================== * ====================================================================== */
*/
/** Initialize UI components */ /** Initialize UI components */
private void setUpUIComponents() { private void setUpUIComponents() {
Resources r = getResources(); Resources r = getResources();
setTitle(new StringBuilder().append(r.getString(R.string.taskEdit_titleGeneric))); setTitle(new StringBuilder()
.append(r.getString(R.string.taskEdit_titleGeneric)));
// populate instance variables // populate instance variables
name = (EditText)findViewById(R.id.name); name = (EditText)findViewById(R.id.name);
importance = new ImportanceControlSet(R.id.importance_container); importance = new ImportanceControlSet(R.id.importance_container);
tagsContainer = (LinearLayout)findViewById(R.id.tags_container); tagsContainer = (LinearLayout)findViewById(R.id.tags_container);
estimatedDuration = new TimeDurationControlSet(this, R.id.estimatedDuration, 0, R.string.hour_minutes_dialog, estimatedDuration = new TimeDurationControlSet(this,
R.id.estimatedDuration, 0, R.string.hour_minutes_dialog,
TimeDurationType.HOURS_MINUTES); TimeDurationType.HOURS_MINUTES);
elapsedDuration = new TimeDurationControlSet(this, R.id.elapsedDuration, 0, R.string.hour_minutes_dialog, elapsedDuration = new TimeDurationControlSet(this, R.id.elapsedDuration,
0, R.string.hour_minutes_dialog,
TimeDurationType.HOURS_MINUTES); TimeDurationType.HOURS_MINUTES);
notification = new TimeDurationControlSet(this, R.id.notification, R.string.notification_prefix, notification = new TimeDurationControlSet(this, R.id.notification,
R.string.notification_dialog, TimeDurationType.DAYS_HOURS); R.string.notification_prefix, R.string.notification_dialog,
definiteDueDate = new DateWithNullControlSet(this, R.id.definiteDueDate_notnull, R.id.definiteDueDate_date, TimeDurationType.DAYS_HOURS);
R.id.definiteDueDate_time); definiteDueDate = new DateWithNullControlSet(this, R.id.definiteDueDate_notnull,
preferredDueDate = new DateWithNullControlSet(this, R.id.preferredDueDate_notnull, R.id.preferredDueDate_date, R.id.definiteDueDate_date, R.id.definiteDueDate_time);
R.id.preferredDueDate_time); preferredDueDate = new DateWithNullControlSet(this, R.id.preferredDueDate_notnull,
hiddenUntil = new DateWithNullControlSet(this, R.id.hiddenUntil_notnull, R.id.hiddenUntil_date, R.id.preferredDueDate_date, R.id.preferredDueDate_time);
R.id.hiddenUntil_time); hiddenUntil = new DateWithNullControlSet(this, R.id.hiddenUntil_notnull,
R.id.hiddenUntil_date, R.id.hiddenUntil_time);
notes = (EditText)findViewById(R.id.notes); notes = (EditText)findViewById(R.id.notes);
flags = new NotifyFlagControlSet(R.id.flag_before, R.id.flag_during, R.id.flag_after, R.id.flag_nonstop); flags = new NotifyFlagControlSet(R.id.flag_before,
R.id.flag_during, R.id.flag_after, R.id.flag_nonstop);
alertsContainer = (LinearLayout)findViewById(R.id.alert_container); alertsContainer = (LinearLayout)findViewById(R.id.alert_container);
repeatInterval = (Spinner)findViewById(R.id.repeat_interval); repeatInterval = (Spinner)findViewById(R.id.repeat_interval);
repeatValue = (Button)findViewById(R.id.repeat_value); repeatValue = (Button)findViewById(R.id.repeat_value);
addToCalendar = (CheckBox)findViewById(R.id.add_to_calendar); addToCalendar = (CheckBox)findViewById(R.id.add_to_calendar);
// individual ui component initialization // individual ui component initialization
ArrayAdapter<String> repeatAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ArrayAdapter<String> repeatAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item,
RepeatInterval.getLabels(getResources())); RepeatInterval.getLabels(getResources()));
repeatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); repeatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
repeatInterval.setAdapter(repeatAdapter); repeatInterval.setAdapter(repeatAdapter);
@ -510,8 +514,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private RepeatInfo getRepeatValue() { private RepeatInfo getRepeatValue() {
if(repeatValue.getTag().equals(0)) if(repeatValue.getTag().equals(0))
return null; return null;
return new RepeatInfo(RepeatInterval.values()[repeatInterval.getSelectedItemPosition()], (Integer) repeatValue return new RepeatInfo(RepeatInterval.values()
.getTag()); [repeatInterval.getSelectedItemPosition()],
(Integer)repeatValue.getTag());
} }
/** Adds an alert to the alert field */ /** Adds an alert to the alert field */
@ -523,8 +528,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
final View alertItem = inflater.inflate(R.layout.edit_alert_item, null); final View alertItem = inflater.inflate(R.layout.edit_alert_item, null);
alertsContainer.addView(alertItem); alertsContainer.addView(alertItem);
DateControlSet dcs = new DateControlSet(this, (Button) alertItem.findViewById(R.id.date), (Button) alertItem DateControlSet dcs = new DateControlSet(this,
.findViewById(R.id.time)); (Button)alertItem.findViewById(R.id.date),
(Button)alertItem.findViewById(R.id.time));
dcs.setDate(alert); dcs.setDate(alert);
alertItem.setTag(dcs); alertItem.setTag(dcs);
@ -549,14 +555,18 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
final View tagItem = inflater.inflate(R.layout.edit_tag_item, null); final View tagItem = inflater.inflate(R.layout.edit_tag_item, null);
tagsContainer.addView(tagItem); tagsContainer.addView(tagItem);
AutoCompleteTextView textView = (AutoCompleteTextView) tagItem.findViewById(R.id.text1); AutoCompleteTextView textView = (AutoCompleteTextView)tagItem.
findViewById(R.id.text1);
textView.setText(tagName); textView.setText(tagName);
ArrayAdapter<TagModelForView> tagsAdapter = new ArrayAdapter<TagModelForView>(this, ArrayAdapter<TagModelForView> tagsAdapter =
new ArrayAdapter<TagModelForView>(this,
android.R.layout.simple_dropdown_item_1line, tags); android.R.layout.simple_dropdown_item_1line, tags);
textView.setAdapter(tagsAdapter); textView.setAdapter(tagsAdapter);
textView.addTextChangedListener(new TextWatcher() { textView.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before,
if (start == 0 && tagsContainer.getChildAt(tagsContainer.getChildCount() - 1) == tagItem) { int count) {
if(start == 0 && tagsContainer.getChildAt(
tagsContainer.getChildCount()-1) == tagItem) {
addTag(""); addTag("");
} }
} }
@ -565,7 +575,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
// //
} }
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// //
} }
}); });
@ -581,11 +592,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
return true; return true;
} }
/* /* ======================================================================
* ======================================================================
* ======================================================= event handlers * ======================================================= event handlers
* ====================================================================== * ====================================================================== */
*/
@Override @Override
public void onWindowFocusChanged(boolean hasFocus) { public void onWindowFocusChanged(boolean hasFocus) {
@ -608,8 +617,11 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
private void deleteButtonClick() { private void deleteButtonClick() {
new AlertDialog.Builder(this).setTitle(R.string.delete_title).setMessage(R.string.delete_this_task_title) new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(android.R.string.ok, .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() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// tell the task list to update itself // tell the task list to update itself
@ -620,7 +632,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
setResult(Constants.RESULT_GO_HOME); setResult(Constants.RESULT_GO_HOME);
finish(); finish();
} }
}).setNegativeButton(android.R.string.cancel, null).show(); })
.setNegativeButton(android.R.string.cancel, null)
.show();
} }
private void repeatValueClick() { private void repeatValueClick() {
@ -640,7 +654,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
public void onNumberPicked(NumberPicker view, int number) { public void onNumberPicked(NumberPicker view, int number) {
setRepeatValue(number); setRepeatValue(number);
} }
}, getResources().getString(R.string.repeat_picker_title), dialogValue, 1, 0, 31).show(); }, getResources().getString(R.string.repeat_picker_title),
dialogValue, 1, 0, 31).show();
} }
}; };
@ -649,18 +664,24 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
return; return;
} }
new AlertDialog.Builder(this).setTitle(R.string.repeat_help_dialog_title).setMessage( new AlertDialog.Builder(this)
R.string.repeat_help_dialog).setIcon(android.R.drawable.ic_dialog_info).setPositiveButton( .setTitle(R.string.repeat_help_dialog_title)
android.R.string.ok, new DialogInterface.OnClickListener() { .setMessage(R.string.repeat_help_dialog)
.setIcon(android.R.drawable.ic_dialog_info)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
openDialogRunnable.run(); openDialogRunnable.run();
} }
}).setNeutralButton(R.string.repeat_help_hide, new DialogInterface.OnClickListener() { })
.setNeutralButton(R.string.repeat_help_hide,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Preferences.setShowRepeatHelp(TaskEdit.this, false); Preferences.setShowRepeatHelp(TaskEdit.this, false);
openDialogRunnable.run(); openDialogRunnable.run();
} }
}).show(); })
.show();
} }
@Override @Override
@ -709,23 +730,20 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
// save the tag name token for when we rotate the screen // save the tag name token for when we rotate the screen
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if(extras != null && extras.containsKey(TAG_NAME_TOKEN)) if(extras != null && extras.containsKey(TAG_NAME_TOKEN))
outState.putString(TAG_NAME_TOKEN, extras.getString(TAG_NAME_TOKEN)); outState.putString(TAG_NAME_TOKEN,
extras.getString(TAG_NAME_TOKEN));
} }
/** /** Take the values from the model and set the calendar start and end times
* Take the values from the model and set the calendar start and end times
* based on these. Sets keys 'dtstart' and 'dtend'. * based on these. Sets keys 'dtstart' and 'dtend'.
* *
* @param preferred * @param preferred preferred due date or null
* preferred due date or null * @param definite definite due date or null
* @param definite * @param estimatedSeconds estimated duration or null
* definite due date or null
* @param estimatedSeconds
* estimated duration or null
* @param values * @param values
*/ */
public static void createCalendarStartEndTimes(Date preferred, Date definite, Integer estimatedSeconds, public static void createCalendarStartEndTimes(Date preferred, Date definite,
ContentValues values) { Integer estimatedSeconds, ContentValues values) {
FlurryAgent.onEvent("create-calendar-event"); FlurryAgent.onEvent("create-calendar-event");
Long deadlineDate = null; Long deadlineDate = null;
@ -759,8 +777,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
values.put("transparency", 0); values.put("transparency", 0);
values.put("visibility", 0); values.put("visibility", 0);
createCalendarStartEndTimes(model.getPreferredDueDate(), model.getDefiniteDueDate(), model createCalendarStartEndTimes(model.getPreferredDueDate(),
.getEstimatedSeconds(), values); model.getDefiniteDueDate(), model.getEstimatedSeconds(),
values);
Uri result = cr.insert(uri, values); Uri result = cr.insert(uri, values);
if(result != null) if(result != null)
@ -777,8 +796,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Intent intent = new Intent(Intent.ACTION_EDIT, result); Intent intent = new Intent(Intent.ACTION_EDIT, result);
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
createCalendarStartEndTimes(model.getPreferredDueDate(), model.getDefiniteDueDate(), model createCalendarStartEndTimes(model.getPreferredDueDate(),
.getEstimatedSeconds(), values); model.getDefiniteDueDate(), model.getEstimatedSeconds(),
values);
intent.putExtra("beginTime", values.getAsLong("dtstart")); intent.putExtra("beginTime", values.getAsLong("dtstart"));
intent.putExtra("endTime", values.getAsLong("dtend")); intent.putExtra("endTime", values.getAsLong("dtend"));
@ -802,17 +822,16 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
alertController.close(); alertController.close();
} }
/* /* ======================================================================
* ======================================================================
* ========================================== UI component helper classes * ========================================== UI component helper classes
* ====================================================================== * ====================================================================== */
*/
/** Control set dealing with notification flags */ /** Control set dealing with notification flags */
public class NotifyFlagControlSet { public class NotifyFlagControlSet {
private CheckBox before, during, after, nonstop; private CheckBox before, during, after, nonstop;
public NotifyFlagControlSet(int beforeId, int duringId, int afterId, int nonstopId) { public NotifyFlagControlSet(int beforeId, int duringId,
int afterId, int nonstopId) {
before = (CheckBox)findViewById(beforeId); before = (CheckBox)findViewById(beforeId);
during = (CheckBox)findViewById(duringId); during = (CheckBox)findViewById(duringId);
after = (CheckBox)findViewById(afterId); after = (CheckBox)findViewById(afterId);
@ -820,10 +839,14 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
public void setValue(int flags) { public void setValue(int flags) {
before.setChecked((flags & TaskModelForEdit.NOTIFY_BEFORE_DEADLINE) > 0); before.setChecked((flags &
during.setChecked((flags & TaskModelForEdit.NOTIFY_AT_DEADLINE) > 0); TaskModelForEdit.NOTIFY_BEFORE_DEADLINE) > 0);
after.setChecked((flags & TaskModelForEdit.NOTIFY_AFTER_DEADLINE) > 0); during.setChecked((flags &
nonstop.setChecked((flags & TaskModelForEdit.NOTIFY_NONSTOP) > 0); TaskModelForEdit.NOTIFY_AT_DEADLINE) > 0);
after.setChecked((flags &
TaskModelForEdit.NOTIFY_AFTER_DEADLINE) > 0);
nonstop.setChecked((flags &
TaskModelForEdit.NOTIFY_NONSTOP) > 0);
} }
public int getValue() { public int getValue() {
@ -850,8 +873,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
for(Importance i : Importance.values()) { for(Importance i : Importance.values()) {
final ToggleButton button = new ToggleButton(TaskEdit.this); final ToggleButton button = new ToggleButton(TaskEdit.this);
button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, button.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, 1)); LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
button.setTextColor(r.getColor(i.getColorResource())); button.setTextColor(r.getColor(i.getColorResource()));
button.setTextOff(r.getString(i.getLabelResource())); button.setTextOff(r.getString(i.getLabelResource()));
button.setTextOn(r.getString(i.getLabelResource())); button.setTextOn(r.getString(i.getLabelResource()));
@ -900,12 +923,15 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Cursor tasks = controller.getActiveTaskListCursor(); Cursor tasks = controller.getActiveTaskListCursor();
startManagingCursor(tasks); startManagingCursor(tasks);
SimpleCursorAdapter tasksAdapter = new SimpleCursorAdapter(TaskEdit.this, SimpleCursorAdapter tasksAdapter = new SimpleCursorAdapter(TaskEdit.this,
android.R.layout.simple_list_item_1, tasks, new String[] { TaskModelForList.getNameField() }, android.R.layout.simple_list_item_1, tasks,
new String[] { TaskModelForList.getNameField() },
new int[] { android.R.id.text1 }); new int[] { android.R.id.text1 });
taskBox.setAdapter(tasksAdapter); taskBox.setAdapter(tasksAdapter);
activatedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { activatedCheckBox.setOnCheckedChangeListener(
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
taskBox.setEnabled(isChecked); taskBox.setEnabled(isChecked);
} }
}); });

@ -34,6 +34,7 @@ import com.timsu.astrid.data.tag.AbstractTagModel.TagModelDatabaseHelper;
import com.timsu.astrid.data.tag.TagToTaskMapping.TagToTaskMappingDatabaseHelper; import com.timsu.astrid.data.tag.TagToTaskMapping.TagToTaskMappingDatabaseHelper;
import com.timsu.astrid.data.task.TaskIdentifier; import com.timsu.astrid.data.task.TaskIdentifier;
import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper; import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper;
import com.timsu.astrid.provider.TasksProvider;
/** Controller for Tag-related operations */ /** Controller for Tag-related operations */
public class TagController extends AbstractController { public class TagController extends AbstractController {
@ -247,8 +248,13 @@ public class TagController extends AbstractController {
TagToTaskMapping.TAG + " = " + tagId.idAsString(), null) < 0) TagToTaskMapping.TAG + " = " + tagId.idAsString(), null) < 0)
return false; return false;
return tagDatabase.delete(TAG_TABLE_NAME, int res = tagDatabase.delete(TAG_TABLE_NAME,
KEY_ROWID + " = " + tagId.idAsString(), null) > 0; KEY_ROWID + " = " + tagId.idAsString(), null);
// notify modification
TasksProvider.notifyDatabaseModification();
return res > 0;
} }
// --- single tag to task operations // --- single tag to task operations
@ -256,10 +262,16 @@ public class TagController extends AbstractController {
/** Remove the given tag from the task */ /** Remove the given tag from the task */
public boolean removeTag(TaskIdentifier taskId, TagIdentifier tagId) public boolean removeTag(TaskIdentifier taskId, TagIdentifier tagId)
throws SQLException{ throws SQLException{
return tagToTaskMapDatabase.delete(TAG_TASK_MAP_NAME,
int res = tagToTaskMapDatabase.delete(TAG_TASK_MAP_NAME,
String.format("%s = ? AND %s = ?", String.format("%s = ? AND %s = ?",
TagToTaskMapping.TAG, TagToTaskMapping.TASK), TagToTaskMapping.TAG, TagToTaskMapping.TASK),
new String[] { tagId.idAsString(), taskId.idAsString() }) > 0; new String[] { tagId.idAsString(), taskId.idAsString() });
// notify modification
TasksProvider.notifyDatabaseModification();
return res > 0;
} }
/** Add the given tag to the task */ /** Add the given tag to the task */
@ -268,8 +280,14 @@ public class TagController extends AbstractController {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(TagToTaskMapping.TAG, tagId.getId()); values.put(TagToTaskMapping.TAG, tagId.getId());
values.put(TagToTaskMapping.TASK, taskId.getId()); values.put(TagToTaskMapping.TASK, taskId.getId());
return tagToTaskMapDatabase.insert(TAG_TASK_MAP_NAME, TagToTaskMapping.TAG,
values) >= 0; long res = tagToTaskMapDatabase.insert(TAG_TASK_MAP_NAME, TagToTaskMapping.TAG,
values);
// notify modification
TasksProvider.notifyDatabaseModification();
return res >= 0;
} }
// --- boilerplate // --- boilerplate

@ -1,6 +1,7 @@
package com.timsu.astrid.provider; package com.timsu.astrid.provider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentValues; import android.content.ContentValues;
@ -11,7 +12,9 @@ import android.database.MatrixCursor;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import com.timsu.astrid.data.task.AbstractTaskModel; import com.timsu.astrid.data.tag.TagController;
import com.timsu.astrid.data.tag.TagIdentifier;
import com.timsu.astrid.data.tag.TagModelForView;
import com.timsu.astrid.data.task.TaskController; import com.timsu.astrid.data.task.TaskController;
import com.timsu.astrid.data.task.TaskModelForProvider; import com.timsu.astrid.data.task.TaskModelForProvider;
@ -19,86 +22,49 @@ public class TasksProvider extends ContentProvider {
private static final String TAG = "MessageProvider"; private static final String TAG = "MessageProvider";
private static final boolean LOGD = false;
public static final String AUTHORITY = "com.timsu.astrid.tasksprovider"; public static final String AUTHORITY = "com.timsu.astrid.tasksprovider";
public static final Uri CONTENT_URI = Uri.parse("content://com.timsu.astrid.tasksprovider"); public static final Uri CONTENT_URI = Uri.parse("content://com.timsu.astrid.tasksprovider");
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
private static final int MAX_NUMBEER_OF_TASKS = 20; private static final int MAX_NUMBEER_OF_TASKS = 30;
private final static String NAME = "name";
private final static String IMPORTANCE_COLOR = "importance_color"; private final static String IMPORTANCE_COLOR = "importance_color";
private final static String IDENTIFIER = "identifier"; private final static String IDENTIFIER = "identifier";
private final static String PREFERRED_DUE_DATE = "preferredDueDate";
private final static String DEFINITE_DUE_DATE = "definiteDueDate";
private final static String IMPORTANCE = "importance";
private final static String ID = "id";
private final static String TAGS_ID = "tags_id";
static String[] TASK_FIELD_LIST = new String[] { AbstractTaskModel.NAME, IMPORTANCE_COLOR, static String[] TASK_FIELD_LIST = new String[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE,
AbstractTaskModel.PREFERRED_DUE_DATE, AbstractTaskModel.DEFINITE_DUE_DATE, AbstractTaskModel.IMPORTANCE, IDENTIFIER }; IMPORTANCE, IDENTIFIER, TAGS_ID };
static String[] TAGS_FIELD_LIST = new String[] { ID, NAME };
private static final int URI_TASKS = 0; private static final int URI_TASKS = 0;
// private static final int URI_MESSAGES = 1; private static final int URI_TAGS = 1;
// private static final int URI_MESSAGE = 2;
// private static final int URI_FOLDERS = 3; private static final String TAG_SEPARATOR = "|";
private static Context ctx = null; private static Context ctx = null;
static { static {
URI_MATCHER.addURI(AUTHORITY, "tasks", URI_TASKS); URI_MATCHER.addURI(AUTHORITY, "tasks", URI_TASKS);
// URI_MATCHER.addURI(AUTHORITY, "messages/*", URI_MESSAGES); URI_MATCHER.addURI(AUTHORITY, "tags", URI_TAGS);
// URI_MATCHER.addURI(AUTHORITY, "message/*", URI_MESSAGE);
// URI_MATCHER.addURI(AUTHORITY, "folders/*", URI_FOLDERS);
} }
@Override @Override
public int delete(Uri uri, String selection, String[] selectionArgs) { public int delete(Uri uri, String selection, String[] selectionArgs) {
if (LOGD)
Log.d(TAG, "delete"); Log.d(TAG, "delete");
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// can only delete a message
// List<String> segments = null;
// String emailAccount = null;
// String msgId = null;
// String msgUId = null;
//
// segments = uri.getPathSegments();
// emailAccount = segments.get(1);
// msgId = segments.get(2);
//
//
// openOrReopenDatabase(emailAccount);
//
// // get messages uid
// Cursor cursor = null;
// try {
// cursor = getAllMessages(null, "( id = " + msgId + " )", null, null);
// if (cursor != null) {
// cursor.moveToFirst();
// msgUId = cursor.getString(cursor.getColumnIndex("uid"));
// cursor.close();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // get localstore parameter
// Message msg = null;
// try {
// Folder lf = LocalStore.getInstance(myAccount.getLocalStoreUri(),
// mApp, null).getFolder("INBOX");
// int msgCount = lf.getMessageCount();
// Log.d(TAG, "folder msg count = " + msgCount);
// msg = lf.getMessage(msgUId);
// } catch (MessagingException e) {
// e.printStackTrace();
// }
//
// // launch command to delete the message
// if ((myAccount != null) && (msg != null)) {
// MessagingController.getInstance(mApp).deleteMessage(myAccount,
// "INBOX", msg, null);
// }
//
// notifyDatabaseModification();
return 0; return 0;
} }
@ -120,15 +86,24 @@ public class TasksProvider extends ContentProvider {
public Cursor getTags() { public Cursor getTags() {
// TaskController taskController = new TaskController(ctx); LinkedList<TagModelForView> tags = null;
// taskController.ge
//
// MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST);
//
// for (int i = 0; i < taskList.size(); i++) {
// }
return null; TagController tagController = new TagController(ctx);
tagController.open();
tags = tagController.getAllTags();
tagController.close();
MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST);
for (int i = 0; i < tags.size(); i++) {
Object[] values = new Object[2];
values[0] = tags.get(i).getTagIdentifier().getId();
values[1] = tags.get(i).getName();
ret.addRow(values);
}
return ret;
} }
public Cursor getTasks() { public Cursor getTasks() {
@ -157,13 +132,28 @@ public class TasksProvider extends ContentProvider {
if (taskModel.getDefiniteDueDate() != null) if (taskModel.getDefiniteDueDate() != null)
definiteDueDate = taskModel.getDefiniteDueDate().getTime(); definiteDueDate = taskModel.getDefiniteDueDate().getTime();
Object[] values = new Object[6]; // get tags for task
LinkedList<TagIdentifier> tags = null;
TagController tagController = new TagController(ctx);
tagController.open();
tags = tagController.getTaskTags(taskModel.getTaskIdentifier());
String taskTags = "";
for (TagIdentifier tag : tags) {
if (taskTags.equals(""))
taskTags = Long.toString(tag.getId());
else
taskTags = taskTags + TAG_SEPARATOR + Long.toString(tag.getId());
}
tagController.close();
Object[] values = new Object[7];
values[0] = taskModel.getName(); values[0] = taskModel.getName();
values[1] = ctx.getResources().getColor(taskModel.getImportance().getColorResource()); values[1] = ctx.getResources().getColor(taskModel.getImportance().getColorResource());
values[2] = preferredDueDateTime; values[2] = preferredDueDateTime;
values[3] = definiteDueDate; values[3] = definiteDueDate;
values[4] = taskModel.getImportance().ordinal(); values[4] = taskModel.getImportance().ordinal();
values[5] = taskModel.getTaskIdentifier().getId(); values[5] = taskModel.getTaskIdentifier().getId();
values[6] = taskTags;
ret.addRow(values); ret.addRow(values);
@ -176,32 +166,19 @@ public class TasksProvider extends ContentProvider {
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (LOGD)
Log.d(TAG, "query"); Log.d(TAG, "query");
Cursor cursor; Cursor cursor;
switch (URI_MATCHER.match(uri)) { switch (URI_MATCHER.match(uri)) {
// case URI_MESSAGES:
// segments = uri.getPathSegments();
// emailAccount = segments.get(1);
//
// openOrReopenDatabase(emailAccount);
//
// cursor = getAllMessages(projection, selection, selectionArgs,
// sortOrder);
// break;
case URI_TASKS: case URI_TASKS:
cursor = getTasks(); cursor = getTasks();
break; break;
// case URI_FOLDERS: case URI_TAGS:
// segments = uri.getPathSegments(); cursor = getTags();
// emailAccount = segments.get(1); break;
//
// openOrReopenDatabase(emailAccount);
//
// cursor = getFolders(projection, selection, selectionArgs, sortOrder);
// break;
default: default:
throw new IllegalStateException("Unrecognized URI:" + uri); throw new IllegalStateException("Unrecognized URI:" + uri);
@ -210,93 +187,19 @@ public class TasksProvider extends ContentProvider {
return cursor; return cursor;
} }
// private void openOrReopenDatabase(String emailAccount) {
//
// String dbPath = null;
//
// if ((!emailAccount.equals(mCurrentEmailAccount)) || (mDb == null)) {
//
// // look at existing accounts
// for (Account account :
// Preferences.getPreferences(getContext()).getAccounts()) {
// if (account.getEmail().equals(emailAccount)) {
// dbPath = account.getLocalStoreUri();
// }
// }
//
// if (dbPath != null) {
//
// // save this account as current account
// mCurrentEmailAccount = emailAccount;
//
// // close old database
// if (mDb != null)
// mDb.close();
//
// // open database
// String path = Uri.parse(dbPath).getPath();
// mDb = SQLiteDatabase.openDatabase(path, null,
// SQLiteDatabase.OPEN_READONLY);
// }
// }
//
// }
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (LOGD)
Log.d(TAG, "update"); Log.d(TAG, "update");
// // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// // can only set flag to 'SEEN'
//
// List<String> segments = null;
// String emailAccount = null;
// String msgId = null;
// String msgUId = null;
//
// segments = uri.getPathSegments();
// emailAccount = segments.get(1);
// msgId = segments.get(2);
//
// openOrReopenDatabase(emailAccount);
//
// // get account parameters
// Account myAccount = null;
// for (Account account :
// Preferences.getPreferences(getContext()).getAccounts()) {
// if (emailAccount.equals(account.getEmail())) {
// myAccount = account;
// }
// }
//
// // get messages uid
// Cursor cursor = null;
// try {
// cursor = getAllMessages(null, "( id = " + msgId + " )", null, null);
// if (cursor != null) {
// cursor.moveToFirst();
// msgUId = cursor.getString(cursor.getColumnIndex("uid"));
// cursor.close();
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // launch command to delete the message
// if ((myAccount != null) && (msgUId != null)) {
// MessagingController.getInstance(mApp).markMessageRead(myAccount,
// "INBOX", msgUId, true);
// }
//
// notifyDatabaseModification();
return 0; return 0;
} }
public static void notifyDatabaseModification() { public static void notifyDatabaseModification() {
Log.d(TAG, "UPDATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); if (LOGD)
Log.d(TAG, "notifyDatabaseModification");
ctx.getContentResolver().notifyChange(CONTENT_URI, null); ctx.getContentResolver().notifyChange(CONTENT_URI, null);

Loading…
Cancel
Save