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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timsu.astrid"
android:versionCode="123" android:versionName="2.10.2">
android:versionCode="124" android:versionName="2.10.3">
<!-- ============================ Metadata ============================ -->

@ -88,8 +88,8 @@ import com.timsu.astrid.widget.TimeDurationControlSet.TimeDurationType;
/**
* 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)
* as long as the task has a title.
* ones. It saves a task when it is paused (screen rotated, back button
* pressed) as long as the task has a title.
*
* @author timsu
*
@ -192,11 +192,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
return controller.createNewTaskForEdit();
}
/*
* ======================================================================
/* ======================================================================
* =============================================== model reading / saving
* ======================================================================
*/
* ====================================================================== */
/** Populate UI component values from the model */
private void populateFields() {
@ -216,8 +214,10 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
}
if(model.getName().length() > 0)
setTitle(new StringBuilder().append(r.getString(R.string.taskEdit_titlePrefix)).append(" ").append(
model.getName()));
setTitle(new StringBuilder().
append(r.getString(R.string.taskEdit_titlePrefix)).
append(" ").
append(model.getName()));
estimatedDuration.setTimeDuration(model.getEstimatedSeconds());
elapsedDuration.setTimeDuration(model.getElapsedSeconds());
importance.setImportance(model.getImportance());
@ -241,7 +241,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
if(model.getTaskIdentifier() != null) {
taskTags = tagController.getTaskTags(model.getTaskIdentifier());
if(taskTags.size() > 0) {
Map<TagIdentifier, TagModelForView> tagsMap = new HashMap<TagIdentifier, TagModelForView>();
Map<TagIdentifier, TagModelForView> tagsMap =
new HashMap<TagIdentifier, TagModelForView>();
for(TagModelForView tag : tags)
tagsMap.put(tag.getTagIdentifier(), tag);
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
* due in 'x' amount of time, to 2 time-units of precision (e.g. Days +
* Hours).
*
* @param dueDate
* the Date when the task is due
* due in 'x' amount of time, to 2 time-units of precision (e.g. Days + Hours).
* @param dueDate the Date when the task is due
*/
private void showSaveToast(Date dueDate) {
int stringResource;
@ -338,19 +336,20 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
int timeInSeconds = (int)((dueDate.getTime() - System.currentTimeMillis())/1000L);
if (timeInSeconds < 0) {
timeInSeconds *= -1; // DateUtilities.getDurationString() requires
// positive integer
timeInSeconds *= -1; // DateUtilities.getDurationString() requires positive integer
stringResource = R.string.taskEdit_onTaskSave_Overdue;
} else {
stringResource = R.string.taskEdit_onTaskSave_Due;
}
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
* this version when no due Date has been set.
* Displays a Toast reporting that the selected task has been saved.
* Use this version when no due Date has been set.
*/
private void showSaveToast() {
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());
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();
alertController.addAlert(model.getTaskIdentifier(), date);
}
}
/*
* ======================================================================
/* ======================================================================
* ==================================================== UI initialization
* ======================================================================
*/
* ====================================================================== */
/** Initialize UI components */
private void setUpUIComponents() {
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
name = (EditText)findViewById(R.id.name);
importance = new ImportanceControlSet(R.id.importance_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);
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);
notification = new TimeDurationControlSet(this, R.id.notification, R.string.notification_prefix,
R.string.notification_dialog, TimeDurationType.DAYS_HOURS);
definiteDueDate = new DateWithNullControlSet(this, R.id.definiteDueDate_notnull, R.id.definiteDueDate_date,
R.id.definiteDueDate_time);
preferredDueDate = new DateWithNullControlSet(this, R.id.preferredDueDate_notnull, R.id.preferredDueDate_date,
R.id.preferredDueDate_time);
hiddenUntil = new DateWithNullControlSet(this, R.id.hiddenUntil_notnull, R.id.hiddenUntil_date,
R.id.hiddenUntil_time);
notification = new TimeDurationControlSet(this, R.id.notification,
R.string.notification_prefix, R.string.notification_dialog,
TimeDurationType.DAYS_HOURS);
definiteDueDate = new DateWithNullControlSet(this, R.id.definiteDueDate_notnull,
R.id.definiteDueDate_date, R.id.definiteDueDate_time);
preferredDueDate = new DateWithNullControlSet(this, R.id.preferredDueDate_notnull,
R.id.preferredDueDate_date, R.id.preferredDueDate_time);
hiddenUntil = new DateWithNullControlSet(this, R.id.hiddenUntil_notnull,
R.id.hiddenUntil_date, R.id.hiddenUntil_time);
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);
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
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()));
repeatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
repeatInterval.setAdapter(repeatAdapter);
@ -510,8 +514,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
private RepeatInfo getRepeatValue() {
if(repeatValue.getTag().equals(0))
return null;
return new RepeatInfo(RepeatInterval.values()[repeatInterval.getSelectedItemPosition()], (Integer) repeatValue
.getTag());
return new RepeatInfo(RepeatInterval.values()
[repeatInterval.getSelectedItemPosition()],
(Integer)repeatValue.getTag());
}
/** 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);
alertsContainer.addView(alertItem);
DateControlSet dcs = new DateControlSet(this, (Button) alertItem.findViewById(R.id.date), (Button) alertItem
.findViewById(R.id.time));
DateControlSet dcs = new DateControlSet(this,
(Button)alertItem.findViewById(R.id.date),
(Button)alertItem.findViewById(R.id.time));
dcs.setDate(alert);
alertItem.setTag(dcs);
@ -549,14 +555,18 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
final View tagItem = inflater.inflate(R.layout.edit_tag_item, null);
tagsContainer.addView(tagItem);
AutoCompleteTextView textView = (AutoCompleteTextView) tagItem.findViewById(R.id.text1);
AutoCompleteTextView textView = (AutoCompleteTextView)tagItem.
findViewById(R.id.text1);
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);
textView.setAdapter(tagsAdapter);
textView.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (start == 0 && tagsContainer.getChildAt(tagsContainer.getChildCount() - 1) == tagItem) {
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if(start == 0 && tagsContainer.getChildAt(
tagsContainer.getChildCount()-1) == tagItem) {
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;
}
/*
* ======================================================================
/* ======================================================================
* ======================================================= event handlers
* ======================================================================
*/
* ====================================================================== */
@Override
public void onWindowFocusChanged(boolean hasFocus) {
@ -608,8 +617,11 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
}
private void deleteButtonClick() {
new AlertDialog.Builder(this).setTitle(R.string.delete_title).setMessage(R.string.delete_this_task_title)
.setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(android.R.string.ok,
new AlertDialog.Builder(this)
.setTitle(R.string.delete_title)
.setMessage(R.string.delete_this_task_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// tell the task list to update itself
@ -620,7 +632,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
setResult(Constants.RESULT_GO_HOME);
finish();
}
}).setNegativeButton(android.R.string.cancel, null).show();
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private void repeatValueClick() {
@ -640,7 +654,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
public void onNumberPicked(NumberPicker view, int 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;
}
new AlertDialog.Builder(this).setTitle(R.string.repeat_help_dialog_title).setMessage(
R.string.repeat_help_dialog).setIcon(android.R.drawable.ic_dialog_info).setPositiveButton(
android.R.string.ok, new DialogInterface.OnClickListener() {
new AlertDialog.Builder(this)
.setTitle(R.string.repeat_help_dialog_title)
.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) {
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) {
Preferences.setShowRepeatHelp(TaskEdit.this, false);
openDialogRunnable.run();
}
}).show();
})
.show();
}
@Override
@ -709,23 +730,20 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
// save the tag name token for when we rotate the screen
Bundle extras = getIntent().getExtras();
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'.
*
* @param preferred
* preferred due date or null
* @param definite
* definite due date or null
* @param estimatedSeconds
* estimated duration or null
* @param preferred preferred due date or null
* @param definite definite due date or null
* @param estimatedSeconds estimated duration or null
* @param values
*/
public static void createCalendarStartEndTimes(Date preferred, Date definite, Integer estimatedSeconds,
ContentValues values) {
public static void createCalendarStartEndTimes(Date preferred, Date definite,
Integer estimatedSeconds, ContentValues values) {
FlurryAgent.onEvent("create-calendar-event");
Long deadlineDate = null;
@ -759,8 +777,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
values.put("transparency", 0);
values.put("visibility", 0);
createCalendarStartEndTimes(model.getPreferredDueDate(), model.getDefiniteDueDate(), model
.getEstimatedSeconds(), values);
createCalendarStartEndTimes(model.getPreferredDueDate(),
model.getDefiniteDueDate(), model.getEstimatedSeconds(),
values);
Uri result = cr.insert(uri, values);
if(result != null)
@ -777,8 +796,9 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Intent intent = new Intent(Intent.ACTION_EDIT, result);
ContentValues values = new ContentValues();
createCalendarStartEndTimes(model.getPreferredDueDate(), model.getDefiniteDueDate(), model
.getEstimatedSeconds(), values);
createCalendarStartEndTimes(model.getPreferredDueDate(),
model.getDefiniteDueDate(), model.getEstimatedSeconds(),
values);
intent.putExtra("beginTime", values.getAsLong("dtstart"));
intent.putExtra("endTime", values.getAsLong("dtend"));
@ -802,17 +822,16 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
alertController.close();
}
/*
* ======================================================================
/* ======================================================================
* ========================================== UI component helper classes
* ======================================================================
*/
* ====================================================================== */
/** Control set dealing with notification flags */
public class NotifyFlagControlSet {
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);
during = (CheckBox)findViewById(duringId);
after = (CheckBox)findViewById(afterId);
@ -820,10 +839,14 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
}
public void setValue(int flags) {
before.setChecked((flags & TaskModelForEdit.NOTIFY_BEFORE_DEADLINE) > 0);
during.setChecked((flags & TaskModelForEdit.NOTIFY_AT_DEADLINE) > 0);
after.setChecked((flags & TaskModelForEdit.NOTIFY_AFTER_DEADLINE) > 0);
nonstop.setChecked((flags & TaskModelForEdit.NOTIFY_NONSTOP) > 0);
before.setChecked((flags &
TaskModelForEdit.NOTIFY_BEFORE_DEADLINE) > 0);
during.setChecked((flags &
TaskModelForEdit.NOTIFY_AT_DEADLINE) > 0);
after.setChecked((flags &
TaskModelForEdit.NOTIFY_AFTER_DEADLINE) > 0);
nonstop.setChecked((flags &
TaskModelForEdit.NOTIFY_NONSTOP) > 0);
}
public int getValue() {
@ -850,8 +873,8 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
for(Importance i : Importance.values()) {
final ToggleButton button = new ToggleButton(TaskEdit.this);
button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT, 1));
button.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
button.setTextColor(r.getColor(i.getColorResource()));
button.setTextOff(r.getString(i.getLabelResource()));
button.setTextOn(r.getString(i.getLabelResource()));
@ -900,12 +923,15 @@ public class TaskEdit extends TaskModificationTabbedActivity<TaskModelForEdit> {
Cursor tasks = controller.getActiveTaskListCursor();
startManagingCursor(tasks);
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 });
taskBox.setAdapter(tasksAdapter);
activatedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
activatedCheckBox.setOnCheckedChangeListener(
new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean 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.task.TaskIdentifier;
import com.timsu.astrid.data.task.AbstractTaskModel.TaskModelDatabaseHelper;
import com.timsu.astrid.provider.TasksProvider;
/** Controller for Tag-related operations */
public class TagController extends AbstractController {
@ -247,8 +248,13 @@ public class TagController extends AbstractController {
TagToTaskMapping.TAG + " = " + tagId.idAsString(), null) < 0)
return false;
return tagDatabase.delete(TAG_TABLE_NAME,
KEY_ROWID + " = " + tagId.idAsString(), null) > 0;
int res = tagDatabase.delete(TAG_TABLE_NAME,
KEY_ROWID + " = " + tagId.idAsString(), null);
// notify modification
TasksProvider.notifyDatabaseModification();
return res > 0;
}
// --- single tag to task operations
@ -256,10 +262,16 @@ public class TagController extends AbstractController {
/** Remove the given tag from the task */
public boolean removeTag(TaskIdentifier taskId, TagIdentifier tagId)
throws SQLException{
return tagToTaskMapDatabase.delete(TAG_TASK_MAP_NAME,
int res = tagToTaskMapDatabase.delete(TAG_TASK_MAP_NAME,
String.format("%s = ? AND %s = ?",
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 */
@ -268,8 +280,14 @@ public class TagController extends AbstractController {
ContentValues values = new ContentValues();
values.put(TagToTaskMapping.TAG, tagId.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

@ -1,6 +1,7 @@
package com.timsu.astrid.provider;
import java.util.ArrayList;
import java.util.LinkedList;
import android.content.ContentProvider;
import android.content.ContentValues;
@ -11,7 +12,9 @@ import android.database.MatrixCursor;
import android.net.Uri;
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.TaskModelForProvider;
@ -19,86 +22,49 @@ public class TasksProvider extends ContentProvider {
private static final String TAG = "MessageProvider";
private static final boolean LOGD = false;
public static final String AUTHORITY = "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 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 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,
AbstractTaskModel.PREFERRED_DUE_DATE, AbstractTaskModel.DEFINITE_DUE_DATE, AbstractTaskModel.IMPORTANCE, IDENTIFIER };
static String[] TASK_FIELD_LIST = new String[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE,
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_MESSAGES = 1;
// private static final int URI_MESSAGE = 2;
// private static final int URI_FOLDERS = 3;
private static final int URI_TAGS = 1;
private static final String TAG_SEPARATOR = "|";
private static Context ctx = null;
static {
URI_MATCHER.addURI(AUTHORITY, "tasks", URI_TASKS);
// URI_MATCHER.addURI(AUTHORITY, "messages/*", URI_MESSAGES);
// URI_MATCHER.addURI(AUTHORITY, "message/*", URI_MESSAGE);
// URI_MATCHER.addURI(AUTHORITY, "folders/*", URI_FOLDERS);
URI_MATCHER.addURI(AUTHORITY, "tags", URI_TAGS);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (LOGD)
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;
}
@ -120,15 +86,24 @@ public class TasksProvider extends ContentProvider {
public Cursor getTags() {
// TaskController taskController = new TaskController(ctx);
// taskController.ge
//
// MatrixCursor ret = new MatrixCursor(TASK_FIELD_LIST);
//
// for (int i = 0; i < taskList.size(); i++) {
// }
LinkedList<TagModelForView> tags = null;
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() {
@ -157,13 +132,28 @@ public class TasksProvider extends ContentProvider {
if (taskModel.getDefiniteDueDate() != null)
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[1] = ctx.getResources().getColor(taskModel.getImportance().getColorResource());
values[2] = preferredDueDateTime;
values[3] = definiteDueDate;
values[4] = taskModel.getImportance().ordinal();
values[5] = taskModel.getTaskIdentifier().getId();
values[6] = taskTags;
ret.addRow(values);
@ -176,32 +166,19 @@ public class TasksProvider extends ContentProvider {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (LOGD)
Log.d(TAG, "query");
Cursor cursor;
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:
cursor = getTasks();
break;
// case URI_FOLDERS:
// segments = uri.getPathSegments();
// emailAccount = segments.get(1);
//
// openOrReopenDatabase(emailAccount);
//
// cursor = getFolders(projection, selection, selectionArgs, sortOrder);
// break;
case URI_TAGS:
cursor = getTags();
break;
default:
throw new IllegalStateException("Unrecognized URI:" + uri);
@ -210,93 +187,19 @@ public class TasksProvider extends ContentProvider {
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
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (LOGD)
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;
}
public static void notifyDatabaseModification() {
Log.d(TAG, "UPDATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
if (LOGD)
Log.d(TAG, "notifyDatabaseModification");
ctx.getContentResolver().notifyChange(CONTENT_URI, null);

Loading…
Cancel
Save