data包和gtask包中data子包的标注

pull/10/head
djq 11 months ago
parent 0a0c035905
commit 5ac24f2052

@ -37,7 +37,14 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: SqlNote
* @Description:
* SqlNote便便
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 1718 PM
*/
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
@ -52,9 +59,9 @@ public class SqlNote {
NoteColumns.VERSION
};
public static final int ID_COLUMN = 0;
public static final int ID_COLUMN = 0;//便签的ID列的索引为0
public static final int ALERTED_DATE_COLUMN = 1;
public static final int ALERTED_DATE_COLUMN = 1;//提醒日期列的索引为1
public static final int BG_COLOR_ID_COLUMN = 2;
@ -120,8 +127,12 @@ public class SqlNote {
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
private ArrayList<SqlData> mDataList;//用Java中的ArrayList类定义了一个SqlData对象 mDataList用于存储从数据库查询中返回的便签数据
/**
* SqlNote SqlNote
* @param context 使
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -143,6 +154,11 @@ public class SqlNote {
mDataList = new ArrayList<SqlData>();
}
/**
* SqlNote Cursor
* @param context 使
* @param c
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -154,6 +170,11 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
/**
* SqlNote ID
* @param context 使
* @param id 便ID
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -166,8 +187,17 @@ public class SqlNote {
}
/**
* ID 便 SqlNote
* @param id 便 ID
*/
private void loadFromCursor(long id) {
Cursor c = null;
/**
* try-finally
*
* finally
*/
try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] {
@ -185,6 +215,10 @@ public class SqlNote {
}
}
/**
* 便 SqlNote
* @param c
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -200,9 +234,17 @@ public class SqlNote {
mVersion = c.getLong(VERSION_COLUMN);
}
/**
* ID
* 便
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
/**
* ID mDataList
*
*/
try {
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] {
@ -226,7 +268,19 @@ public class SqlNote {
}
}
/**
* JSONObject
* JSONObjectmDiffNoteValues
* @param js JSONObject
* @return truefalse
*/
public boolean setContent(JSONObject js) {
/**
* tryJSONJSONExceptioncatch
* catchfalse
*
*/
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
@ -237,14 +291,14 @@ public class SqlNote {
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
}//判断是否需要更新笔记的摘要snippet。它通过比较当前对象的mSnippet属性和传入的参数snippet如果两者不相等则将新的摘要值存储在mDiffNoteValues中。
mSnippet = snippet;
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type);
}
}//检查是否正在创建新的笔记mIsCreate为true或者当前笔记的类型与传入的类型值不相等mType != type。如果满足其中一个条件就会将新的类型值存储在mDiffNoteValues中。
mType = type;
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
@ -359,6 +413,10 @@ public class SqlNote {
return true;
}
/**
* JSON
* @return JSONObject
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
@ -407,39 +465,74 @@ public class SqlNote {
return null;
}
/**
* IDmDiffNoteValues
* @param id longID
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/**
* Google TasksIDgidmDiffNoteValues便
* @param gid Google TasksID
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/**
* IDsyncIdmDiffNoteValues便
* @param syncId longID
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/**
*
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/**
* ID
* @return ID
*/
public long getId() {
return mId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
* 便
* @return 便便truefalse
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
*
* @param validateVersion true
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -31,7 +31,16 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: Task
* @Description:
* TaskNodeGoogle使
*
* JSON便Google
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 1948 PM
*/
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
@ -45,17 +54,27 @@ public class Task extends Node {
private TaskList mParent;
/**
*
* null
*/
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;
mParent = null;
mMetaInfo = null;
super();//调用父类Node的构造方法确保父类的属性得到正确初始化
mCompleted = false;//任务完成状态设置为未完成
mNotes = null;//暂时没有便签笔记
mPriorSibling = null;//当前任务没有前节点
mParent = null;//当前任务没有父节点
mMetaInfo = null;//当前任务没有元数据信息
}
/**
* JSON
* JSONActionFailureException
* @param actionId
* @return JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
JSONObject js = new JSONObject();//创建一个空的JSONObject对象。
try {
// action_type
@ -97,12 +116,17 @@ public class Task extends Node {
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate task-create jsonobject");
throw new ActionFailureException("fail to generate task-create jsonobject");//抛出异常
}
return js;
}
/**
* JSON
* @param actionId
* @return JSONObject
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -135,6 +159,11 @@ public class Task extends Node {
return js;
}
/**
* JSONObject
* JSON
* @param js JSONObject
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -175,17 +204,25 @@ public class Task extends Node {
}
}
/**
* JSONObject
* @param js
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
}
/**
* JSONObject
* 便便
*/
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {//检查便签类型是不是普通便签
Log.e(TAG, "invalid type");
return;
}
@ -204,6 +241,11 @@ public class Task extends Node {
}
}
/**
* JSONObject
* @return JSONObjectjs
* mMetaInfo
*/
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
@ -247,6 +289,10 @@ public class Task extends Node {
}
}
/**
*
* @param metaData MetaData
*/
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
@ -258,6 +304,16 @@ public class Task extends Node {
}
}
/**
* Cursor
* @param c Cursorc
* @return
* SYNC_ACTION_NONE
* SYNC_ACTION_UPDATE_LOCAL
* SYNC_ACTION_UPDATE_REMOTE
* SYNC_ACTION_UPDATE_CONFLICT
* SYNC_ACTION_ERROR
*/
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
@ -311,39 +367,80 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return booleantruefalse
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
/**
*
* 便
* @param completed boolean
*/
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
/**
*
* 便
* @param notes String
*/
public void setNotes(String notes) {
this.mNotes = notes;
}
/**
*
*
* @param priorSibling Task
*/
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
/**
*
*
* @param parent TaskList
*/
public void setParent(TaskList parent) {
this.mParent = parent;
}
/**
*
* 便
* @return booleantruefalse
*/
public boolean getCompleted() {
return this.mCompleted;
}
/**
*
* @return String
*/
public String getNotes() {
return this.mNotes;
}
/**
*
* @return Tasknull
*/
public Task getPriorSibling() {
return this.mPriorSibling;
}
/**
*
* @return TaskListnull
*/
public TaskList getParent() {
return this.mParent;
}

