|
|
|
|
@ -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,85 +22,48 @@ 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[] { NAME, IMPORTANCE_COLOR, PREFERRED_DUE_DATE, DEFINITE_DUE_DATE,
|
|
|
|
|
IMPORTANCE, IDENTIFIER, 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[] 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) {
|
|
|
|
|
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();
|
|
|
|
|
if (LOGD)
|
|
|
|
|
Log.d(TAG, "delete");
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "query");
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
if (LOGD)
|
|
|
|
|
Log.d(TAG, "update");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void notifyDatabaseModification() {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "UPDATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
|
if (LOGD)
|
|
|
|
|
Log.d(TAG, "notifyDatabaseModification");
|
|
|
|
|
|
|
|
|
|
ctx.getContentResolver().notifyChange(CONTENT_URI, null);
|
|
|
|
|
|
|
|
|
|
|