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,32 +192,32 @@ 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() {
Resources r = getResources(); Resources r = getResources();
// set UI components based on model variables // set UI components based on model variables
if (model.getCursor() != null) if(model.getCursor() != null)
startManagingCursor(model.getCursor()); startManagingCursor(model.getCursor());
if (model.getTaskIdentifier() == null) { if(model.getTaskIdentifier() == null) {
FlurryAgent.onEvent("create-task"); FlurryAgent.onEvent("create-task");
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(START_CHAR_TOKEN)) if(extras != null && extras.containsKey(START_CHAR_TOKEN))
name.setText("" + extras.getChar(START_CHAR_TOKEN)); name.setText("" + extras.getChar(START_CHAR_TOKEN));
} else { } else {
FlurryAgent.onEvent("edit-task"); FlurryAgent.onEvent("edit-task");
name.setText(model.getName()); name.setText(model.getName());
} }
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());
@ -227,25 +227,26 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
notification.setTimeDuration(model.getNotificationIntervalSeconds()); notification.setTimeDuration(model.getNotificationIntervalSeconds());
flags.setValue(model.getNotificationFlags()); flags.setValue(model.getNotificationFlags());
notes.setText(model.getNotes()); notes.setText(model.getNotes());
if (model.getTaskIdentifier() == null) { if(model.getTaskIdentifier() == null) {
Integer reminder = Preferences.getDefaultReminder(this); Integer reminder = Preferences.getDefaultReminder(this);
if (reminder != null) if(reminder != null)
notification.setTimeDuration(24 * 3600 * reminder); notification.setTimeDuration(24*3600*reminder);
} }
if (model.getCalendarUri() != null) if(model.getCalendarUri() != null)
addToCalendar.setText(r.getString(R.string.showCalendar_label)); addToCalendar.setText(r.getString(R.string.showCalendar_label));
// tags (only configure if not already set) // tags (only configure if not already set)
if (tagsContainer.getChildCount() == 0) { if(tagsContainer.getChildCount() == 0) {
tags = tagController.getAllTags(); tags = tagController.getAllTags();
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 =
for (TagModelForView tag : tags) new HashMap<TagIdentifier, TagModelForView>();
for(TagModelForView tag : tags)
tagsMap.put(tag.getTagIdentifier(), tag); tagsMap.put(tag.getTagIdentifier(), tag);
for (TagIdentifier id : taskTags) { for(TagIdentifier id : taskTags) {
if (!tagsMap.containsKey(id)) if(!tagsMap.containsKey(id))
continue; continue;
TagModelForView tag = tagsMap.get(id); TagModelForView tag = tagsMap.get(id);
@ -256,7 +257,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
taskTags = new LinkedList<TagIdentifier>(); taskTags = new LinkedList<TagIdentifier>();
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(TAG_NAME_TOKEN)) { if(extras != null && extras.containsKey(TAG_NAME_TOKEN)) {
addTag(extras.getString(TAG_NAME_TOKEN)); addTag(extras.getString(TAG_NAME_TOKEN));
} }
} }
@ -264,16 +265,16 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
// alerts // alerts
if (model.getTaskIdentifier() != null) { if(model.getTaskIdentifier() != null) {
List<Date> alerts = alertController.getTaskAlerts(model.getTaskIdentifier()); List<Date> alerts = alertController.getTaskAlerts(model.getTaskIdentifier());
for (Date alert : alerts) { for(Date alert : alerts) {
addAlert(alert); addAlert(alert);
} }
} }
// repeats // repeats
RepeatInfo repeatInfo = model.getRepeat(); RepeatInfo repeatInfo = model.getRepeat();
if (repeatInfo != null) { if(repeatInfo != null) {
setRepeatValue(repeatInfo.getValue()); setRepeatValue(repeatInfo.getValue());
repeatInterval.setSelection(repeatInfo.getInterval().ordinal()); repeatInterval.setSelection(repeatInfo.getInterval().ordinal());
} else } else
@ -284,7 +285,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
/** Save task model from values in UI components */ /** Save task model from values in UI components */
private void save() { private void save() {
// don't save if user accidentally created a new task // don't save if user accidentally created a new task
if (name.getText().length() == 0) if(name.getText().length() == 0)
return; return;
// tell the task list to update itself // tell the task list to update itself
@ -326,31 +327,29 @@ 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;
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();
@ -362,9 +361,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Set<TagIdentifier> tagsToAdd; Set<TagIdentifier> tagsToAdd;
HashSet<String> tagNames = new HashSet<String>(); HashSet<String> tagNames = new HashSet<String>();
for (int i = 0; i < tagsContainer.getChildCount(); i++) { for(int i = 0; i < tagsContainer.getChildCount(); i++) {
TextView tagName = (TextView) tagsContainer.getChildAt(i).findViewById(R.id.text1); TextView tagName = (TextView)tagsContainer.getChildAt(i).findViewById(R.id.text1);
if (tagName.getText().length() == 0) if(tagName.getText().length() == 0)
continue; continue;
tagNames.add(tagName.getText().toString()); tagNames.add(tagName.getText().toString());
} }
@ -372,10 +371,10 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
// map names to tag identifiers, creating them if necessary // map names to tag identifiers, creating them if necessary
HashSet<TagIdentifier> tagIds = new HashSet<TagIdentifier>(); HashSet<TagIdentifier> tagIds = new HashSet<TagIdentifier>();
HashMap<String, TagIdentifier> tagsByName = new HashMap<String, TagIdentifier>(); HashMap<String, TagIdentifier> tagsByName = new HashMap<String, TagIdentifier>();
for (TagModelForView tag : tags) for(TagModelForView tag : tags)
tagsByName.put(tag.getName(), tag.getTagIdentifier()); tagsByName.put(tag.getName(), tag.getTagIdentifier());
for (String tagName : tagNames) { for(String tagName : tagNames) {
if (tagsByName.containsKey(tagName)) if(tagsByName.containsKey(tagName))
tagIds.add(tagsByName.get(tagName)); tagIds.add(tagsByName.get(tagName));
else { else {
TagIdentifier newTagId = tagController.createTag(tagName); TagIdentifier newTagId = tagController.createTag(tagName);
@ -390,12 +389,12 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
tagsToAdd.removeAll(taskTags); tagsToAdd.removeAll(taskTags);
// perform the database updates // perform the database updates
for (TagIdentifier tagId : tagsToDelete) for(TagIdentifier tagId : tagsToDelete)
tagController.removeTag(model.getTaskIdentifier(), tagId); tagController.removeTag(model.getTaskIdentifier(), tagId);
for (TagIdentifier tagId : tagsToAdd) for(TagIdentifier tagId : tagsToAdd)
tagController.addTag(model.getTaskIdentifier(), tagId); tagController.addTag(model.getTaskIdentifier(), tagId);
if (tagsToDelete.size() > 0 || tagsToAdd.size() > 0) if(tagsToDelete.size() > 0 || tagsToAdd.size() > 0)
SyncDataController.taskUpdated(this, model); SyncDataController.taskUpdated(this, model);
} }
@ -403,49 +402,54 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private void saveAlerts() { private void saveAlerts() {
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,
notes = (EditText) findViewById(R.id.notes); R.id.hiddenUntil_date, R.id.hiddenUntil_time);
flags = new NotifyFlagControlSet(R.id.flag_before, R.id.flag_during, R.id.flag_after, R.id.flag_nonstop); notes = (EditText)findViewById(R.id.notes);
alertsContainer = (LinearLayout) findViewById(R.id.alert_container); flags = new NotifyFlagControlSet(R.id.flag_before,
repeatInterval = (Spinner) findViewById(R.id.repeat_interval); R.id.flag_during, R.id.flag_after, R.id.flag_nonstop);
repeatValue = (Button) findViewById(R.id.repeat_value); alertsContainer = (LinearLayout)findViewById(R.id.alert_container);
addToCalendar = (CheckBox) findViewById(R.id.add_to_calendar); repeatInterval = (Spinner)findViewById(R.id.repeat_interval);
repeatValue = (Button)findViewById(R.id.repeat_value);
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);
@ -474,7 +478,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Button deleteButtonGeneral = (Button) findViewById(R.id.delete_general); Button deleteButtonGeneral = (Button) findViewById(R.id.delete_general);
Button deleteButtonDates = (Button) findViewById(R.id.delete_dates); Button deleteButtonDates = (Button) findViewById(R.id.delete_dates);
Button deleteButtonNotify = (Button) findViewById(R.id.delete_notify); Button deleteButtonNotify = (Button) findViewById(R.id.delete_notify);
if (model.getTaskIdentifier() == null) { if(model.getTaskIdentifier() == null) {
deleteButtonGeneral.setVisibility(View.GONE); deleteButtonGeneral.setVisibility(View.GONE);
deleteButtonDates.setVisibility(View.GONE); deleteButtonDates.setVisibility(View.GONE);
deleteButtonNotify.setVisibility(View.GONE); deleteButtonNotify.setVisibility(View.GONE);
@ -500,7 +504,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
/** Set up the repeat value button */ /** Set up the repeat value button */
private void setRepeatValue(int value) { private void setRepeatValue(int value) {
if (value == 0) if(value == 0)
repeatValue.setText(R.string.repeat_value_unset); repeatValue.setText(R.string.repeat_value_unset);
else else
repeatValue.setText(Integer.toString(value)); repeatValue.setText(Integer.toString(value));
@ -508,28 +512,30 @@ 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 */
private boolean addAlert(Date alert) { private boolean addAlert(Date alert) {
if (alertsContainer.getChildCount() >= MAX_ALERTS) if(alertsContainer.getChildCount() >= MAX_ALERTS)
return false; return false;
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
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);
ImageButton reminderRemoveButton; ImageButton reminderRemoveButton;
reminderRemoveButton = (ImageButton) alertItem.findViewById(R.id.button1); reminderRemoveButton = (ImageButton)alertItem.findViewById(R.id.button1);
reminderRemoveButton.setOnClickListener(new View.OnClickListener() { reminderRemoveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
alertsContainer.removeView(alertItem); alertsContainer.removeView(alertItem);
@ -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,13 +575,14 @@ 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) {
// //
} }
}); });
ImageButton reminderRemoveButton; ImageButton reminderRemoveButton;
reminderRemoveButton = (ImageButton) tagItem.findViewById(R.id.button1); reminderRemoveButton = (ImageButton)tagItem.findViewById(R.id.button1);
reminderRemoveButton.setOnClickListener(new View.OnClickListener() { reminderRemoveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
tagsContainer.removeView(tagItem); tagsContainer.removeView(tagItem);
@ -581,17 +592,15 @@ 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) {
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
if (hasFocus && TaskList.shouldCloseInstance) { // user wants to quit if(hasFocus && TaskList.shouldCloseInstance) { // user wants to quit
finish(); finish();
} }
} }
@ -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,12 +632,14 @@ 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() {
final int tagValue = (Integer) repeatValue.getTag(); final int tagValue = (Integer)repeatValue.getTag();
if (tagValue > 0) if(tagValue > 0)
repeatHelpShown = true; repeatHelpShown = true;
final Runnable openDialogRunnable = new Runnable() { final Runnable openDialogRunnable = new Runnable() {
@ -633,39 +647,46 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
repeatHelpShown = true; repeatHelpShown = true;
int dialogValue = tagValue; int dialogValue = tagValue;
if (dialogValue == 0) if(dialogValue == 0)
dialogValue = 1; dialogValue = 1;
new NumberPickerDialog(TaskEdit.this, new OnNumberPickedListener() { new NumberPickerDialog(TaskEdit.this, new OnNumberPickedListener() {
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();
} }
}; };
if (repeatHelpShown || !Preferences.shouldShowRepeatHelp(this)) { if(repeatHelpShown || !Preferences.shouldShowRepeatHelp(this)) {
openDialogRunnable.run(); openDialogRunnable.run();
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
public boolean onMenuItemSelected(int featureId, MenuItem item) { public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) { switch(item.getItemId()) {
case SAVE_ID: case SAVE_ID:
saveButtonClick(); saveButtonClick();
return true; return true;
@ -708,24 +729,21 @@ 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;
@ -734,10 +752,10 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
else if (definite != null) else if (definite != null)
deadlineDate = definite.getTime(); deadlineDate = definite.getTime();
else else
deadlineDate = System.currentTimeMillis() + 24 * 3600 * 1000L; deadlineDate = System.currentTimeMillis() + 24*3600*1000L;
int estimatedTime = DEFAULT_CAL_TIME; int estimatedTime = DEFAULT_CAL_TIME;
if (estimatedSeconds != null && estimatedSeconds > 0) { if(estimatedSeconds != null && estimatedSeconds > 0) {
estimatedTime = estimatedSeconds; estimatedTime = estimatedSeconds;
} }
values.put("dtstart", deadlineDate - estimatedTime * 1000L); values.put("dtstart", deadlineDate - estimatedTime * 1000L);
@ -747,7 +765,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
@Override @Override
protected void onPause() { protected void onPause() {
// create calendar event // create calendar event
if (addToCalendar.isChecked() && model.getCalendarUri() == null) { if(addToCalendar.isChecked() && model.getCalendarUri() == null) {
Uri uri = Uri.parse("content://calendar/events"); Uri uri = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver(); ContentResolver cr = getContentResolver();
@ -759,26 +777,28 @@ 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)
model.setCalendarUri(result.toString()); model.setCalendarUri(result.toString());
else else
Log.e("astrid", "Error creating calendar event!"); Log.e("astrid", "Error creating calendar event!");
} }
if (shouldSaveState) if(shouldSaveState)
save(); save();
if (addToCalendar.isChecked() && model.getCalendarUri() != null) { if(addToCalendar.isChecked() && model.getCalendarUri() != null) {
Uri result = Uri.parse(model.getCalendarUri()); Uri result = Uri.parse(model.getCalendarUri());
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,39 +822,42 @@ 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,
before = (CheckBox) findViewById(beforeId); int afterId, int nonstopId) {
during = (CheckBox) findViewById(duringId); before = (CheckBox)findViewById(beforeId);
after = (CheckBox) findViewById(afterId); during = (CheckBox)findViewById(duringId);
nonstop = (CheckBox) findViewById(nonstopId); after = (CheckBox)findViewById(afterId);
nonstop = (CheckBox)findViewById(nonstopId);
} }
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() {
int value = 0; int value = 0;
if (before.isChecked()) if(before.isChecked())
value |= TaskModelForEdit.NOTIFY_BEFORE_DEADLINE; value |= TaskModelForEdit.NOTIFY_BEFORE_DEADLINE;
if (during.isChecked()) if(during.isChecked())
value |= TaskModelForEdit.NOTIFY_AT_DEADLINE; value |= TaskModelForEdit.NOTIFY_AT_DEADLINE;
if (after.isChecked()) if(after.isChecked())
value |= TaskModelForEdit.NOTIFY_AFTER_DEADLINE; value |= TaskModelForEdit.NOTIFY_AFTER_DEADLINE;
if (nonstop.isChecked()) if(nonstop.isChecked())
value |= TaskModelForEdit.NOTIFY_NONSTOP; value |= TaskModelForEdit.NOTIFY_NONSTOP;
return value; return value;
} }
@ -845,19 +868,19 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private List<CompoundButton> buttons = new LinkedList<CompoundButton>(); private List<CompoundButton> buttons = new LinkedList<CompoundButton>();
public ImportanceControlSet(int containerId) { public ImportanceControlSet(int containerId) {
LinearLayout layout = (LinearLayout) findViewById(containerId); LinearLayout layout = (LinearLayout)findViewById(containerId);
Resources r = getResources(); Resources r = getResources();
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()));
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
setImportance((Importance) button.getTag()); setImportance((Importance)button.getTag());
} }
}); });
button.setTag(i); button.setTag(i);
@ -868,8 +891,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
public void setImportance(Importance i) { public void setImportance(Importance i) {
for (CompoundButton b : buttons) { for(CompoundButton b : buttons) {
if (b.getTag() == i) { if(b.getTag() == i) {
b.setTextSize(24); b.setTextSize(24);
b.setChecked(true); b.setChecked(true);
} else { } else {
@ -880,9 +903,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
public Importance getImportance() { public Importance getImportance() {
for (CompoundButton b : buttons) for(CompoundButton b : buttons)
if (b.isChecked()) if(b.isChecked())
return (Importance) b.getTag(); return (Importance)b.getTag();
return Importance.DEFAULT; return Importance.DEFAULT;
} }
} }
@ -894,18 +917,21 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private Spinner taskBox; private Spinner taskBox;
public BlockingOnControlSet(int checkBoxId, int taskBoxId) { public BlockingOnControlSet(int checkBoxId, int taskBoxId) {
activatedCheckBox = (CheckBox) findViewById(checkBoxId); activatedCheckBox = (CheckBox)findViewById(checkBoxId);
taskBox = (Spinner) findViewById(taskBoxId); taskBox = (Spinner)findViewById(taskBoxId);
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);
} }
}); });
@ -914,12 +940,12 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
public void setBlockingOn(TaskIdentifier value) { public void setBlockingOn(TaskIdentifier value) {
activatedCheckBox.setChecked(value != null); activatedCheckBox.setChecked(value != null);
if (value == null) { if(value == null) {
return; return;
} }
for (int i = 0; i < taskBox.getCount(); i++) for(int i = 0; i < taskBox.getCount(); i++)
if (taskBox.getItemIdAtPosition(i) == value.getId()) { if(taskBox.getItemIdAtPosition(i) == value.getId()) {
taskBox.setSelection(i); taskBox.setSelection(i);
return; return;
} }
@ -929,7 +955,7 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
} }
public TaskIdentifier getBlockingOn() { public TaskIdentifier getBlockingOn() {
if (!activatedCheckBox.isChecked()) if(!activatedCheckBox.isChecked())
return null; return null;
return new TaskIdentifier(taskBox.getSelectedItemId()); return new TaskIdentifier(taskBox.getSelectedItemId());

@ -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