@ -30,19 +30,36 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Package: net.micode.notes.gtask.data
* @ClassName: TaskList
* @Description:
* TaskListNode
* JSON
* @Author: Dong Jiaqi
* @CreateDate: 12/24/2023 2048 PM
*/
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
private static final String TAG = TaskList.class.getSimpleName();//私有静态常量,用于在日志和调试中标识类名。
private int mIndex;
private int mIndex;//私有整型变量,表示任务列表的索引。
private ArrayList<Task> mChildren;
private ArrayList<Task> mChildren;//私有ArrayList存储Task对象表示该任务列表下的子任务列表。
/**
* mChildrenTaskmIndex1
*/
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
/**
* actionIdJSONObject
* @param actionId ID
* @return JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +91,11 @@ public class TaskList extends Node {
return js;
}
/**
* actionIdJSONObject
* @param actionId ID
* @return JSONObject
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -103,6 +125,10 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
* @param js JSONObject
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -129,6 +155,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @param js JSONObject
*/
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -157,6 +187,10 @@ public class TaskList extends Node {
}
}
/**
* JSON
* @return JSONObject
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -183,6 +217,17 @@ public class TaskList extends Node {
}
}
/**
*
* @param c Cursor
* @return
* SYNC_ACTION_NONE
* SYNC_ACTION_UPDATE_LOCAL
* SYNC_ACTION_ERROR
* SYNC_ACTION_UPDATE_REMOTEID,
* SYNC_ACTION_UPDATE_REMOTEID,
* SYNC_ACTION_ERROR
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -216,10 +261,19 @@ public class TaskList extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
* @return
*/
public int getChildTaskCount() {
return mChildren.size();
}
/**
*
* @param task
* @return boolean:truefalse
*/
public boolean addChildTask(Task task) {
boolean ret = false;
if (task != null && !mChildren.contains(task)) {
@ -234,6 +288,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index 0
* @return boolean:truefalse
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
@ -260,6 +320,11 @@ public class TaskList extends Node {
return true;
}
/**
*
* @param task
* @return boolean:truefalse
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
@ -281,6 +346,12 @@ public class TaskList extends Node {
return ret;
}
/**
*
* @param task
* @param index 0
* @return boolean:truefalse
*/
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
@ -299,6 +370,11 @@ public class TaskList extends Node {
return (removeChildTask(task) && addChildTask(task, index));
}
/**
*
* @param gid gid()
* @return Taskgidnull
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
@ -309,10 +385,20 @@ public class TaskList extends Node {
return null;
}
/**
*
* @param task
* @return int:0-1
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
* @param index 0
* @return Tasknull
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +407,11 @@ public class TaskList extends Node {
return mChildren.get(index);
}
/**
*
* @param gid gid
* @return Taskgidnull
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))
@ -329,14 +420,26 @@ public class TaskList extends Node {
return null;
}
/**
*
* @return ArrayList<Task>ArrayList
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
/**
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index;
}
/**
*
* @return
*/
public int getIndex() {
return this.mIndex;
}

Loading…
Cancel
Save