parent
2cf0415a25
commit
94407f0156
@ -0,0 +1,104 @@
|
||||
// 该类是一个抽象类,作为节点的基类,可能用于同步操作相关的数据管理
|
||||
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;
|
||||
|
||||
|
||||
// 节点的全局唯一标识符
|
||||
private String mGid;
|
||||
// 节点的名称
|
||||
private String mName;
|
||||
// 最后修改时间
|
||||
private long mLastModified;
|
||||
// 节点是否已删除的标记
|
||||
private boolean mDeleted;
|
||||
|
||||
|
||||
// 构造函数,初始化成员变量
|
||||
public Node() {
|
||||
mGid = null;
|
||||
mName = "";
|
||||
mLastModified = 0;
|
||||
mDeleted = false;
|
||||
}
|
||||
|
||||
|
||||
// 获取创建操作的 JSON 对象,具体实现由子类完成
|
||||
public abstract JSONObject getCreateAction(int actionId);
|
||||
|
||||
|
||||
// 获取更新操作的 JSON 对象,具体实现由子类完成
|
||||
public abstract JSONObject getUpdateAction(int actionId);
|
||||
|
||||
|
||||
// 根据远程的 JSON 对象设置节点的内容,具体实现由子类完成
|
||||
public abstract void setContentByRemoteJSON(JSONObject js);
|
||||
|
||||
|
||||
// 根据本地的 JSON 对象设置节点的内容,具体实现由子类完成
|
||||
public abstract void setContentByLocalJSON(JSONObject js);
|
||||
|
||||
|
||||
// 从节点的内容获取本地的 JSON 对象,具体实现由子类完成
|
||||
public abstract JSONObject getLocalJSONFromContent();
|
||||
|
||||
|
||||
// 获取同步操作的状态,具体实现由子类完成
|
||||
public abstract int getSyncAction(Cursor c);
|
||||
|
||||
|
||||
// 设置节点的全局唯一标识符
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
// 该类用于处理与 SQL 数据相关的操作,可能是在笔记应用中对数据的管理和同步操作
|
||||
public class SqlData {
|
||||
// 日志标签,使用类的简单名称
|
||||
private static final String TAG = SqlData.class.getSimpleName();
|
||||
// 表示无效的 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
|
||||
};
|
||||
// 投影中数据 ID 列的索引
|
||||
public static final int DATA_ID_COLUMN = 0;
|
||||
// 投影中数据 MIME 类型列的索引
|
||||
public static final int DATA_MIME_TYPE_COLUMN = 1;
|
||||
// 投影中数据内容列的索引
|
||||
public static final int DATA_CONTENT_COLUMN = 2;
|
||||
// 投影中数据 DATA1 列的索引
|
||||
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
|
||||
// 投影中数据 DATA3 列的索引
|
||||
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
|
||||
// 用于解析和操作数据的内容解析器
|
||||
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;
|
||||
// 存储不同的数据值,可能用于更新操作
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
// 构造函数,根据 Cursor 初始化数据对象,用于从数据库中加载数据
|
||||
public SqlData(Context context, Cursor c) {
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = false;
|
||||
loadFromCursor(c);
|
||||
mDiffDataValues = new ContentValues();
|
||||
}
|
||||
|
||||
|
||||
// 从 Cursor 中加载数据
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
// 根据 JSON 对象设置数据内容
|
||||
public void setContent(JSONObject js) throws JSONException {
|
||||
long dataId = js.has(DataColumns.ID)? js.getLong(DataColumns.ID) : INVALID_ID;
|
||||
if (mIsCreate || mDataId!= dataId) {
|
||||
mDiffDataValues.put(DataColumns.ID, dataId);
|
||||
}
|
||||
mDataId = dataId;
|
||||
|
||||
|
||||
String dataMimeType = js.has(DataColumns.MIME_TYPE)? js.getString(DataColumns.MIME_TYPE)
|
||||
: DataConstants.NOTE;
|
||||
if (mIsCreate ||!mDataMimeType.equals(dataMimeType)) {
|
||||
mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType);
|
||||
}
|
||||
mDataMimeType = dataMimeType;
|
||||
|
||||
|
||||
String dataContent = js.has(DataColumns.CONTENT)? js.getString(DataColumns.CONTENT) : "";
|
||||
if (mIsCreate ||!mDataContent.equals(dataContent)) {
|
||||
mDiffDataValues.put(DataColumns.CONTENT, dataContent);
|
||||
}
|
||||
mDataContent = dataContent;
|
||||
|
||||
|
||||
long dataContentData1 = js.has(DataColumns.DATA1)? js.getLong(DataColumns.DATA1) : 0;
|
||||
if (mIsCreate || mDataContentData1!= dataContentData1) {
|
||||
mDiffDataValues.put(DataColumns.DATA1, dataContentData1);
|
||||
}
|
||||
mDataContentData3 = dataContentData1;
|
||||
|
||||
|
||||
String dataContentData3 = js.has(DataColumns.DATA3)? js.getString(DataColumns.DATA3) : "";
|
||||
if (mIsCreate ||!mDataContentData3.equals(dataContentData3)) {
|
||||
mDiffDataValues.put(DataColumns.DATA3, dataContentData3);
|
||||
}
|
||||
mDataContentData3 = dataContentData3;
|
||||
}
|
||||
|
||||
|
||||
// 获取数据的 JSON 表示
|
||||
public JSONObject getContent() throws JSONException {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// 提交数据更改,根据情况进行插入或更新操作
|
||||
public void commit(long noteId, boolean validateVersion, long version) {
|
||||
|
||||
|
||||
if (mIsCreate) {
|
||||
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
|
||||
mDiffDataValues.remove(DataColumns.ID);
|
||||
}
|
||||
|
||||
|
||||
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
|
||||
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
|
||||
try {
|
||||
mDataId = Long.valueOf(uri.getPathSegments().get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Get note id error :" + e.toString());
|
||||
throw new ActionFailureException("create note failed");
|
||||
}
|
||||
} else {
|
||||
if (mDiffDataValues.size() > 0) {
|
||||
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,
|
||||
"? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
|
||||
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
|
||||
String.valueOf(noteId), String.valueOf(version)
|
||||
});
|
||||
}
|
||||
if (result == 0) {
|
||||
Log.w(TAG, "there is no update. maybe user updates note when syncing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mDiffDataValues.clear();
|
||||
mIsCreate = false;
|
||||
}
|
||||
|
||||
|
||||
// 获取数据的 ID
|
||||
public long getId() {
|
||||
return mDataId;
|
||||
}
|
||||
}
|
@ -0,0 +1,526 @@
|
||||
// 该类用于管理 SQL 笔记的数据操作,可能是在笔记应用中对笔记信息的管理和同步操作
|
||||
public class SqlNote {
|
||||
// 日志标签,使用类的简单名称
|
||||
private static final String TAG = SqlNote.class.getSimpleName();
|
||||
// 表示无效的 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,
|
||||
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
|
||||
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID,
|
||||
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
|
||||
NoteColumns.VERSION
|
||||
};
|
||||
// 投影中笔记 ID 列的索引
|
||||
public static final int ID_COLUMN = 0;
|
||||
// 投影中提醒日期列的索引
|
||||
public static final int ALERTED_DATE_COLUMN = 1;
|
||||
// 投影中背景颜色 ID 列的索引
|
||||
public static final int BG_COLOR_ID_COLUMN = 2;
|
||||
// 投影中创建日期列的索引
|
||||
public static final int CREATED_DATE_COLUMN = 3;
|
||||
// 投影中有附件标记列的索引
|
||||
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
||||
// 投影中修改日期列的索引
|
||||
public static final int MODIFIED_DATE_COLUMN = 5;
|
||||
// 投影中笔记计数列的索引
|
||||
public static final int NOTES_COUNT_COLUMN = 6;
|
||||
// 投影中父 ID 列的索引
|
||||
public static final int PARENT_ID_COLUMN = 7;
|
||||
// 投影中摘要列的索引
|
||||
public static final int SNIPPET_COLUMN = 8;
|
||||
// 投影中类型列的索引
|
||||
public static final int TYPE_COLUMN = 9;
|
||||
// 投影中窗口小部件 ID 列的索引
|
||||
public static final int WIDGET_ID_COLUMN = 10;
|
||||
// 投影中窗口小部件类型列的索引
|
||||
public static final int WIDGET_TYPE_COLUMN = 11;
|
||||
// 投影中同步 ID 列的索引
|
||||
public static final int SYNC_ID_COLUMN = 12;
|
||||
// 投影中本地修改标记列的索引
|
||||
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
||||
// 投影中原父 ID 列的索引
|
||||
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
||||
// 投影中 GTASK ID 列的索引
|
||||
public static final int GTASK_ID_COLUMN = 15;
|
||||
// 投影中版本列的索引
|
||||
public static final int VERSION_COLUMN = 16;
|
||||
|
||||
|
||||
// 上下文对象,用于获取系统服务等
|
||||
private Context mContext;
|
||||
// 内容解析器,用于操作内容提供者的数据
|
||||
private ContentResolver mContentResolver;
|
||||
// 标记是否为创建操作
|
||||
private boolean mIsCreate;
|
||||
// 笔记的 ID
|
||||
private long mId;
|
||||
// 笔记的提醒日期
|
||||
private long mAlertDate;
|
||||
// 笔记的背景颜色 ID
|
||||
private int mBgColorId;
|
||||
// 笔记的创建日期
|
||||
private long mCreatedDate;
|
||||
// 笔记是否有附件的标记
|
||||
private int mHasAttachment;
|
||||
// 笔记的修改日期
|
||||
private long mModifiedDate;
|
||||
// 笔记的父 ID
|
||||
private long mParentId;
|
||||
// 笔记的摘要
|
||||
private String mSnippet;
|
||||
// 笔记的类型
|
||||
private int mType;
|
||||
// 笔记关联的窗口小部件 ID
|
||||
private int mWidgetId;
|
||||
// 笔记关联的窗口小部件类型
|
||||
private int mWidgetType;
|
||||
// 笔记的原父 ID
|
||||
private long mOriginParent;
|
||||
// 笔记的版本
|
||||
private long mVersion;
|
||||
// 存储不同的笔记数据值,可能用于更新操作
|
||||
private ContentValues mDiffNoteValues;
|
||||
// 存储 SqlData 列表,可能用于存储笔记的数据内容
|
||||
private ArrayList<SqlData> mDataList;
|
||||
|
||||
|
||||
// 构造函数,用于创建新的笔记对象,初始化成员变量
|
||||
public SqlNote(Context context) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = true;
|
||||
mId = INVALID_ID;
|
||||
mAlertDate = 0;
|
||||
mBgColorId = ResourceParser.getDefaultBgId(context);
|
||||
mCreatedDate = System.currentTimeMillis();
|
||||
mHasAttachment = 0;
|
||||
mModifiedDate = System.currentTimeMillis();
|
||||
mParentId = 0;
|
||||
mSnippet = "";
|
||||
mType = Notes.TYPE_NOTE;
|
||||
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
||||
mOriginParent = 0;
|
||||
mVersion = 0;
|
||||
mDiffNoteValues = new ContentValues();
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
}
|
||||
|
||||
|
||||
// 构造函数,根据 Cursor 初始化笔记对象,用于从数据库中加载笔记信息
|
||||
public SqlNote(Context context, Cursor c) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = false;
|
||||
loadFromCursor(c);
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
mDiffNoteValues = new ContentValues();
|
||||
}
|
||||
|
||||
|
||||
// 构造函数,根据笔记 ID 初始化笔记对象,从数据库中加载笔记信息
|
||||
public SqlNote(Context context, long id) {
|
||||
mContext = context;
|
||||
mContentResolver = context.getContentResolver();
|
||||
mIsCreate = false;
|
||||
loadFromCursor(id);
|
||||
mDataList = new ArrayList<SqlData>();
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
mDiffNoteValues = new ContentValues();
|
||||
}
|
||||
|
||||
|
||||
// 从指定的笔记 ID 加载笔记信息
|
||||
private void loadFromCursor(long id) {
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
|
||||
new String[] {
|
||||
String.valueOf(id)
|
||||
}, null);
|
||||
if (c!= null) {
|
||||
c.moveToNext();
|
||||
loadFromCursor(c);
|
||||
} else {
|
||||
Log.w(TAG, "loadFromCursor: cursor = null");
|
||||
}
|
||||
} finally {
|
||||
if (c!= null)
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 从 Cursor 中加载笔记信息
|
||||
private void loadFromCursor(Cursor c) {
|
||||
mId = c.getLong(ID_COLUMN);
|
||||
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
||||
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
||||
mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
|
||||
mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
|
||||
mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
|
||||
mParentId = c.getLong(PARENT_ID_COLUMN);
|
||||
mSnippet = c.getString(SNIPPET_COLUMN);
|
||||
mType = c.getInt(TYPE_COLUMN);
|
||||
mWidgetId = c.getInt(WIDGET_ID_COLUMN);
|
||||
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
|
||||
mVersion = c.getLong(VERSION_COLUMN);
|
||||
}
|
||||
|
||||
|
||||
// 加载笔记的数据内容
|
||||
private void loadDataContent() {
|
||||
Cursor c = null;
|
||||
mDataList.clear();
|
||||
try {
|
||||
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
|
||||
"(note_id=?)", new String[] {
|
||||
String.valueOf(mId)
|
||||
}, null);
|
||||
if (c!= null) {
|
||||
if (c.getCount() == 0) {
|
||||
Log.w(TAG, "it seems that the note has not data");
|
||||
return;
|
||||
}
|
||||
while (c.moveToNext()) {
|
||||
SqlData data = new SqlData(mContext, c);
|
||||
mDataList.add(data);
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "loadDataContent: cursor = null");
|
||||
}
|
||||
} finally {
|
||||
if (c!= null)
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 根据 JSON 对象设置笔记内容
|
||||
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) {
|
||||
// 对于文件夹,仅更新摘要和类型
|
||||
String snippet = note.has(NoteColumns.SNIPPET)? note
|
||||
.getString(NoteColumns.SNIPPET) : "";
|
||||
if (mIsCreate ||!mSnippet.equals(snippet)) {
|
||||
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
||||
}
|
||||
mSnippet = snippet;
|
||||
|
||||
|
||||
int type = note.has(NoteColumns.TYPE)? note.getInt(NoteColumns.TYPE)
|
||||
: Notes.TYPE_NOTE;
|
||||
if (mIsCreate || mType!= type) {
|
||||
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
||||
}
|
||||
mType = type;
|
||||
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
|
||||
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
||||
long id = note.has(NoteColumns.ID)? note.getLong(NoteColumns.ID) : INVALID_ID;
|
||||
if (mIsCreate || mId!= id) {
|
||||
mDiffNoteValues.put(NoteColumns.ID, id);
|
||||
}
|
||||
mId = id;
|
||||
|
||||
|
||||
long alertDate = note.has(NoteColumns.ALERTED_DATE)? note
|
||||
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
||||
if (mIsCreate || mAlertDate!= alertDate) {
|
||||
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
|
||||
}
|
||||
mAlertDate = alertDate;
|
||||
|
||||
|
||||
int bgColorId = note.has(NoteColumns.BG_COLOR_ID)? note
|
||||
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
||||
if (mIsCreate || mBgColorId!= bgColorId) {
|
||||
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
||||
}
|
||||
mBgColorId = bgColorId;
|
||||
|
||||
|
||||
long createDate = note.has(NoteColumns.CREATED_DATE)? note
|
||||
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
|
||||
if (mIsCreate || mCreatedDate!= createDate) {
|
||||
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
|
||||
}
|
||||
mCreatedDate = createDate;
|
||||
|
||||
|
||||
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT)? note
|
||||
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
|
||||
if (mIsCreate || mHasAttachment!= hasAttachment) {
|
||||
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
|
||||
}
|
||||
mHasAttachment = hasAttachment;
|
||||
|
||||
|
||||
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE)? note
|
||||
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
|
||||
if (mIsCreate || mModifiedDate!= modifiedDate) {
|
||||
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
|
||||
}
|
||||
mModifiedDate = modifiedDate;
|
||||
|
||||
|
||||
long parentId = note.has(NoteColumns.PARENT_ID)? note
|
||||
.getLong(NoteColumns.PARENT_ID) : 0;
|
||||
if (mIsCreate || mParentId!= parentId) {
|
||||
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
|
||||
}
|
||||
mParentId = parentId;
|
||||
|
||||
|
||||
String snippet = note.has(NoteColumns.SNIPPET)? note
|
||||
.getString(NoteColumns.SNIPPET) : "";
|
||||
if (mIsCreate ||!mSnippet.equals(snippet)) {
|
||||
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
||||
}
|
||||
mSnippet = snippet;
|
||||
|
||||
|
||||
int type = note.has(NoteColumns.TYPE)? note.getInt(NoteColumns.TYPE)
|
||||
: Notes.TYPE_NOTE;
|
||||
if (mIsCreate || mType!= type) {
|
||||
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
||||
}
|
||||
mType = type;
|
||||
|
||||
|
||||
int widgetId = note.has(NoteColumns.WIDGET_ID)? note.getInt(NoteColumns.WIDGET_ID)
|
||||
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||
if (mIsCreate || mWidgetId!= widgetId) {
|
||||
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
||||
}
|
||||
mWidgetId = widgetId;
|
||||
|
||||
|
||||
int widgetType = note.has(NoteColumns.WIDGET_TYPE)? note
|
||||
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
|
||||
if (mIsCreate || mWidgetType!= widgetType) {
|
||||
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
|
||||
}
|
||||
mWidgetType = widgetType;
|
||||
|
||||
|
||||
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID)? note
|
||||
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
|
||||
if (mIsCreate || mOriginParent!= originParent) {
|
||||
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
|
||||
}
|
||||
mOriginParent = originParent;
|
||||
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
SqlData sqlData = null;
|
||||
if (data.has(DataColumns.ID)) {
|
||||
long dataId = data.getLong(DataColumns.ID);
|
||||
for (SqlData temp : mDataList) {
|
||||
if (dataId == temp.getId()) {
|
||||
sqlData = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sqlData == null) {
|
||||
sqlData = new SqlData(mContext);
|
||||
mDataList.add(sqlData);
|
||||
}
|
||||
|
||||
|
||||
sqlData.setContent(data);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// 获取笔记的 JSON 表示
|
||||
public JSONObject getContent() {
|
||||
try {
|
||||
JSONObject js = new JSONObject();
|
||||
|
||||
|
||||
if (mIsCreate) {
|
||||
Log.e(TAG, "it seems that we haven't created this in database yet");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
JSONObject note = new JSONObject();
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
note.put(NoteColumns.ID, mId);
|
||||
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
||||
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
||||
note.put(NoteColumns.CREATED_DATE, mCreatedDate);
|
||||
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
|
||||
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
|
||||
note.put(NoteColumns.PARENT_ID, mParentId);
|
||||
note.put(NoteColumns.SNIPPET, mSnippet);
|
||||
note.put(NoteColumns.TYPE, mType);
|
||||
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
||||
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
||||
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
||||
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
||||
|
||||
|
||||
JSONArray dataArray = new JSONArray();
|
||||
for (SqlData sqlData : mDataList) {
|
||||
JSONObject data = sqlData.getContent();
|
||||
if (data!= null) {
|
||||
dataArray.put(data);
|
||||
}
|
||||
}
|
||||
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
||||
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
||||
note.put(NoteColumns.ID, mId);
|
||||
note.put(NoteColumns.TYPE, mType);
|
||||
note.put(NoteColumns.SNIPPET, mSnippet);
|
||||
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
||||
}
|
||||
|
||||
|
||||
return js;
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// 设置笔记的父 ID
|
||||
public void setParentId(long id) {
|
||||
mParentId = id;
|
||||
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
||||
}
|
||||
|
||||
|
||||
// 设置笔记的 GTASK ID
|
||||
public void setGtaskId(String gid) {
|
||||
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
||||
}
|
||||
|
||||
|
||||
// 设置笔记的同步 ID
|
||||
public void setSyncId(long syncId) {
|
||||
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
||||
}
|
||||
|
||||
|
||||
// 重置本地修改标记
|
||||
public void resetLocalModified() {
|
||||
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
||||
}
|
||||
|
||||
|
||||
// 获取笔记的 ID
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
// 获取笔记的父 ID
|
||||
public long getParentId() {
|
||||
return mParentId;
|
||||
}
|
||||
|
||||
|
||||
// 获取笔记的摘要
|
||||
public String getSnippet() {
|
||||
return mSnippet;
|
||||
}
|
||||
|
||||
|
||||
// 判断是否为笔记类型
|
||||
public boolean isNoteType() {
|
||||
return mType == Notes.TYPE_NOTE;
|
||||
}
|
||||
|
||||
|
||||
// 提交笔记的更改,根据是否为创建操作进行插入或更新操作
|
||||
public void commit(boolean validateVersion) {
|
||||
if (mIsCreate) {
|
||||
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
||||
mDiffNoteValues.remove(NoteColumns.ID);
|
||||
}
|
||||
|
||||
|
||||
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
||||
try {
|
||||
mId = Long.valueOf(uri.getPathSegments().get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, "Get note id error :" + e.toString());
|
||||
throw new ActionFailureException("create note failed");
|
||||
}
|
||||
if (mId == 0) {
|
||||
throw new IllegalStateException("Create thread id failed");
|
||||
}
|
||||
|
||||
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
for (SqlData sqlData : mDataList) {
|
||||
sqlData.commit(mId, false, -1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mId <= 0 && mId!= Notes.ID_ROOT_FOLDER && mId!= Notes.ID_CALL_RECORD_FOLDER) {
|
||||
Log.e(TAG, "No such note");
|
||||
throw new IllegalStateException("Try to update note with invalid id");
|
||||
}
|
||||
if (mDiffNoteValues.size() > 0) {
|
||||
mVersion++;
|
||||
int result = 0;
|
||||
if (!validateVersion) {
|
||||
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
||||
+ NoteColumns.ID + "=?)", new String[] {
|
||||
String.valueOf(mId)
|
||||
});
|
||||
} else {
|
||||
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
||||
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
|
||||
new String[] {
|
||||
String.valueOf(mId), String.valueOf(mVersion)
|
||||
});
|
||||
}
|
||||
if (result == 0) {
|
||||
Log.w(TAG, "there is no update. maybe user updates note when syncing");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mType == Notes.TYPE_NOTE) {
|
||||
for (SqlData sqlData : mDataList) {
|
||||
sqlData.commit(mId, validateVersion, mVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 刷新本地信息
|
||||
loadFromCursor(mId);
|
||||
if (mType == Notes.TYPE_NOTE)
|
||||
loadDataContent();
|
||||
|
||||
|
||||
mDiffNoteValues.clear();
|
||||
mIsCreate = false;
|
||||
}
|
||||
}
|
@ -0,0 +1,385 @@
|
||||
// 该类 Task 继承自 Node 类,是一个表示任务的类,可能用于任务管理和同步操作
|
||||
public class Task extends Node {
|
||||
// 日志标签,使用类的简单名称
|
||||
private static final String TAG = Task.class.getSimpleName();
|
||||
// 标记任务是否完成
|
||||
private boolean mCompleted;
|
||||
// 任务的笔记信息
|
||||
private String mNotes;
|
||||
// 任务的元信息,存储为 JSONObject
|
||||
private JSONObject mMetaInfo;
|
||||
// 任务的前一个兄弟任务
|
||||
private Task mPriorSibling;
|
||||
// 任务所属的任务列表
|
||||
private TaskList mParent;
|
||||
|
||||
|
||||
// 构造函数,初始化任务的属性
|
||||
public Task() {
|
||||
super();
|
||||
mCompleted = false;
|
||||
mNotes = null;
|
||||
mPriorSibling = null;
|
||||
mParent = null;
|
||||
mMetaInfo = null;
|
||||
}
|
||||
|
||||
|
||||
// 获取创建操作的 JSON 对象
|
||||
public JSONObject getCreateAction(int actionId) {
|
||||
JSONObject js = new JSONObject();
|
||||
|
||||
|
||||
try {
|
||||
// action_type
|
||||
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
|
||||
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
|
||||
|
||||
|
||||
// action_id
|
||||
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
|
||||
|
||||
|
||||
// index
|
||||
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
|
||||
|
||||
|
||||
// entity_delta
|
||||
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_TASK);
|
||||
if (getNotes()!= null) {
|
||||
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
|
||||
}
|
||||
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
|
||||
|
||||
|
||||
// parent_id
|
||||
js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());
|
||||
|
||||
|
||||
// dest_parent_type
|
||||
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE,
|
||||
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
|
||||
|
||||
|
||||
// list_id
|
||||
js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());
|
||||
|
||||
|
||||
// prior_sibling_id
|
||||
if (mPriorSibling!= null) {
|
||||
js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid());
|
||||
}
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
throw new ActionFailureException("fail to generate task-create jsonobject");
|
||||
}
|
||||
|
||||
|
||||
return js;
|
||||
}
|
||||
|
||||
|
||||
// 获取更新操作的 JSON 对象
|
||||
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());
|
||||
if (getNotes()!= null) {
|
||||
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
|
||||
}
|
||||
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
|
||||
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
throw new ActionFailureException("fail to generate task-update jsonobject");
|
||||
}
|
||||
|
||||
|
||||
return js;
|
||||
}
|
||||
|
||||
|
||||
// 根据远程的 JSON 对象设置任务的内容
|
||||
public void setContentByRemoteJSON(JSONObject js) {
|
||||
if (js!= null) {
|
||||
try {
|
||||
// id
|
||||
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
|
||||
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
|
||||
}
|
||||
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
// notes
|
||||
if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
|
||||
setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
|
||||
}
|
||||
|
||||
|
||||
// deleted
|
||||
if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
|
||||
setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
|
||||
}
|
||||
|
||||
|
||||
// completed
|
||||
if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
|
||||
setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
throw new ActionFailureException("fail to get task content from jsonobject");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 根据本地的 JSON 对象设置任务的内容
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
Log.e(TAG, "invalid type");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
||||
setName(data.getString(DataColumns.CONTENT));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 从任务的内容获取本地的 JSON 对象
|
||||
public JSONObject getLocalJSONFromContent() {
|
||||
String name = getName();
|
||||
try {
|
||||
if (mMetaInfo == null) {
|
||||
// 新创建的任务
|
||||
if (name == null) {
|
||||
Log.w(TAG, "the note seems to be an empty one");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
JSONObject js = new JSONObject();
|
||||
JSONObject note = new JSONObject();
|
||||
JSONArray dataArray = new JSONArray();
|
||||
JSONObject data = new JSONObject();
|
||||
data.put(DataColumns.CONTENT, name);
|
||||
dataArray.put(data);
|
||||
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
||||
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
|
||||
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
||||
return js;
|
||||
} else {
|
||||
// 已同步的任务
|
||||
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
||||
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
||||
|
||||
|
||||
for (int i = 0; i < dataArray.length(); i++) {
|
||||
JSONObject data = dataArray.getJSONObject(i);
|
||||
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
|
||||
data.put(DataColumns.CONTENT, getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
|
||||
return mMetaInfo;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 设置任务的元信息
|
||||
public void setMetaInfo(MetaData metaData) {
|
||||
if (metaData!= null && metaData.getNotes()!= null) {
|
||||
try {
|
||||
mMetaInfo = new JSONObject(metaData.getNotes());
|
||||
} catch (JSONException e) {
|
||||
Log.w(TAG, e.toString());
|
||||
mMetaInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取同步操作的状态
|
||||
public int getSyncAction(Cursor c) {
|
||||
try {
|
||||
JSONObject noteInfo = null;
|
||||
if (mMetaInfo!= null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
|
||||
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
||||
}
|
||||
|
||||
|
||||
if (noteInfo == null) {
|
||||
Log.w(TAG, "it seems that note meta has been deleted");
|
||||
return SYNC_ACTION_UPDATE_REMOTE;
|
||||
}
|
||||
|
||||
|
||||
if (!noteInfo.has(NoteColumns.ID)) {
|
||||
Log.w(TAG, "remote note id seems to be deleted");
|
||||
return SYNC_ACTION_UPDATE_LOCAL;
|
||||
}
|
||||
|
||||
|
||||
// 验证笔记的 ID
|
||||
if (c.getLong(SqlNote.ID_COLUMN)!= noteInfo.getLong(NoteColumns.ID)) {
|
||||
Log.w(TAG, "note id doesn't match");
|
||||
return SYNC_ACTION_UPDATE_LOCAL;
|
||||
}
|
||||
|
||||
|
||||
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
|
||||
// 本地没有更新
|
||||
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
|
||||
// 两边都没有更新
|
||||
return SYNC_ACTION_NONE;
|
||||
} else {
|
||||
// 将远程更新应用到本地
|
||||
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_CONFLICT;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return SYNC_ACTION_ERROR;
|
||||
}
|
||||
|
||||
|
||||
// 判断任务是否值得保存
|
||||
public boolean isWorthSaving() {
|
||||
return mMetaInfo!= null || (getName()!= null && getName().trim().length() > 0)
|
||||
|| (getNotes()!= null && getNotes().trim().length() > 0);
|
||||
}
|
||||
|
||||
|
||||
// 设置任务完成状态
|
||||
public void setCompleted(boolean completed) {
|
||||
this.mCompleted = completed;
|
||||
}
|
||||
|
||||
|
||||
// 设置任务的笔记信息
|
||||
public void setNotes(String notes) {
|
||||
this.mNotes = notes;
|
||||
}
|
||||
|
||||
|
||||
// 设置任务的前一个兄弟任务
|
||||
public void setPriorSibling(Task priorSibling) {
|
||||
this.mPriorSibling = priorSibling;
|
||||
}
|
||||
|
||||
|
||||
// 设置任务的父任务列表
|
||||
public void setParent(TaskList parent) {
|
||||
this.mParent = parent;
|
||||
}
|
||||
|
||||
|
||||
// 获取任务完成状态
|
||||
public boolean getCompleted() {
|
||||
return this.mCompleted;
|
||||
}
|
||||
|
||||
|
||||
// 获取任务的笔记信息
|
||||
public String getNotes() {
|
||||
return this.mNotes;
|
||||
}
|
||||
|
||||
|
||||
// 获取任务的前一个兄弟任务
|
||||
public Task getPriorSibling() {
|
||||
return this.mPriorSibling;
|
||||
}
|
||||
|
||||
|
||||
// 获取任务的父任务列表
|
||||
public TaskList getParent() {
|
||||
return this.mParent;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue