diff --git a/zz_code/gtask/data/.idea/.gitignore b/zz_code/gtask/data/.idea/.gitignore
new file mode 100644
index 0000000..01b5f8c
--- /dev/null
+++ b/zz_code/gtask/data/.idea/.gitignore
@@ -0,0 +1,10 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# GitHub Copilot persisted chat sessions
+/copilot/chatSessions
diff --git a/zz_code/gtask/data/.idea/misc.xml b/zz_code/gtask/data/.idea/misc.xml
new file mode 100644
index 0000000..639900d
--- /dev/null
+++ b/zz_code/gtask/data/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/modules.xml b/zz_code/gtask/data/.idea/modules.xml
new file mode 100644
index 0000000..9db1d29
--- /dev/null
+++ b/zz_code/gtask/data/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/2/9/299b8fefb8e07955453bf475fb724aefbb521c56 b/zz_code/gtask/data/.idea/sonarlint/issuestore/2/9/299b8fefb8e07955453bf475fb724aefbb521c56
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/6/c/6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd b/zz_code/gtask/data/.idea/sonarlint/issuestore/6/c/6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd
new file mode 100644
index 0000000..6ceb1d7
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/6/c/6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd
@@ -0,0 +1,17 @@
+
+u
+java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(
+u
+java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(
+u
+java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(
+
+java:S1598"This file "SqlNote.java" should be located in "net\micode\notes\gtask\data" directory, not in "E:\software\java\zz_code\gtask\data".(
+2
+java:S2386/"Make this member "protected".(u
+n
+java:S3776"RRefactor this method to reduce its Cognitive Complexity from 91 to the 15 allowed.(
+h
+java:S3776"RRefactor this method to reduce its Cognitive Complexity from 32 to the 15 allowed.(
+
+java:S6541"A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 116 to 64, Complexity from 51 to 14, Nesting Level from 6 to 2, Number of Variables from 23 to 6.(
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/a/8/a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04 b/zz_code/gtask/data/.idea/sonarlint/issuestore/a/8/a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04
new file mode 100644
index 0000000..8756022
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/a/8/a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04
@@ -0,0 +1,7 @@
+
+t
+java:S2293+"YReplace the type specification in this constructor call with the diamond operator ("<>").(ʩ
+
+java:S1598"This file "TaskList.java" should be located in "net\micode\notes\gtask\data" directory, not in "E:\software\java\zz_code\gtask\data".(
+r
+java:S3923"[Remove this conditional structure or edit its code blocks so that they're not all the same.(ԡ
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/e/d/ed02129552b2e83baf49343541491561975ba1ea b/zz_code/gtask/data/.idea/sonarlint/issuestore/e/d/ed02129552b2e83baf49343541491561975ba1ea
new file mode 100644
index 0000000..52cf303
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/e/d/ed02129552b2e83baf49343541491561975ba1ea
@@ -0,0 +1,5 @@
+
+
+java:S1598"This file "Node.java" should be located in "net\micode\notes\gtask\data" directory, not in "E:\software\java\zz_code\gtask\data".(
+O
+java:S59933"9Change the visibility of this constructor to "protected".(
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/f/9/f97a970974b4caa5a4cebaa56b3baae5059b6324 b/zz_code/gtask/data/.idea/sonarlint/issuestore/f/9/f97a970974b4caa5a4cebaa56b3baae5059b6324
new file mode 100644
index 0000000..02c7a1e
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/f/9/f97a970974b4caa5a4cebaa56b3baae5059b6324
@@ -0,0 +1,8 @@
+
+
+java:S1598"This file "SqlData.java" should be located in "net\micode\notes\gtask\data" directory, not in "E:\software\java\zz_code\gtask\data".(
+2
+java:S2386/"Make this member "protected".(X
+8 java:S131""Add a default case to this switch.(Ӂ
+n
+java:S3776"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.(
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/f/a/fa2ac87563a7f02291ea933ffc96fff7ca749e80 b/zz_code/gtask/data/.idea/sonarlint/issuestore/f/a/fa2ac87563a7f02291ea933ffc96fff7ca749e80
new file mode 100644
index 0000000..ddea60e
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/f/a/fa2ac87563a7f02291ea933ffc96fff7ca749e80
@@ -0,0 +1,5 @@
+
+
+java:S1598"This file "MetaData.java" should be located in "net\micode\notes\gtask\data" directory, not in "E:\software\java\zz_code\gtask\data".(
+[
+java:S1124"EReorder the modifiers to comply with the Java Language Specification.(
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/issuestore/index.pb b/zz_code/gtask/data/.idea/sonarlint/issuestore/index.pb
new file mode 100644
index 0000000..4eff3c4
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/issuestore/index.pb
@@ -0,0 +1,13 @@
+
+=
+
MetaData.java,f\a\fa2ac87563a7f02291ea933ffc96fff7ca749e80
+9
+ Node.java,e\d\ed02129552b2e83baf49343541491561975ba1ea
+<
+SqlData.java,f\9\f97a970974b4caa5a4cebaa56b3baae5059b6324
+<
+SqlNote.java,6\c\6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd
+9
+ Task.java,2\9\299b8fefb8e07955453bf475fb724aefbb521c56
+=
+
TaskList.java,a\8\a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/2/9/299b8fefb8e07955453bf475fb724aefbb521c56 b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/2/9/299b8fefb8e07955453bf475fb724aefbb521c56
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/6/c/6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/6/c/6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/a/8/a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04 b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/a/8/a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/e/d/ed02129552b2e83baf49343541491561975ba1ea b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/e/d/ed02129552b2e83baf49343541491561975ba1ea
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/f/9/f97a970974b4caa5a4cebaa56b3baae5059b6324 b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/f/9/f97a970974b4caa5a4cebaa56b3baae5059b6324
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/f/a/fa2ac87563a7f02291ea933ffc96fff7ca749e80 b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/f/a/fa2ac87563a7f02291ea933ffc96fff7ca749e80
new file mode 100644
index 0000000..e69de29
diff --git a/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/index.pb b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/index.pb
new file mode 100644
index 0000000..4eff3c4
--- /dev/null
+++ b/zz_code/gtask/data/.idea/sonarlint/securityhotspotstore/index.pb
@@ -0,0 +1,13 @@
+
+=
+
MetaData.java,f\a\fa2ac87563a7f02291ea933ffc96fff7ca749e80
+9
+ Node.java,e\d\ed02129552b2e83baf49343541491561975ba1ea
+<
+SqlData.java,f\9\f97a970974b4caa5a4cebaa56b3baae5059b6324
+<
+SqlNote.java,6\c\6cb06ae04ce8f51c8bb9004d1daa08b7819cabcd
+9
+ Task.java,2\9\299b8fefb8e07955453bf475fb724aefbb521c56
+=
+
TaskList.java,a\8\a8f9d13ce198840c1f6a37c4e30b69f5d3e9ab04
\ No newline at end of file
diff --git a/zz_code/gtask/data/.idea/vcs.xml b/zz_code/gtask/data/.idea/vcs.xml
new file mode 100644
index 0000000..c2365ab
--- /dev/null
+++ b/zz_code/gtask/data/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/zz_code/gtask/data/MetaData.java b/zz_code/gtask/data/MetaData.java
deleted file mode 100644
index bc07419..0000000
--- a/zz_code/gtask/data/MetaData.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.micode.notes.gtask.data;//包名声明:路径"net.micode.notes.gtask.data",文件中定义的类和接口都归属于这个包
-
-import org.json.JSONException; //引入"org.json.JSONException"类,用于处理JSON格式数据的异常
-import org.json.JSONObject; //表示和操作JSON对象
-
-import android.database.Cursor;//导入Android平台的数据库Cursor类用于从数据库中检索数据记录并对结果进行管理和遍历。
-import android.util.Log;//引入工具类Log来存放一些通用的、与业务逻辑无关的工具方法
-import net.micode.notes.tool.GTaskStringUtils;//导入 GTaskStringUtils工具类
-
-public class MetaData extends Task {
- private final static String TAG = MetaData.class.getSimpleName(); // 用于在日志中标识当前类的名称
-
- private String mRelatedGid = null;
-
- public void setMeta(String gid, JSONObject metaInfo) {
- try {
- metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
- } catch (JSONException e) { // 如果出现 JSONException 异常,则会捕获并记录日志
- Log.e(TAG, "failed to put related gid");
- }
- // try-catch 块中,将键值对 (GTaskStringUtils.META_HEAD_GTASK_ID, gid) 添加到传入的 metaInfo
- // JSON 对象中。
-
- setNotes(metaInfo.toString());
- setName(GTaskStringUtils.META_NOTE_NAME);
- }
-
- public String getRelatedGid() {
- return mRelatedGid;
- }
-
- @Override
- // 是一个Java注解,用于告诉编译器该方法是重写父类或接口中的方法。
- public boolean isWorthSaving() {
- return getNotes() != null;
- }
-
- @Override
- public void setContentByRemoteJSON(JSONObject js) {
- super.setContentByRemoteJSON(js); // 调用父类的方法,传入参数js
- if (getNotes() != null) {
- String notes = getNotes().trim(); // 获取notes并去除首尾空格
- try {
- JSONObject metaInfo = new JSONObject(notes); // 转化为JSONObject对象
- mRelatedGid = metaInfo.optString(GTaskStringUtils.META_HEAD_GTASK_ID, null); // 提取特征字段
- } catch (JSONException e) {
- Log.w(TAG, "failed to get related gid", e);
- mRelatedGid = null;
- }
- }
- }
-
- // 以下三段表示不应该被调用,如果调用了,抛出了一个IllegalAccessError异常,并提供了错误消息
-
- @Override
- public void setContentByLocalJSON(JSONObject js) {
- // this function should not be called
- throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
- }
-
- @Override
- public JSONObject getLocalJSONFromContent() {
- throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
- }
-
- @Override
- public int getSyncAction(Cursor c) {
- throw new IllegalAccessError("MetaData:getSyncAction should not be called");
- }
-
-}
diff --git a/zz_code/gtask/data/Node.java b/zz_code/gtask/data/Node.java
deleted file mode 100644
index 3f79681..0000000
--- a/zz_code/gtask/data/Node.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.micode.notes.gtask.data;
-
-import org.json.JSONObject;
-
-import android.database.Cursor;
-
-public abstract class Node {
- public static final int SYNC_ACTION_NONE = 0;// 本地和云端都无可更新内容(即本地和云端内容一致)
-
- public static final int SYNC_ACTION_ADD_REMOTE = 1;// 在远程云端增加内容
-
- public static final int SYNC_ACTION_ADD_LOCAL = 2;// 在本地增加内容
-
- public static final int SYNC_ACTION_DEL_REMOTE = 3;// 在云端删除内容
-
- public static final int SYNC_ACTION_DEL_LOCAL = 4;// 在本地删除内容
-
- public static final int SYNC_ACTION_UPDATE_REMOTE = 5;// 本地上传云端
-
- public static final int SYNC_ACTION_UPDATE_LOCAL = 6;// 云端更新本地
-
- public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 同步出现冲突
-
- public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误
-
- // 定义了Node类中的私有字段
- private String mGid; // 唯一标识符
-
- private String mName; // 名称
-
- private long mLastModified; // 最后一次修改时间
-
- private boolean mDeleted; // 是否删除
-
- public Node() {
- mGid = null;
- mName = "";
- mLastModified = 0;
- mDeleted = false;
- }// 初始化
-
- public abstract JSONObject getCreateAction(int actionId); // 根据给定的 actionId 返回一个 JSON 对象,表示创建操作
-
- public abstract JSONObject getUpdateAction(int actionId); // 根据给定的 actionId 返回一个 JSON 对象,表示更新操作
-
- public abstract void setContentByRemoteJSON(JSONObject js); // 根据远程的 JSON 对象设置内容
-
- public abstract void setContentByLocalJSON(JSONObject js); // 根据本地的 JSON 对象设置内容
-
- public abstract JSONObject getLocalJSONFromContent(); // 返回一个 JSON 对象,表示从当前内容中获取本地 JSON 数据
-
- public abstract int getSyncAction(Cursor c); // 根据给定的 Cursor 返回一个 JSON 对象,表示同步操作
-
- // 设置相关信息
- public void setGid(String gid) {
- this.mGid = gid;
- }
-
- public void setName(String name) {
- this.mName = name;
- }
-
- public void setLastModified(long lastModified) {
- this.mLastModified = lastModified;
- }
-
- public void setDeleted(boolean deleted) {
- this.mDeleted = deleted;
- }
-
- // 获取相关信息
- public String getGid() {
- return this.mGid;
- }
-
- public String getName() {
- return this.mName;
- }
-
- public long getLastModified() {
- return this.mLastModified;
- }
-
- public boolean getDeleted() {
- return this.mDeleted;
- }
-
-}
diff --git a/zz_code/gtask/data/SqlData.java b/zz_code/gtask/data/SqlData.java
deleted file mode 100644
index a126b6e..0000000
--- a/zz_code/gtask/data/SqlData.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.micode.notes.gtask.data;
-
-import java.util.Objects;
-import java.util.function.Function;
-
-import javax.naming.Context;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import android.content.ContentResolver; //应用程序需要访问其他应用的数据或者系统提供的数据时,就会使用ContentResolver来进行数据访问操作
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.database.Cursor;
-import android.net.Uri;
-import android.util.Log;
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.DataColumns;
-import net.micode.notes.data.Notes.DataConstants;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.data.NotesDatabaseHelper.TABLE;
-import net.micode.notes.gtask.exception.ActionFailureException;
-
-//数据库中基本数据,方法包括读取数据、获取数据库中数据、提交数据到数据库
-
-public class SqlData {
- private static final String TAG = SqlData.class.getSimpleName(); // 得到类的简写名称存入字符串TAG中
-
- private static final int INVALID_ID = -99999;
-
- public static final String[] PROJECTION_DATA = new String[] {
- DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
- DataColumns.DATA3
- // DataColumns.ID:表示查询结果中每个数据行的唯一标识符。
- // DataColumns.MIME_TYPE:表示查询结果中每个数据行的MIME类型。
- // DataColumns.CONTENT:表示查询结果中每个数据行的内容。 标识不同的数据列
- // DataColumns.DATA1:表示查询结果中每个数据行的第一个数据项。
- // DataColumns.DATA3:表示查询结果中每个数据行的第三个数据项。
- };
-
- public static final int DATA_ID_COLUMN = 0;
-
- public static final int DATA_MIME_TYPE_COLUMN = 1;
-
- public static final int DATA_CONTENT_COLUMN = 2;
-
- public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
-
- public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
- // 每个数据行中各个信息的位置
-
- private ContentResolver mContentResolver;
-
- private boolean mIsCreate;
-
- private long mDataId;
-
- private String mDataMimeType;
-
- private String mDataContent;
-
- private long mDataContentData1;
-
- private String mDataContentData3;
-
- private ContentValues mDiffDataValues;
-
- public SqlData(Context context) {
- mContentResolver = context.getContentResolver();
- mIsCreate = true;
- mDataId = INVALID_ID;
- mDataMimeType = DataConstants.NOTE;
- mDataContent = "";
- mDataContentData1 = 0;
- mDataContentData3 = "";
- mDiffDataValues = new ContentValues();
- } // 初始化SqlData对象的字段和属性
-
- public SqlData(Context context, Cursor c) {
- mContentResolver = context.getContentResolver();
- mIsCreate = false;
- loadFromCursor(c);
- mDiffDataValues = new ContentValues();
- } // 传入c,初始化数据
-
- private void loadFromCursor(Cursor c) {
- mDataId = c.getLong(DATA_ID_COLUMN);
- mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
- mDataContent = c.getString(DATA_CONTENT_COLUMN);
- mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
- mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
- } // 从传入的 Cursor 对象中加载数据并设置给类中的字段,具体来说,根据 Cursor 中的列索引,将特定列的值提取出来
-
- public void setContent(JSONObject js) throws JSONException {
- setDataValue(js, DataColumns.ID, mDataId, Long::parseLong);
- setDataValue(js, DataColumns.MIME_TYPE, mDataMimeType, Function.identity());
- setDataValue(js, DataColumns.CONTENT, mDataContent, Function.identity());
- setDataValue(js, DataColumns.DATA1, mDataContentData1, Long::parseLong);
- setDataValue(js, DataColumns.DATA3, mDataContentData3, Function.identity());
- }
-
- private void setDataValue(JSONObject jsonObject, String key, T currentValue, Function parser)
- throws JSONException {
- T newValue = jsonObject.has(key) ? parser.apply(jsonObject.getString(key)) : null;
- if (mIsCreate || !Objects.equals(currentValue, newValue)) {
- mDiffDataValues.put(key, newValue);
- }
- setFieldValue(key, newValue);
- }
-
- private void setFieldValue(String key, Object value) {
- switch (key) {
- case DataColumns.ID:
- mDataId = (Long) value;
- break;
- case DataColumns.MIME_TYPE:
- mDataMimeType = (String) value;
- break;
- case DataColumns.CONTENT:
- mDataContent = (String) value;
- break;
- case DataColumns.DATA1:
- mDataContentData1 = (Long) value;
- break;
- case DataColumns.DATA3:
- mDataContentData3 = (String) value;
- break;
- }
- }
-
- public JSONObject getContent() throws JSONException { // 获取对象的内容并返回一个 JSON格式的对象。
- if (mIsCreate) {
- Log.e(TAG, "it seems that we haven't created this in database yet");
- return null;
- }
- JSONObject js = new JSONObject();
- js.put(DataColumns.ID, mDataId);
- js.put(DataColumns.MIME_TYPE, mDataMimeType);
- js.put(DataColumns.CONTENT, mDataContent);
- js.put(DataColumns.DATA1, mDataContentData1);
- js.put(DataColumns.DATA3, mDataContentData3);
- return js;
- // 首先判断变量 mIsCreate 的值,如果为 true,表示当前对象还未在数据库中创建,则记录错误日志并返回 null。
- // 如果对象在数据库中已经创建,则创建一个新的 JSONObject 对象 js。
- // 将对象中的数据以键值对的形式存储到 JSON 对象 js 中,键包括 DataColumns.ID等,对应的值分别为对象中的 mDataId等
- // 最后返回构建好的 JSON 对象 js
- }
-
- public void commit(long noteId, boolean validateVersion, long version) {
- if (mIsCreate) { // 如果是创建操作
- // 判断是否需要移除无效的ID
- if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
- mDiffDataValues.remove(DataColumns.ID);
- }
- // 将笔记ID放入差异数据值中
- mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
- // 插入数据并获取新的数据ID
- Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
- try {
- mDataId = Long.parseLong(uri.getLastPathSegment());
- } catch (NumberFormatException e) {
- Log.e(TAG, "Get note id error: " + e.toString());
- throw new ActionFailureException("Failed to create note");
- }
- } else { // 如果不是创建操作
- // 如果有差异数据值需要更新
- if (!mDiffDataValues.isEmpty()) {
- int result = 0;
- // 根据是否需要验证版本号决定更新方式
- if (!validateVersion) {
- result = mContentResolver.update(ContentUris.withAppendedId(
- Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
- } else {
- // 使用版本号验证更新数据
- result = mContentResolver.update(ContentUris.withAppendedId(
- Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
- NoteColumns.ID + " IN (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
- + " WHERE " + NoteColumns.ID + "=? AND " + NoteColumns.VERSION + "=? )",
- new String[] { String.valueOf(noteId), String.valueOf(version) });
- }
- // 如果没有更新数据,则打印警告信息
- if (result == 0) {
- Log.w(TAG, "No data update. Perhaps the user has updated the note while syncing.");
- }
- }
- }
-
- // 清空差异数据值并标记不再是创建操作
- mDiffDataValues.clear();
- mIsCreate = false;
- }
-
- public long getId() {
- return mDataId;
- }
-}
diff --git a/zz_code/gtask/data/TaskList.java b/zz_code/gtask/data/TaskList.java
deleted file mode 100644
index a8a25bf..0000000
--- a/zz_code/gtask/data/TaskList.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.micode.notes.gtask.data;
-
-import android.database.Cursor;
-import android.util.Log;
-
-import net.micode.notes.data.Notes;
-import net.micode.notes.data.Notes.NoteColumns;
-import net.micode.notes.gtask.exception.ActionFailureException;
-import net.micode.notes.tool.GTaskStringUtils;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-
-// TaskList类继承自Node类
-public class TaskList extends Node {
- // 定义一个静态的字符串TAG,用于调试
- private static final String TAG = TaskList.class.getSimpleName();
- // 定义一个整型变量mIndex,用于存储索引
- private int mIndex;
- // 定义一个Task类型的ArrayList对象mChildren,用于存储Task对象
- private ArrayList mChildren;
- // 定义一个TaskList构造函数,无参数
- public TaskList() {
- super();
- mChildren = new ArrayList();
- mIndex = 1;
- }
- // 定义一个TaskList构造函数,参数为String类型的name
- public JSONObject getCreateAction(int actionId) {
- JSONObject js = new JSONObject();
- // 尝试
- try {
- // action_type
- // 将键值对action_type和GTASK_JSON_ACTION_TYPE_CREATE放入js中
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
-
- // action_id
- // 将键值对action_id和actionId放入js中
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // index
- // 将键值对index和mIndex放入js中
- js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
-
- // entity_delta
- // 创建一个JSONObject对象entity
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
- entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
- GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
- // 捕获JSONException异常
- } catch (JSONException e) {
- // 打印异常信息
- Log.e(TAG, e.toString());
- // 打印异常堆栈信息
- e.printStackTrace();
- // 抛出ActionFailureException异常
- throw new ActionFailureException("fail to generate tasklist-create jsonobject");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate tasklist-create jsonobject");
- }
-
- return js;
- }
- // 定义一个JSONObject类型的方法getUpdateAction,参数为整型的actionId
- public JSONObject getUpdateAction(int actionId) {
- JSONObject js = new JSONObject();
- // 尝试
- try {
- // action_type
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
- GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
-
- // action_id
- js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
-
- // id
- js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
-
- // entity_delta
- JSONObject entity = new JSONObject();
- entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
- entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
- js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
- // 捕获JSONException异常
- } catch (JSONException e) {
- // 打印异常信息
- Log.e(TAG, e.toString());
- // 打印异常堆栈信息
- e.printStackTrace();
- // 抛出ActionFailureException异常
- throw new ActionFailureException("fail to generate tasklist-update jsonobject");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to generate tasklist-update jsonobject");
- }
- // 返回js
- return js;
- }
- // 定义一个JSONObject类型的方法getDeleteAction,参数为整型的actionId
- public void setContentByRemoteJSON(JSONObject js) {
- if (js != null) {
- try {
- // id
- if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
- setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
- }
- // deleted
- // last_modified
- if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
- setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
- }
-
- // name
- if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
- setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
- }
- // 捕获JSONException异常
- } catch (JSONException e) {
- // 打印异常信息
- Log.e(TAG, e.toString());
- // 打印异常堆栈信息
- e.printStackTrace();
- // 抛出ActionFailureException异常
- throw new ActionFailureException("fail to get tasklist content from jsonobject");
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- throw new ActionFailureException("fail to get tasklist content from jsonobject");
- }
- }
- }
- // 定义一个JSONObject类型的方法getLocalJSONFromContent
- public void setContentByLocalJSON(JSONObject js) {
- if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
- Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
- }
- // 尝试
- try {
- JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
- // name of the folder is the snippet of the note
- if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
- String name = folder.getString(NoteColumns.SNIPPET);
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
- } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
- if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
- else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
- setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
- + GTaskStringUtils.FOLDER_CALL_NOTE);
- else
- Log.e(TAG, "invalid system folder");// invalid system folder
- } else {// invalid type
- Log.e(TAG, "error type");
- }
- // 捕获JSONException异常
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
- }
- // 定义一个JSONObject类型的方法getLocalJSONFromContent
- public JSONObject getLocalJSONFromContent() {
- // 尝试
- try {
- JSONObject js = new JSONObject();
- JSONObject folder = new JSONObject();
- // 文件夹的名称是注释的代码段
- String folderName = getName();
- // 将键值对id和getId放入folder中
- if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
- folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
- folderName.length());
- folder.put(NoteColumns.SNIPPET, folderName);
- // 如果文件夹的名称是默认的或者是通话记录
- if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT)
- || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE))
- folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
- else// 否则,文件夹的类型是文件夹
- folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
-
- js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
-
- return js;
- // 捕获JSONException异常
- } catch (JSONException e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- return null;
- }
- }
- // 定义一个整型的方法getSyncAction,参数为Cursor类型的c
- public int getSyncAction(Cursor c) {
- try {
- // 如果Cursor对象c为空
- if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
- // there is no local update
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // no update both side
- return SYNC_ACTION_NONE;
- } else {
- // apply remote to local
- return SYNC_ACTION_UPDATE_LOCAL;
- }
- } else {
-
- // 验证 GTASK ID
- if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
- Log.e(TAG, "gtask id doesn't match");
- return SYNC_ACTION_ERROR;
- }
- // 局部修改
- if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
- // 仅限本地修改
- return SYNC_ACTION_UPDATE_REMOTE;
- } else {
- // 对于文件夹冲突,只需应用本地修改
- return SYNC_ACTION_UPDATE_REMOTE;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, e.toString());
- e.printStackTrace();
- }
-
- return SYNC_ACTION_ERROR;
- }
- // 定义一个整型的方法getSyncAction,参数为TaskList类型的t
- public int getChildTaskCount() {
- return mChildren.size();
- }
- // 定义一个布尔型的方法addChildTask,参数为Task类型的task
- public boolean addChildTask(Task task) {
- boolean ret = false;
- // 如果task不为空且mChildren不包含task
- if (task != null && !mChildren.contains(task)) {
- ret = mChildren.add(task);
- if (ret) {
- // 需要设置先前的兄弟姐妹和父级
- task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
- .get(mChildren.size() - 1));
- task.setParent(this);
- }
- }
- return ret;
- }
- // 定义一个布尔型的方法addChildTask,参数为Task类型的task和整型的index
- public boolean addChildTask(Task task, int index) {
- if (index < 0 || index > mChildren.size()) {
- Log.e(TAG, "add child task: invalid index");
- return false;
- }
- // 如果task不为空且mChildren不包含task
- int pos = mChildren.indexOf(task);
- if (task != null && pos == -1) {
- mChildren.add(index, task);
-
- // 更新任务列表
- Task preTask = null;
- Task afterTask = null;
- // 如果index不等于0
- if (index != 0)
- preTask = mChildren.get(index - 1);
- // 如果index不等于mChildren.size() - 1
- if (index != mChildren.size() - 1)
- afterTask = mChildren.get(index + 1);
- // 需要设置先前的兄弟姐妹和父级
- task.setPriorSibling(preTask);
- if (afterTask != null)
- afterTask.setPriorSibling(task);
- }
-
- return true;
- }
- // 定义一个布尔型的方法removeChildTask,参数为Task类型的task
- public boolean removeChildTask(Task task) {
- boolean ret = false;
- int index = mChildren.indexOf(task);
- if (index != -1) {
- ret = mChildren.remove(task);
- // 如果ret为真
- if (ret) {
- // 重置先前的兄弟姐妹和父级
- task.setPriorSibling(null);
- task.setParent(null);
-
- // 更新任务列表
- if (index != mChildren.size()) {
- mChildren.get(index).setPriorSibling(
- index == 0 ? null : mChildren.get(index - 1));
- }
- }
- }
- return ret;
- }
- // 定义一个布尔型的方法moveChildTask,参数为Task类型的task和整型的index
- public boolean moveChildTask(Task task, int index) {
- // 如果index小于0或者index大于等于mChildren.size()
- if (index < 0 || index >= mChildren.size()) {
- Log.e(TAG, "move child task: invalid index");
- return false;
- }
- // 定义一个整型变量pos,用于存储mChildren中task的位置
- int pos = mChildren.indexOf(task);
- if (pos == -1) {
- Log.e(TAG, "move child task: the task should in the list");
- return false;
- }
- // 如果pos等于index
- if (pos == index)
- return true;
- return (removeChildTask(task) && addChildTask(task, index));
- }
- // 定义一个Task类型的方法findChildTaskByGid,参数为String类型的gid
- public Task findChildTaskByGid(String gid) {
- for (int i = 0; i < mChildren.size(); i++) {
- Task t = mChildren.get(i);
- if (t.getGid().equals(gid)) {
- return t;
- }
- }
- return null;
- }
- // 定义一个整型的方法getChildTaskIndex,参数为Task类型的task
- public int getChildTaskIndex(Task task) {
- return mChildren.indexOf(task);
- }
- // 定义一个Task类型的方法getChildTaskByIndex,参数为整型的index
- public Task getChildTaskByIndex(int index) {
- if (index < 0 || index >= mChildren.size()) {
- Log.e(TAG, "getTaskByIndex: invalid index");
- return null;
- }
- // 返回mChildren中的index位置的Task对象
- return mChildren.get(index);
- }
- // 定义一个Task类型的方法getChilTaskByGid,参数为String类型的gid
- public Task getChilTaskByGid(String gid) {
- for (Task task : mChildren) {
- if (task.getGid().equals(gid))
- return task;
- }
- return null;
- }
- // 定义一个ArrayList类型的方法getChildTaskList
- public ArrayList getChildTaskList() {
- return this.mChildren;
- }
- // 定义一个整型的方法getIndex
- public void setIndex(int index) {
- this.mIndex = index;
- }
- // 定义一个整型的方法getIndex
- public int getIndex() {
- return this.mIndex;
- }
-}
diff --git a/zz_code/gtask/data/data.iml b/zz_code/gtask/data/data.iml
new file mode 100644
index 0000000..5278d65
--- /dev/null
+++ b/zz_code/gtask/data/data.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file