|
|
|
@ -73,31 +73,41 @@ public class DataUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put(NoteColumns.PARENT_ID, desFolderId);
|
|
|
|
|
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
|
|
|
|
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
|
// 创建一个ContentValues对象,用于存储需要更新的数据
|
|
|
|
|
ContentValues values = new ContentValues();// 将笔记的父文件夹ID设置为目标文件夹ID
|
|
|
|
|
values.put(NoteColumns.PARENT_ID, desFolderId);// 将笔记的原始父文件夹ID设置为源文件夹ID
|
|
|
|
|
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);// 将笔记的本地修改标志设置为1,表示需要同步到服务器
|
|
|
|
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);// 使用ContentResolver对象更新笔记的数据
|
|
|
|
|
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
|
|
|
|
|
long folderId) {
|
|
|
|
|
// 该方法用于批量将多个笔记移动到指定文件夹中
|
|
|
|
|
// 检查传入的笔记ID集合是否为空
|
|
|
|
|
if (ids == null) {
|
|
|
|
|
Log.d(TAG, "the ids is null");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建一个操作列表,用于存储需要执行的更新操作
|
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
|
// 遍历传入的笔记ID集合
|
|
|
|
|
for (long id : ids) {
|
|
|
|
|
// 创建一个新的更新操作
|
|
|
|
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
|
|
|
|
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
|
|
|
|
// 设置更新操作的值,将笔记的父文件夹ID设置为目标文件夹ID
|
|
|
|
|
builder.withValue(NoteColumns.PARENT_ID, folderId);
|
|
|
|
|
// 将笔记的本地修改标志设置为1,表示需要同步到服务器
|
|
|
|
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
|
// 将更新操作添加到操作列表中
|
|
|
|
|
operationList.add(builder.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 使用ContentResolver对象批量执行更新操作
|
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
|
// 检查更新操作是否成功
|
|
|
|
|
if (results == null || results.length == 0 || results[0] == null) {
|
|
|
|
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
|
|
|
|
return false;
|
|
|
|
|