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

File diff suppressed because it is too large Load Diff

@ -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,85 +22,48 @@ 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[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE,
IMPORTANCE, IDENTIFIER, TAGS_ID };
static String[] TASK_FIELD_LIST = new String[] { AbstractTaskModel.NAME, IMPORTANCE_COLOR, static String[] TAGS_FIELD_LIST = new String[] { ID, NAME };
AbstractTaskModel.PREFERRED_DUE_DATE, AbstractTaskModel.DEFINITE_DUE_DATE, AbstractTaskModel.IMPORTANCE, IDENTIFIER };
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) {
Log.d(TAG, "delete"); 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; 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) {
Log.d(TAG, "query"); if (LOGD)
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) {
Log.d(TAG, "update"); 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; 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