From c245ab501bffddd331eea419a32f0ae208fb49ee Mon Sep 17 00:00:00 2001 From: puavjn2x9 <3530152719@qq.com> Date: Sat, 23 Dec 2023 10:53:48 +0800 Subject: [PATCH] Update DataUtils.java --- src/net/micode/notes/tool/DataUtils.java | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/net/micode/notes/tool/DataUtils.java b/src/net/micode/notes/tool/DataUtils.java index 2a14982..4163d69 100644 --- a/src/net/micode/notes/tool/DataUtils.java +++ b/src/net/micode/notes/tool/DataUtils.java @@ -50,7 +50,7 @@ public class DataUtils { ArrayList operationList = new ArrayList(); for (long id : ids) { if(id == Notes.ID_ROOT_FOLDER) { - Log.e(TAG, "Don't delete system folder root"); + Log.e(TAG, "Don't delete system folder root"); //如果发现是根文件夹,则不删除 continue; } ContentProviderOperation.Builder builder = ContentProviderOperation @@ -58,7 +58,7 @@ public class DataUtils { operationList.add(builder.build()); } try { - ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); + 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; @@ -93,7 +93,8 @@ public class DataUtils { .newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); builder.withValue(NoteColumns.PARENT_ID, folderId); builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); - operationList.add(builder.build()); + operationList.add(builder.build());//将ids里包含的每一列的数据逐次加入到operationList中,等待最后的批量处理 + } try { @@ -119,7 +120,7 @@ public class DataUtils { new String[] { "COUNT(*)" }, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?", new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)}, - null); + null);//筛选条件:源文件不为trash folder int count = 0; if(cursor != null) { @@ -141,11 +142,11 @@ public class DataUtils { null, NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER, new String [] {String.valueOf(type)}, - null); + null);//查询条件:type符合,且不属于垃圾文件夹 boolean exist = false; if (cursor != null) { - if (cursor.getCount() > 0) { + if (cursor.getCount() > 0) {//用getcount函数判断cursor是否为空 exist = true; } cursor.close(); @@ -171,7 +172,7 @@ public class DataUtils { Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null, null, null, null); - boolean exist = false; + boolean exist = false;//通过名字查询文件是否存在 if (cursor != null) { if (cursor.getCount() > 0) { exist = true; @@ -202,7 +203,7 @@ public class DataUtils { new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE }, NoteColumns.PARENT_ID + "=?", new String[] { String.valueOf(folderId) }, - null); + null);//查询条件:父ID是传入的folderId; HashSet set = null; if (c != null) { @@ -211,13 +212,13 @@ public class DataUtils { do { try { AppWidgetAttribute widget = new AppWidgetAttribute(); - widget.widgetId = c.getInt(0); - widget.widgetType = c.getInt(1); + widget.widgetId = c.getInt(0);//0对应的NoteColumns.WIDGET_ID + widget.widgetType = c.getInt(1);//1对应的NoteColumns.WIDGET_TYPE set.add(widget); } catch (IndexOutOfBoundsException e) { Log.e(TAG, e.toString()); } - } while (c.moveToNext()); + } while (c.moveToNext());//查询下一条 } c.close(); } @@ -229,11 +230,12 @@ public class DataUtils { new String [] { CallNote.PHONE_NUMBER }, CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?", new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE }, - null); + null); //通过数据库操作,查询条件是(callDate和phoneNumber匹配传入参数的值) + if (cursor != null && cursor.moveToFirst()) { try { - return cursor.getString(0); + return cursor.getString(0);//0对应的CallNote.NOTE_ID } catch (IndexOutOfBoundsException e) { Log.e(TAG, "Get call number fails " + e.toString()); } finally { @@ -249,7 +251,7 @@ public class DataUtils { CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL(" + CallNote.PHONE_NUMBER + ",?)", new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber }, - null); + null);//查询条件:noteId if (cursor != null) { if (cursor.moveToFirst()) { @@ -282,7 +284,7 @@ public class DataUtils { throw new IllegalArgumentException("Note is not found with id: " + noteId); } - public static String getFormattedSnippet(String snippet) { + public static String getFormattedSnippet(String snippet) {//对字符串进行格式处理,将字符串两头的空格去掉,同时将换行符去掉 if (snippet != null) { snippet = snippet.trim(); int index = snippet.indexOf('\n');