diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 7efc0ae..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Notes-master \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 47f3303..9e8b972 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,8 +3,8 @@ apply plugin: 'com.android.application' android { useLibrary 'org.apache.http.legacy' namespace "net.micode.notes" - compileSdkVersion 33 - buildToolsVersion "33.0.2" + compileSdkVersion 30 + buildToolsVersion "30.0.2" defaultConfig { applicationId "net.micode.notes" diff --git a/app/read.md b/app/read.md new file mode 100644 index 0000000..e69de29 diff --git a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java index 3a2050b..ff61c3b 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/MetaData.java +++ b/app/src/main/java/net/micode/notes/gtask/data/MetaData.java @@ -4,7 +4,6 @@ * 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 @@ -27,19 +26,24 @@ import org.json.JSONObject; public class MetaData extends Task { private final static String TAG = MetaData.class.getSimpleName(); - + //相关GTask任务的ID private String mRelatedGid = null; + //设置元数据,传入gid和元数据的JSONObject public void setMeta(String gid, JSONObject metaInfo) { + //向元数据中加入相关GTaskID try { metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); } catch (JSONException e) { Log.e(TAG, "failed to put related gid"); } + //设置笔记内容为元数据的JSON字符串 setNotes(metaInfo.toString()); + //设置笔记名称 setName(GTaskStringUtils.META_NOTE_NAME); } + //获取相关GTask任务的ID public String getRelatedGid() { return mRelatedGid; } @@ -49,11 +53,15 @@ public class MetaData extends Task { return getNotes() != null; } + //从远程同步的数据中获取内容 @Override public void setContentByRemoteJSON(JSONObject js) { + //调用父类方法 super.setContentByRemoteJSON(js); + //如果有笔记内容 if (getNotes() != null) { try { + //解析笔记内容,获取相关GTask任务ID JSONObject metaInfo = new JSONObject(getNotes().trim()); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); } catch (JSONException e) { @@ -65,18 +73,20 @@ public class MetaData extends Task { @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"); } -} +} \ 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..2843a63 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 @@ -88,7 +88,7 @@ public class SqlData { loadFromCursor(c); mDiffDataValues = new ContentValues(); } - + //加载数据 private void loadFromCursor(Cursor c) { mDataId = c.getLong(DATA_ID_COLUMN); mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); @@ -96,7 +96,11 @@ public class SqlData { mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN); mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); } - + /** + * 设置内容 + * @param js JSON对象 + * @throws JSONException + */ public void setContent(JSONObject js) throws JSONException { long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; if (mIsCreate || mDataId != dataId) { @@ -129,7 +133,11 @@ public class SqlData { } mDataContentData3 = dataContentData3; } - + /** + * 获取内容 + * @return JSON对象 + * @throws JSONException + */ public JSONObject getContent() throws JSONException { if (mIsCreate) { Log.e(TAG, "it seems that we haven't created this in database yet"); @@ -144,6 +152,12 @@ public class SqlData { return js; } + /** + * 提交 + * @param noteId 笔记ID + * @param validateVersion 是否校验版本 + * @param version 版本 + */ public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { 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..abb272f 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 @@ -199,7 +199,9 @@ public class SqlNote { mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); mVersion = c.getLong(VERSION_COLUMN); } - + /** + * 加载数据内容 + */ private void loadDataContent() { Cursor c = null; mDataList.clear(); @@ -225,7 +227,11 @@ public class SqlNote { c.close(); } } - + /** + * 设置内容 + * @param js JSON对象 + * @return 是否设置成功 + */ public boolean setContent(JSONObject js) { try { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); @@ -358,7 +364,10 @@ public class SqlNote { } return true; } - + /** + * 获取内容 + * @return JSON对象 + */ public JSONObject getContent() { try { JSONObject js = new JSONObject(); @@ -439,7 +448,10 @@ public class SqlNote { public boolean isNoteType() { return mType == Notes.TYPE_NOTE; } - + /** + * 提交 + * @param validateVersion 是否校验版本 + */ public void commit(boolean validateVersion) { if (mIsCreate) { if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { diff --git a/app/src/main/java/net/micode/notes/gtask/data/Task.java b/app/src/main/java/net/micode/notes/gtask/data/Task.java index 6a19454..ecb5b51 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Task.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Task.java @@ -53,7 +53,11 @@ public class Task extends Node { mParent = null; mMetaInfo = null; } - + /** + * 获取创建操作JSON对象 + * @param actionId 操作ID + * @return JSON对象 + */ public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -102,7 +106,11 @@ public class Task extends Node { return js; } - + /** + * 获取更新操作JSON对象 + * @param actionId 操作ID + * @return JSON对象 + */ public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); @@ -134,7 +142,10 @@ public class Task extends Node { return js; } - + /** + * 根据远程JSON对象设置内容 + * @param js JSON对象 + */ public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { @@ -174,7 +185,10 @@ public class Task extends Node { } } } - + /** + * 根据本地JSON对象设置内容 + * @param js JSON对象 + */ public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) { @@ -203,7 +217,10 @@ public class Task extends Node { e.printStackTrace(); } } - + /** + * 从内容获取本地JSON对象 + * @return JSON对象 + */ public JSONObject getLocalJSONFromContent() { String name = getName(); try { @@ -246,7 +263,10 @@ public class Task extends Node { return null; } } - + /** + * 设置元信息 + * @param metaData 元数据 + */ public void setMetaInfo(MetaData metaData) { if (metaData != null && metaData.getNotes() != null) { try { diff --git a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java index 4ea21c5..2810fad 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/TaskList.java +++ b/app/src/main/java/net/micode/notes/gtask/data/TaskList.java @@ -42,7 +42,11 @@ public class TaskList extends Node { mChildren = new ArrayList(); mIndex = 1; } - + /** + * 获取创建操作JSON对象 + * @param actionId 操作ID + * @return JSON对象 + */ public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -73,7 +77,11 @@ public class TaskList extends Node { return js; } - + /** + * 获取更新操作JSON对象 + * @param actionId 操作ID + * @return JSON对象 + */ public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); @@ -102,7 +110,10 @@ public class TaskList extends Node { return js; } - + /** + * 根据远程JSON对象设置内容 + * @param js JSON对象 + */ public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { @@ -128,7 +139,10 @@ public class TaskList extends Node { } } } - + /** + * 根据本地JSON对象设置内容 + * @param js JSON对象 + */ public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); @@ -156,7 +170,10 @@ public class TaskList extends Node { e.printStackTrace(); } } - + /** + * 从内容获取本地JSON对象 + * @return JSON对象 + */ public JSONObject getLocalJSONFromContent() { try { JSONObject js = new JSONObject(); @@ -182,7 +199,11 @@ public class TaskList extends Node { return null; } } - + /** + * 获取同步操作 + * @param c Cursor + * @return 同步操作 + */ public int getSyncAction(Cursor c) { try { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { @@ -215,11 +236,18 @@ public class TaskList extends Node { return SYNC_ACTION_ERROR; } - + /** + * 获取子任务数 + * @return 子任务数 + */ public int getChildTaskCount() { return mChildren.size(); } - + /** + * 添加子任务 + * @param task 子任务 + * @return 是否成功 + */ public boolean addChildTask(Task task) { boolean ret = false; if (task != null && !mChildren.contains(task)) { @@ -233,7 +261,12 @@ public class TaskList extends Node { } return ret; } - + /** + * 在指定位置添加子任务 + * @param task 子任务 + * @param index 位置 + * @return 是否成功 + */ public boolean addChildTask(Task task, int index) { if (index < 0 || index > mChildren.size()) { Log.e(TAG, "add child task: invalid index"); @@ -259,7 +292,11 @@ public class TaskList extends Node { return true; } - + /** + * 移除子任务 + * @param task 子任务 + * @return 是否成功 + */ public boolean removeChildTask(Task task) { boolean ret = false; int index = mChildren.indexOf(task); @@ -280,7 +317,12 @@ public class TaskList extends Node { } return ret; } - + /** + * 移动子任务位置 + * @param task 子任务 + * @param index 目标位置 + * @return 是否成功 + */ public boolean moveChildTask(Task task, int index) { if (index < 0 || index >= mChildren.size()) { @@ -298,7 +340,11 @@ public class TaskList extends Node { return true; return (removeChildTask(task) && addChildTask(task, index)); } - + /** + * 根据GID查找子任务 + * @param gid GID + * @return 子任务 + */ public Task findChildTaskByGid(String gid) { for (int i = 0; i < mChildren.size(); i++) { Task t = mChildren.get(i); @@ -308,11 +354,19 @@ public class TaskList extends Node { } return null; } - + /** + * 获取子任务位置 + * @param task 子任务 + * @return 位置 + */ public int getChildTaskIndex(Task task) { return mChildren.indexOf(task); } - + /** + * 根据位置获取子任务 + * @param index 位置 + * @return 子任务 + */ public Task getChildTaskByIndex(int index) { if (index < 0 || index >= mChildren.size()) { Log.e(TAG, "getTaskByIndex: invalid index"); @@ -320,7 +374,11 @@ public class TaskList extends Node { } return mChildren.get(index); } - + /** + * 根据GID获取子任务 + * @param gid GID + * @return 子任务 + */ public Task getChilTaskByGid(String gid) { for (Task task : mChildren) { if (task.getGid().equals(gid)) diff --git a/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java b/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java index 15504be..302323b 100644 --- a/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java +++ b/app/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java @@ -15,7 +15,9 @@ */ package net.micode.notes.gtask.exception; - +/** + * 操作失败异常 + */ public class ActionFailureException extends RuntimeException { private static final long serialVersionUID = 4425249765923293627L; @@ -26,7 +28,11 @@ public class ActionFailureException extends RuntimeException { public ActionFailureException(String paramString) { super(paramString); } - + /** + * 构造方法 + * @param paramString 异常信息 + * @param paramThrowable 引起该异常的异常 + */ public ActionFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } diff --git a/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java b/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java index b08cfb1..2b4cf25 100644 --- a/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java +++ b/app/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java @@ -15,7 +15,9 @@ */ package net.micode.notes.gtask.exception; - +/** + * 网络异常 + */ public class NetworkFailureException extends Exception { private static final long serialVersionUID = 2107610287180234136L; @@ -26,7 +28,11 @@ public class NetworkFailureException extends Exception { public NetworkFailureException(String paramString) { super(paramString); } - + /** + * 构造方法 + * @param paramString 异常信息 + * @param paramThrowable 引起该异常的异常 + */ public NetworkFailureException(String paramString, Throwable paramThrowable) { super(paramString, paramThrowable); } diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java index 97123d0..582e730 100644 --- a/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java +++ b/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java @@ -27,7 +27,10 @@ import android.os.AsyncTask; import net.micode.notes.R; import net.micode.notes.ui.NotesListActivity; import net.micode.notes.ui.NotesPreferenceActivity; - +/** + * GTask异步任务 + * + */ public class GTaskASyncTask extends AsyncTask { @@ -44,7 +47,11 @@ public class GTaskASyncTask extends AsyncTask { private GTaskManager mTaskManager; private OnCompleteListener mOnCompleteListener; - + /** + * 构造方法 + * @param context 上下文 + * @param listener 完成监听器 + */ public GTaskASyncTask(Context context, OnCompleteListener listener) { mContext = context; mOnCompleteListener = listener; @@ -52,17 +59,25 @@ public class GTaskASyncTask extends AsyncTask { .getSystemService(Context.NOTIFICATION_SERVICE); mTaskManager = GTaskManager.getInstance(); } - - public void cancelSync() { + /** + * 取消同步操作 + */ public void cancelSync() { mTaskManager.cancelSync(); } - + /** + * 发布进度 + * @param message 消息 + */ public void publishProgess(String message) { publishProgress(new String[] { message }); } - + /** + * 显示通知 + * @param tickerId 通知ID + * @param content 内容 + */ private void showNotification(int tickerId, String content) { Notification notification = new Notification(R.drawable.notification, mContext .getString(tickerId), System.currentTimeMillis()); diff --git a/app/src/main/java/net/micode/notes/model/Note.java b/app/src/main/java/net/micode/notes/model/Note.java index 6706cf6..34227f6 100644 --- a/app/src/main/java/net/micode/notes/model/Note.java +++ b/app/src/main/java/net/micode/notes/model/Note.java @@ -14,6 +14,17 @@ * limitations under the License. */ +/** + * 1. Note类代表一个便签,它包含两部分数据: + * - mNoteDiffValues:便签的基本信息,如标题、创建时间等,存储在SQLite中的notes表 + * - mNoteData:便签的文本内容或通话记录等详细数据,存储在SQLite中的data表 + * 2. Note类提供了许多方法来设置mNoteDiffValues和mNoteData,以更新便签信息和详细数据。 + * 3. Note类的syncNote方法用来同步便签信息和详细数据到数据库。它会先更新notes表,然后插入或更新data表中的详细数据。 + * 4. NoteData类表示详细数据,它包含文本数据(存储在mTextDataValues)和通话记录数据(存储在mCallDataValues)。 + * 5. NoteData类也提供了许多方法来设置文本数据和通话记录数据到mTextDataValues和mCallDataValues。 + * 6. NoteData类的pushIntoContentResolver方法会将mTextDataValues和mCallDataValues中的数据插入或更新到data表中。 + */ + package net.micode.notes.model; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; @@ -41,6 +52,13 @@ public class Note { /** * Create a new note id for adding a new note to databases */ + /** + * 获取新便签ID + * + * @param context 上下文 + * @param folderId 文件夹ID + * @return 新便签ID + */ public static synchronized long getNewNoteId(Context context, long folderId) { // Create a new note in the database ContentValues values = new ContentValues(); @@ -70,24 +88,49 @@ public class Note { mNoteData = new NoteData(); } + /** + * 设置便签值 + * + * @param key 键 + * @param value 值 + */ public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + /** + * 设置文本数据 + * + * @param key 键 + * @param value 值 + */ public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } - + /** + * 设置文本数据ID + * + * @param id ID + */ public void setTextDataId(long id) { mNoteData.setTextDataId(id); } - + /** + * 设置通话数据ID + * + * @param id ID + */ public long getTextDataId() { return mNoteData.mTextDataId; } - + /** + * 设置通话数据 + * + * @param key 键 + * @param value 值 + */ public void setCallDataId(long id) { mNoteData.setCallDataId(id); } @@ -95,11 +138,17 @@ public class Note { public void setCallData(String key, String value) { mNoteData.setCallData(key, value); } - + /**是否本地修改*/ public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } - + /** + * 同步便签 + * + * @param context 上下文 + * @param noteId 便签ID + * @return 是否同步成功 + */ public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId);