ZhengLiJie_branch
zlj 3 months ago
parent 94767859bc
commit 1490924c8c

@ -19,8 +19,21 @@ package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
/**
* Node
*
*/
public abstract class Node {
/**
*
* - NONE:
* - ADD_REMOTE/LOCAL: /
* - DEL_REMOTE/LOCAL: /
* - UPDATE_REMOTE/LOCAL: /
* - UPDATE_CONFLICT:
* - ERROR:
*/
public static final int SYNC_ACTION_NONE = 0;
public static final int SYNC_ACTION_ADD_REMOTE = 1;
@ -38,37 +51,78 @@ public abstract class Node {
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
public static final int SYNC_ACTION_ERROR = 8;
/** 节点在远程服务器上的唯一标识符 */
private String mGid;
private String mGid;
private String mName;
private long mLastModified;
private boolean mDeleted;
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
/** 节点名称 */
private String mName;
public abstract JSONObject getCreateAction(int actionId);
/** 最后修改时间戳 */
private long mLastModified;
public abstract JSONObject getUpdateAction(int actionId);
/** 是否被标记为删除 */
private boolean mDeleted;
/**
*
*/
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
/**
* JSON 使
*
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getCreateAction(int actionId);
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* JSON 使
*
* @param actionId ID
* @return JSON
*/
public abstract JSONObject getUpdateAction(int actionId);
public abstract void setContentByLocalJSON(JSONObject js);
/**
* JSON
*
* @param js JSON
*/
public abstract void setContentByRemoteJSON(JSONObject js);
public abstract JSONObject getLocalJSONFromContent();
/**
* JSON
*
* @param js JSON
*/
public abstract void setContentByLocalJSON(JSONObject js);
public abstract int getSyncAction(Cursor c);
/**
* JSON
*
* @return JSON
*/
public abstract JSONObject getLocalJSONFromContent();
public void setGid(String gid) {
this.mGid = gid;
}
/**
*
*
* @param c
* @return
*/
public abstract int getSyncAction(Cursor c);
/**
* GID
*
* @param gid GID
*/
public void setGid(String gid) {
this.mGid = gid;
}
public void setName(String name) {
this.mName = name;
@ -81,10 +135,14 @@ public abstract class Node {
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
public String getGid() {
return this.mGid;
}
/**
* GID
*
* @return mGid GID
*/
public String getGid() {
return this.mGid;
}
public String getName() {
return this.mName;

@ -33,18 +33,24 @@ import net.micode.notes.gtask.exception.ActionFailureException;
import org.json.JSONException;
import org.json.JSONObject;
/**
* SqlData SQLite JSON
*
*/
public class SqlData {
private static final String TAG = SqlData.class.getSimpleName();
/** 日志标签,标识当前类名 */
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
/** 表示无效的 ID 值 */
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
};
/** 查询语句中使用的列投影 */
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
/** 列索引常量 */
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_MIME_TYPE_COLUMN = 1;
@ -55,22 +61,34 @@ public class SqlData {
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
/** 内容解析器,用于访问 ContentProvider */
private ContentResolver mContentResolver;
/** 是否是新建的数据项 */
private boolean mIsCreate;
/** 数据项 ID */
private long mDataId;
/** 数据项 MIME 类型 */
private String mDataMimeType;
/** 数据内容 */
private String mDataContent;
/** 数据字段 DATA1 的值 */
private long mDataContentData1;
/** 数据字段 DATA3 的值 */
private String mDataContentData3;
/** 存储差异内容的 ContentValues 对象 */
private ContentValues mDiffDataValues;
/**
* SqlData
*
* @param context
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -81,7 +99,12 @@ public class SqlData {
mDataContentData3 = "";
mDiffDataValues = new ContentValues();
}
/**
* SqlData
*
* @param context
* @param c
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -96,7 +119,12 @@ public class SqlData {
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/**
* JSON SqlData
*
* @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 +157,12 @@ public class SqlData {
}
mDataContentData3 = dataContentData3;
}
/**
* SqlData JSON
*
* @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");
@ -143,7 +176,13 @@ public class SqlData {
js.put(DataColumns.DATA3, mDataContentData3);
return js;
}
/**
*
*
* @param noteId ID
* @param validateVersion
* @param version
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {

@ -37,12 +37,18 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* SqlNote SQLite JSON
*
*/
public class SqlNote {
private static final String TAG = SqlNote.class.getSimpleName();
/** 日志标签,标识当前类名 */
private static final String TAG = SqlNote.class.getSimpleName();
private static final int INVALID_ID = -99999;
/** 表示无效的 ID 值 */
private static final int INVALID_ID = -99999;
/** 查询语句中使用的列投影数组 */
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
@ -86,42 +92,64 @@ public class SqlNote {
public static final int VERSION_COLUMN = 16;
private Context mContext;
private ContentResolver mContentResolver;
/** 上下文对象 */
private Context mContext;
private boolean mIsCreate;
/** 内容解析器,用于访问 ContentProvider */
private ContentResolver mContentResolver;
private long mId;
/** 是否是新建的笔记项 */
private boolean mIsCreate;
private long mAlertDate;
/** 笔记 ID */
private long mId;
private int mBgColorId;
/** 警告时间 */
private long mAlertDate;
private long mCreatedDate;
/** 背景颜色 ID */
private int mBgColorId;
private int mHasAttachment;
/** 创建时间 */
private long mCreatedDate;
private long mModifiedDate;
/** 是否有附件 */
private int mHasAttachment;
private long mParentId;
/** 最后修改时间 */
private long mModifiedDate;
private String mSnippet;
/** 父节点 ID */
private long mParentId;
private int mType;
/** 摘要内容 */
private String mSnippet;
private int mWidgetId;
/** 类型(如普通笔记、文件夹等) */
private int mType;
private int mWidgetType;
/** 小部件 ID */
private int mWidgetId;
private long mOriginParent;
/** 小部件类型 */
private int mWidgetType;
private long mVersion;
/** 原始父节点 ID */
private long mOriginParent;
private ContentValues mDiffNoteValues;
/** 版本号,用于同步控制 */
private long mVersion;
private ArrayList<SqlData> mDataList;
/** 存储差异内容的 ContentValues 对象 */
private ContentValues mDiffNoteValues;
/** 当前笔记包含的数据列表 */
private ArrayList<SqlData> mDataList;
/**
* SqlNote
*
* @param context
*/
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -142,7 +170,12 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
/**
* SqlNote
*
* @param context
* @param c
*/
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
@ -165,7 +198,11 @@ public class SqlNote {
mDiffNoteValues = new ContentValues();
}
/**
*
*
* @param c
*/
private void loadFromCursor(long id) {
Cursor c = null;
try {
@ -184,7 +221,11 @@ public class SqlNote {
c.close();
}
}
/**
* ID
*
* @param id ID
*/
private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -225,7 +266,12 @@ public class SqlNote {
c.close();
}
}
/**
* JSON
*
* @param js JSON
* @return
*/
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);

@ -30,30 +30,44 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Task Node
* Node
*/
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
private boolean mCompleted;
private String mNotes;
/** 日志标签,标识当前类名 */
private static final String TAG = Task.class.getSimpleName();
/** 是否已完成 */
private boolean mCompleted;
private JSONObject mMetaInfo;
/** 备注信息 */
private String mNotes;
private Task mPriorSibling;
/** 元数据信息JSON 格式) */
private JSONObject mMetaInfo;
private TaskList mParent;
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;
mParent = null;
mMetaInfo = null;
}
/** 上一个同级任务 */
private Task mPriorSibling;
/** 父任务列表 */
private TaskList mParent;
/**
* Task
*/
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;
mParent = null;
mMetaInfo = null;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -102,7 +116,12 @@ public class Task extends Node {
return js;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -257,6 +276,12 @@ public class Task extends Node {
}
}
}
/**
*
*
* @param c
* @return SYNC_ACTION_XXX
*/
public int getSyncAction(Cursor c) {
try {
@ -310,7 +335,11 @@ public class Task extends Node {
return SYNC_ACTION_ERROR;
}
/**
*
*
* @return
*/
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);

@ -29,14 +29,21 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* TaskList Node
* Task
*/
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();
private int mIndex;
private ArrayList<Task> mChildren;
/** 日志标签,标识当前类名 */
private static final String TAG = TaskList.class.getSimpleName();
/** 列表在远程服务器上的索引位置 */
private int mIndex;
/** 当前任务列表中的子任务集合 */
private ArrayList<Task> mChildren;
/**
* TaskList
*/
public TaskList() {
super();
mChildren = new ArrayList<Task>();
@ -73,7 +80,12 @@ public class TaskList extends Node {
return js;
}
/**
* JSON
*
* @param actionId ID
* @return JSON
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
@ -102,7 +114,11 @@ public class TaskList extends Node {
return js;
}
/**
* JSON ID
*
* @param js JSON
*/
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
@ -128,7 +144,11 @@ 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 +176,11 @@ public class TaskList extends Node {
e.printStackTrace();
}
}
/**
* JSON
*
* @return JSON
*/
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
@ -182,7 +206,12 @@ public class TaskList extends Node {
return null;
}
}
/**
*
*
* @param c
* @return SYNC_ACTION_XXX
*/
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -219,7 +248,12 @@ public class TaskList extends Node {
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 +267,13 @@ 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");
@ -280,7 +320,13 @@ 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()) {
@ -308,11 +354,21 @@ public class TaskList extends Node {
}
return null;
}
/**
*
*
* @param task
* @return -1
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
*
*
* @param index
* @return null
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
@ -321,6 +377,11 @@ public class TaskList extends Node {
return mChildren.get(index);
}
/**
*
*
* @return
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid))

Loading…
Cancel
Save