|
|
@ -16,7 +16,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.data;
|
|
|
|
package net.micode.notes.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.SearchManager;
|
|
|
|
import android.app.SearchManager;
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
import android.content.ContentProvider;
|
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.ContentUris;
|
|
|
@ -34,23 +33,27 @@ import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* NotesProvider是应用的内容提供者,负责管理笔记数据的访问接口。
|
|
|
|
|
|
|
|
* 它处理对笔记和数据的CRUD操作,并支持搜索功能。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
|
|
|
|
// URI匹配器,用于解析不同的URI请求
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
|
|
|
// 数据库助手类实例
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
|
|
|
|
|
|
|
|
private static final int URI_NOTE = 1;
|
|
|
|
// URI匹配码常量
|
|
|
|
private static final int URI_NOTE_ITEM = 2;
|
|
|
|
private static final int URI_NOTE = 1; // 匹配所有笔记
|
|
|
|
private static final int URI_DATA = 3;
|
|
|
|
private static final int URI_NOTE_ITEM = 2; // 匹配单个笔记
|
|
|
|
private static final int URI_DATA_ITEM = 4;
|
|
|
|
private static final int URI_DATA = 3; // 匹配所有数据
|
|
|
|
|
|
|
|
private static final int URI_DATA_ITEM = 4; // 匹配单个数据
|
|
|
|
private static final int URI_SEARCH = 5;
|
|
|
|
private static final int URI_SEARCH = 5; // 匹配搜索请求
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6; // 匹配搜索建议请求
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
|
|
|
|
// 初始化URI匹配器
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
@ -62,8 +65,8 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
|
|
|
|
* 笔记搜索的投影列定义,用于搜索结果的格式化显示
|
|
|
|
* we will trim '\n' and white space in order to show more information.
|
|
|
|
* 包含ID、搜索文本、图标和意图信息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
|
|
|
|
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
|
|
|
|
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
|
|
|
@ -73,18 +76,28 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记搜索的SQL查询语句,用于在笔记摘要中搜索关键词
|
|
|
|
|
|
|
|
* 排除回收站中的笔记,只搜索普通笔记类型
|
|
|
|
|
|
|
|
*/
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 初始化内容提供者,获取数据库助手实例
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean onCreate() {
|
|
|
|
public boolean onCreate() {
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理查询请求,根据不同的URI执行相应的数据库查询
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
String sortOrder) {
|
|
|
|
String sortOrder) {
|
|
|
@ -93,25 +106,30 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
String id = null;
|
|
|
|
String id = null;
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
case URI_NOTE:
|
|
|
|
case URI_NOTE:
|
|
|
|
|
|
|
|
// 查询所有笔记
|
|
|
|
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
|
|
|
|
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
|
|
|
|
sortOrder);
|
|
|
|
sortOrder);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
|
|
|
// 查询单个笔记
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
|
|
|
|
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA:
|
|
|
|
case URI_DATA:
|
|
|
|
|
|
|
|
// 查询所有数据
|
|
|
|
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
|
|
|
|
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
|
|
|
|
sortOrder);
|
|
|
|
sortOrder);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
|
|
|
// 查询单个数据
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
|
|
|
|
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_SEARCH:
|
|
|
|
case URI_SEARCH:
|
|
|
|
case URI_SEARCH_SUGGEST:
|
|
|
|
case URI_SEARCH_SUGGEST:
|
|
|
|
|
|
|
|
// 处理搜索和搜索建议请求
|
|
|
|
if (sortOrder != null || projection != null) {
|
|
|
|
if (sortOrder != null || projection != null) {
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
|
|
|
|
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
|
|
|
@ -131,6 +149,7 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 执行模糊搜索
|
|
|
|
searchString = String.format("%%%s%%", searchString);
|
|
|
|
searchString = String.format("%%%s%%", searchString);
|
|
|
|
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
|
|
|
|
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
|
|
|
|
new String[] { searchString });
|
|
|
|
new String[] { searchString });
|
|
|
@ -141,21 +160,27 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置内容观察者通知URI
|
|
|
|
if (c != null) {
|
|
|
|
if (c != null) {
|
|
|
|
c.setNotificationUri(getContext().getContentResolver(), uri);
|
|
|
|
c.setNotificationUri(getContext().getContentResolver(), uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理插入请求,根据不同的URI插入相应的数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Uri insert(Uri uri, ContentValues values) {
|
|
|
|
public Uri insert(Uri uri, ContentValues values) {
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
long dataId = 0, noteId = 0, insertedId = 0;
|
|
|
|
long dataId = 0, noteId = 0, insertedId = 0;
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
case URI_NOTE:
|
|
|
|
case URI_NOTE:
|
|
|
|
|
|
|
|
// 插入笔记
|
|
|
|
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
|
|
|
|
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA:
|
|
|
|
case URI_DATA:
|
|
|
|
|
|
|
|
// 插入数据,需关联笔记ID
|
|
|
|
if (values.containsKey(DataColumns.NOTE_ID)) {
|
|
|
|
if (values.containsKey(DataColumns.NOTE_ID)) {
|
|
|
|
noteId = values.getAsLong(DataColumns.NOTE_ID);
|
|
|
|
noteId = values.getAsLong(DataColumns.NOTE_ID);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -166,13 +191,12 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Notify the note uri
|
|
|
|
// 通知数据变化
|
|
|
|
if (noteId > 0) {
|
|
|
|
if (noteId > 0) {
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Notify the data uri
|
|
|
|
|
|
|
|
if (dataId > 0) {
|
|
|
|
if (dataId > 0) {
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
|
|
|
@ -181,6 +205,9 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
return ContentUris.withAppendedId(uri, insertedId);
|
|
|
|
return ContentUris.withAppendedId(uri, insertedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理删除请求,根据不同的URI删除相应的数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
@ -189,15 +216,13 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
boolean deleteData = false;
|
|
|
|
boolean deleteData = false;
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
case URI_NOTE:
|
|
|
|
case URI_NOTE:
|
|
|
|
|
|
|
|
// 删除多个笔记,确保不删除系统文件夹
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
|
|
|
|
count = db.delete(TABLE.NOTE, selection, selectionArgs);
|
|
|
|
count = db.delete(TABLE.NOTE, selection, selectionArgs);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
|
|
|
// 删除单个笔记,不允许删除系统文件夹
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
/**
|
|
|
|
|
|
|
|
* ID that smaller than 0 is system folder which is not allowed to
|
|
|
|
|
|
|
|
* trash
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
long noteId = Long.valueOf(id);
|
|
|
|
long noteId = Long.valueOf(id);
|
|
|
|
if (noteId <= 0) {
|
|
|
|
if (noteId <= 0) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -206,10 +231,12 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA:
|
|
|
|
case URI_DATA:
|
|
|
|
|
|
|
|
// 删除多个数据
|
|
|
|
count = db.delete(TABLE.DATA, selection, selectionArgs);
|
|
|
|
count = db.delete(TABLE.DATA, selection, selectionArgs);
|
|
|
|
deleteData = true;
|
|
|
|
deleteData = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
|
|
|
// 删除单个数据
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
count = db.delete(TABLE.DATA,
|
|
|
|
count = db.delete(TABLE.DATA,
|
|
|
|
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
@ -218,6 +245,7 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 通知数据变化
|
|
|
|
if (count > 0) {
|
|
|
|
if (count > 0) {
|
|
|
|
if (deleteData) {
|
|
|
|
if (deleteData) {
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
@ -227,6 +255,9 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理更新请求,根据不同的URI更新相应的数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
@ -235,20 +266,24 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
boolean updateData = false;
|
|
|
|
boolean updateData = false;
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
case URI_NOTE:
|
|
|
|
case URI_NOTE:
|
|
|
|
|
|
|
|
// 更新多个笔记,并增加版本号
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs);
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs);
|
|
|
|
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
|
|
|
|
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
|
|
|
// 更新单个笔记,并增加版本号
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
|
|
|
|
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
|
|
|
|
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA:
|
|
|
|
case URI_DATA:
|
|
|
|
|
|
|
|
// 更新多个数据
|
|
|
|
count = db.update(TABLE.DATA, values, selection, selectionArgs);
|
|
|
|
count = db.update(TABLE.DATA, values, selection, selectionArgs);
|
|
|
|
updateData = true;
|
|
|
|
updateData = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
|
|
|
// 更新单个数据
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
|
|
|
|
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
@ -258,6 +293,7 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通知数据变化
|
|
|
|
if (count > 0) {
|
|
|
|
if (count > 0) {
|
|
|
|
if (updateData) {
|
|
|
|
if (updateData) {
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
@ -267,10 +303,16 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 解析SQL选择条件,添加额外的AND条件
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String parseSelection(String selection) {
|
|
|
|
private String parseSelection(String selection) {
|
|
|
|
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
|
|
|
|
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 增加笔记的版本号,用于同步和冲突检测
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
|
|
|
|
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
|
|
|
|
StringBuilder sql = new StringBuilder(120);
|
|
|
|
StringBuilder sql = new StringBuilder(120);
|
|
|
|
sql.append("UPDATE ");
|
|
|
|
sql.append("UPDATE ");
|
|
|
@ -279,6 +321,7 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
sql.append(NoteColumns.VERSION);
|
|
|
|
sql.append(NoteColumns.VERSION);
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 ");
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建WHERE子句
|
|
|
|
if (id > 0 || !TextUtils.isEmpty(selection)) {
|
|
|
|
if (id > 0 || !TextUtils.isEmpty(selection)) {
|
|
|
|
sql.append(" WHERE ");
|
|
|
|
sql.append(" WHERE ");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -293,13 +336,16 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
sql.append(selectString);
|
|
|
|
sql.append(selectString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 执行SQL语句
|
|
|
|
mHelper.getWritableDatabase().execSQL(sql.toString());
|
|
|
|
mHelper.getWritableDatabase().execSQL(sql.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 返回URI对应的MIME类型,此处未实现
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getType(Uri uri) {
|
|
|
|
public String getType(Uri uri) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|