From 470be25a47f9c8c0803c198053a8600b3e95d48e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=40jkccchen123?= <893824054@qq.com> Date: Thu, 23 Nov 2023 08:18:21 +0800 Subject: [PATCH] secondtime --- .../java/net/micode/notes/tool/DataUtils.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Notes-master1/app/src/main/java/net/micode/notes/tool/DataUtils.java b/Notes-master1/app/src/main/java/net/micode/notes/tool/DataUtils.java index 2a14982..eaf4849 100644 --- a/Notes-master1/app/src/main/java/net/micode/notes/tool/DataUtils.java +++ b/Notes-master1/app/src/main/java/net/micode/notes/tool/DataUtils.java @@ -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 ids, long folderId) { + // 该方法用于批量将多个笔记移动到指定文件夹中 + // 检查传入的笔记ID集合是否为空 if (ids == null) { Log.d(TAG, "the ids is null"); return true; } - + // 创建一个操作列表,用于存储需要执行的更新操作 ArrayList operationList = new ArrayList(); + // 遍历传入的笔记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;