From d4a66e755af7a97ec1031240fad969cb6454261c Mon Sep 17 00:00:00 2001 From: ynmlzdwsp <2727940448@qq.com> Date: Fri, 22 Sep 2023 22:24:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BA=86=E4=B8=80=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../6a65e747031f27aef20597b4181148a9fbf963d5 | 22 +++++++++---------- .../9a3a19793537958b8b1b03a81985999e22705a2f | 10 ++++----- .idea/sonarlint/issuestore/index.pb | 10 ++++++++- .idea/sonarlint/securityhotspotstore/index.pb | 10 ++++++++- .../net/micode/notes/gtask/data/SqlData.java | 4 ++++ .../net/micode/notes/gtask/data/SqlNote.java | 20 +++++++++++++++++ 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/.idea/sonarlint/issuestore/6/a/6a65e747031f27aef20597b4181148a9fbf963d5 b/.idea/sonarlint/issuestore/6/a/6a65e747031f27aef20597b4181148a9fbf963d5 index 9cf548a..9a16007 100644 --- a/.idea/sonarlint/issuestore/6/a/6a65e747031f27aef20597b4181148a9fbf963d5 +++ b/.idea/sonarlint/issuestore/6/a/6a65e747031f27aef20597b4181148a9fbf963d5 @@ -1,13 +1,13 @@ -i -java:S1192"MDefine a constant instead of duplicating this literal "Unknown URI " 4 times.( -M -java:S1153"1Directly append the argument of String.valueOf().(ߦ - -java:S3008L"eRename this field "NOTES_SNIPPET_SEARCH_QUERY" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -_ -java:S1659"CDeclare "noteId" and all following declarations on a separate line.(ؘ +p +java:S1192"MDefine a constant instead of duplicating this literal "Unknown URI " 4 times.(81 T -java:S2130"8Use "Long.parseLong" for this string-to-long conversion.( -N -java:S1135"2Complete the task associated to this TODO comment.( \ No newline at end of file +java:S1153"1Directly append the argument of String.valueOf().(ߦ81 + +java:S3008S"eRename this field "NOTES_SNIPPET_SEARCH_QUERY" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(8ڶ1 +f +java:S1659"CDeclare "noteId" and all following declarations on a separate line.(ؘ81 +[ +java:S2130"8Use "Long.parseLong" for this string-to-long conversion.(81 +U +java:S1135"2Complete the task associated to this TODO comment.(81 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/9/a/9a3a19793537958b8b1b03a81985999e22705a2f b/.idea/sonarlint/issuestore/9/a/9a3a19793537958b8b1b03a81985999e22705a2f index 11d5a32..05fb9b0 100644 --- a/.idea/sonarlint/issuestore/9/a/9a3a19793537958b8b1b03a81985999e22705a2f +++ b/.idea/sonarlint/issuestore/9/a/9a3a19793537958b8b1b03a81985999e22705a2f @@ -1,11 +1,11 @@ { -java:S2293)"YReplace the type specification in this constructor call with the diamond operator ("<>").(8ҿ1 +java:S2293,"YReplace the type specification in this constructor call with the diamond operator ("<>").(8ݝ1 W -java:S1118":Add a private constructor to hide the implicit public one.(8’ҿ1 +java:S1118":Add a private constructor to hide the implicit public one.(8ݝ1 x -java:S3252!"VUse static access with "android.provider.ContactsContract$DataColumns" for "MIMETYPE".(8Ȓҿ1 +java:S3252#"VUse static access with "android.provider.ContactsContract$DataColumns" for "MIMETYPE".(8ޝ1 y -java:S3252""\Use static access with "android.provider.ContactsContract$DataColumns" for "RAW_CONTACT_ID".(8Ȓҿ1 +java:S3252$"\Use static access with "android.provider.ContactsContract$DataColumns" for "RAW_CONTACT_ID".(8ޝ1 { -java:S32524"^Use static access with "android.provider.ContactsContract$ContactsColumns" for "DISPLAY_NAME".(8ʒҿ1 \ No newline at end of file +java:S3252<"^Use static access with "android.provider.ContactsContract$ContactsColumns" for "DISPLAY_NAME".(8ޝ1 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index 9d9b693..0cf0abf 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -140,4 +140,12 @@ G.idea/sonarlint/issuestore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164,3\1\31 w G.idea/sonarlint/issuestore/9/e/9e08934d811afe28fbc77aaa3c0d747b94348db9,0\1\0105d5a774c76db833eb83cbebde54a8abef1599 d -4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f \ No newline at end of file +4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f +b +2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5 +p +@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13 +k +;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 +j +:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index 1c21ffd..c2cf1ae 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -140,4 +140,12 @@ G.idea/sonarlint/issuestore/f/0/f07866736216be0ee2aba49e392191aeae700a35,b\f\bf w G.idea/sonarlint/issuestore/f/4/f4a01d6a4fcb971362ec00a83903fd3902f52164,3\1\31073cf3a12b082ef2fe0f9403916a4db3811c89 w -G.idea/sonarlint/issuestore/9/e/9e08934d811afe28fbc77aaa3c0d747b94348db9,0\1\0105d5a774c76db833eb83cbebde54a8abef1599 \ No newline at end of file +G.idea/sonarlint/issuestore/9/e/9e08934d811afe28fbc77aaa3c0d747b94348db9,0\1\0105d5a774c76db833eb83cbebde54a8abef1599 +b +2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5 +p +@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13 +j +:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 +k +;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 \ No newline at end of file diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java index d3ec3be..d0bbbbb 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlData.java @@ -147,7 +147,10 @@ public class SqlData { public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { + //创建新的数据 if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { + //如果 mDataId 的值为无效的 ID, + // 并且 mDiffDataValues 包含了键为 DataColumns.ID 的差异数据,则会将该键移除。 mDiffDataValues.remove(DataColumns.ID); } @@ -160,6 +163,7 @@ public class SqlData { throw new ActionFailureException("create note failed"); } } else { + //更新已有的数据 if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { diff --git a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java index 79a4095..b5232cf 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java +++ b/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java @@ -166,6 +166,10 @@ public class SqlNote { } + /** + * 从数据库中加载指定ID的数据 + * @param id + */ private void loadFromCursor(long id) { Cursor c = null; try { @@ -185,6 +189,7 @@ public class SqlNote { } } + private void loadFromCursor(Cursor c) { mId = c.getLong(ID_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN); @@ -226,12 +231,21 @@ public class SqlNote { } } + /** + * 设置笔记的内容。根据传入的JSON对象js,首先从中获取note对象。然后根据note的类型进行不同的处理 + * @param js + * @return + */ public boolean setContent(JSONObject js) { try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { + //无法设置系统文件夹,会记录一个警告日志 Log.w(TAG, "cannot set system folder"); } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { + //只能更新摘要(snippet)和类型(type)。 + // 如果正在创建新的文件夹或者摘要与原摘要不相同,则将摘要添加到差异值列表mDiffNoteValues中, + // 并更新当前的摘要mSnippet和类型mType。 // for folder we can only update the snnipet and type String snippet = note.has(NoteColumns.SNIPPET) ? note .getString(NoteColumns.SNIPPET) : ""; @@ -247,6 +261,11 @@ public class SqlNote { } mType = type; } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { + //如果note的类型为笔记类型(Notes.TYPE_NOTE), + // 则需要进一步处理其中的数据数组dataArray。 + // 先获取笔记的ID、提醒日期、背景色ID、创建日期、附件标识、修改日期、父文件夹ID、摘要、类型、 + // 小部件ID、小部件类型和原始父文件夹ID等信息,并将它们与当前的值进行比较, + // 如果有改变则添加到差异值列表中并更新对应的字段 JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; if (mIsCreate || mId != id) { @@ -331,6 +350,7 @@ public class SqlNote { } mOriginParent = originParent; + //遍历数据数组dataArray,将每个数据对象转换为SqlData对象,并设置其内容 for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); SqlData sqlData = null;