liuyitao 11 months ago
parent 7a9a5f0b5f
commit e803e6b604

@ -1,12 +1,4 @@
p
@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13
b
2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5
j
:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5
d
4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f
k k
;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 ;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88
g g
@ -19,3 +11,13 @@ p
@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 @app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312
s s
Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf
P
app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e
i
9app/src/main/java/net/micode/notes/data/data/Contact.java,c\b\cbdf3f7fafb3e6fffa1c5a70aa69770de8dcf24f
@
app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164
j
:app/src/main/java/net/micode/notes/gtask/data/SqlData.java,9\3\934a4e2abf19d28a53f6aeb1dcd99248c44b6892
j
:app/src/main/java/net/micode/notes/gtask/data/SqlNote.java,f\1\f1226eeacd46c914d51f3d1a6d6f27377490d2a4

@ -1,12 +1,4 @@
p
@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13
b
2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5
j
:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5
d
4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f
k k
;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 ;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88
g g
@ -19,3 +11,13 @@ p
@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 @app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312
s s
Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf
P
app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e
i
9app/src/main/java/net/micode/notes/data/data/Contact.java,c\b\cbdf3f7fafb3e6fffa1c5a70aa69770de8dcf24f
@
app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164
j
:app/src/main/java/net/micode/notes/gtask/data/SqlData.java,9\3\934a4e2abf19d28a53f6aeb1dcd99248c44b6892
j
:app/src/main/java/net/micode/notes/gtask/data/SqlNote.java,f\1\f1226eeacd46c914d51f3d1a6d6f27377490d2a4

@ -26,35 +26,6 @@ import org.json.JSONObject;
public class MetaData extends Task { public class MetaData extends Task {
<<<<<<< HEAD
<<<<<<< HEAD
/*
* TAG
* getSimpleName ()
*/
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/*
*
* JSONObjectput ()TasksetNotes ()setName ()
*
*/
public void setMeta(String gid, JSONObject metaInfo) {
//对函数块进行注释
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
/*
* metaInfojsonobject
*/
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
/*
*
*/
=======
=======
>>>>>>> liuyitao-branch
private final static String TAG = MetaData.class.getSimpleName(); private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null; private String mRelatedGid = null;
@ -64,54 +35,20 @@ public class MetaData extends Task {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "failed to put related gid"); Log.e(TAG, "failed to put related gid");
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
setNotes(metaInfo.toString()); setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME); setName(GTaskStringUtils.META_NOTE_NAME);
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
* Gid
*/
public String getRelatedGid() {
return mRelatedGid;
}
/*
*
*/
=======
=======
>>>>>>> liuyitao-branch
public String getRelatedGid() { public String getRelatedGid() {
return mRelatedGid; return mRelatedGid;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
@Override @Override
public boolean isWorthSaving() { public boolean isWorthSaving() {
return getNotes() != null; return getNotes() != null;
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
* 使json
* TasksetContentByRemoteJSON ()
*
*/
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
@Override @Override
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js); super.setContentByRemoteJSON(js);
@ -121,57 +58,16 @@ public class MetaData extends Task {
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) { } catch (JSONException e) {
Log.w(TAG, "failed to get related gid"); Log.w(TAG, "failed to get related gid");
<<<<<<< HEAD
<<<<<<< HEAD
/*
*
*/
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
mRelatedGid = null; mRelatedGid = null;
} }
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
* 使json
*/
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
@Override @Override
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
// this function should not be called // this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
} }
<<<<<<< HEAD
<<<<<<< HEAD
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
/*
*/
}
/*
* json
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
/*
*/
}
=======
=======
>>>>>>> liuyitao-branch
@Override @Override
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
@ -183,8 +79,4 @@ public class MetaData extends Task {
throw new IllegalAccessError("MetaData:getSyncAction should not be called"); throw new IllegalAccessError("MetaData:getSyncAction should not be called");
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }

@ -20,34 +20,6 @@ import android.database.Cursor;
import org.json.JSONObject; import org.json.JSONObject;
<<<<<<< HEAD
<<<<<<< HEAD
/**
*
* abstract
*/
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;// 同步出现错误
=======
=======
>>>>>>> liuyitao-branch
public abstract class Node { public abstract class Node {
public static final int SYNC_ACTION_NONE = 0; public static final int SYNC_ACTION_NONE = 0;
@ -66,74 +38,11 @@ public abstract class Node {
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
public static final int SYNC_ACTION_ERROR = 8; public static final int SYNC_ACTION_ERROR = 8;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
private String mGid; private String mGid;
private String mName; private String mName;
<<<<<<< HEAD
<<<<<<< HEAD
private long mLastModified;//记录最后一次修改时间
private boolean mDeleted;//表征是否被删除
public Node() {
mGid = null; // 初始化 mGid 为 null
mName = ""; // 初始化 mName 为空字符串
mLastModified = 0; // 初始化 mLastModified 为 0
mDeleted = false; // 初始化 mDeleted 为 false
}
public abstract JSONObject getCreateAction(int actionId); // 获取创建节点的操作信息的抽象方法
public abstract JSONObject getUpdateAction(int actionId); // 获取更新节点的操作信息的抽象方法
public abstract void setContentByRemoteJSON(JSONObject js); // 根据远程JSON数据设置节点内容的抽象方法
public abstract void setContentByLocalJSON(JSONObject js); // 根据本地JSON数据设置节点内容的抽象方法
public abstract JSONObject getLocalJSONFromContent(); // 从节点内容中获取本地JSON数据的抽象方法
public abstract int getSyncAction(Cursor c); // 获取同步节点的操作信息的抽象方法
public void setGid(String gid) {
this.mGid = gid; // 设置 mGid 的取值为传入的 gid
}
public void setName(String name) {
this.mName = name; // 设置 mName 的取值为传入的 name
}
public void setLastModified(long lastModified) {
this.mLastModified = lastModified; // 设置 mLastModified 的取值为传入的 lastModified
}
public void setDeleted(boolean deleted) {
this.mDeleted = deleted; // 设置 mDeleted 的取值为传入的 deleted
}
public String getGid() {
return this.mGid; // 返回 mGid 的取值
}
public String getName() {
return this.mName; // 返回 mName 的取值
}
public long getLastModified() {
return this.mLastModified; // 返回 mLastModified 的取值
}
public boolean getDeleted() {
return this.mDeleted; // 返回 mDeleted 的取值
}
=======
=======
>>>>>>> liuyitao-branch
private long mLastModified; private long mLastModified;
private boolean mDeleted; private boolean mDeleted;
@ -189,8 +98,4 @@ public abstract class Node {
return this.mDeleted; return this.mDeleted;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }

@ -14,25 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
<<<<<<< HEAD
<<<<<<< HEAD
/*
* Description便sqlnotedatanote
* SqlData
*/
package net.micode.notes.gtask.data;
/*
*
*
*
*/
=======
package net.micode.notes.gtask.data;
>>>>>>> liuyitao-branch
=======
package net.micode.notes.gtask.data; package net.micode.notes.gtask.data;
>>>>>>> liuyitao-branch
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.ContentUris; import android.content.ContentUris;
@ -54,80 +36,14 @@ import org.json.JSONObject;
public class SqlData { public class SqlData {
<<<<<<< HEAD
<<<<<<< HEAD
/*
* TAG
* getSimpleName ()
*/
private static final String TAG = SqlData.class.getSimpleName();// 定义一个私有的静态常量 TAG用于在日志输出中作为标签
private static final int INVALID_ID = -99999;//为mDataId置初始值-99999
/*
* NotesDataColumn
*/
// 集合了interface DataColumns中所有SF常量
=======
=======
>>>>>>> liuyitao-branch
private static final String TAG = SqlData.class.getSimpleName(); private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999; private static final int INVALID_ID = -99999;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
public static final String[] PROJECTION_DATA = new String[] { public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1, DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3 DataColumns.DATA3
}; };
<<<<<<< HEAD
<<<<<<< HEAD
/*
* sql5
*/
public static final int DATA_ID_COLUMN = 0;// 数据记录ID所在列的索引通常为第 0 列
public static final int DATA_MIME_TYPE_COLUMN = 1;// 数据的MIME类型所在列的索引通常为第 1 列
public static final int DATA_CONTENT_COLUMN = 2;// 数据内容所在列的索引,通常为第 2 列
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;// 数据中的DATA1字段所在列的索引通常为第 3 列
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;// 数据中的DATA3字段所在列的索引通常为第 4 列
private ContentResolver mContentResolver;
//判断是否直接用Content生成是为true否则为false
private boolean mIsCreate;// 表示数据记录是否是新创建的标识
private long mDataId;// 数据记录的ID
private String mDataMimeType;// 数据记录的MIME类型
private String mDataContent;// 数据记录的内容
private long mDataContentData1;// 数据记录中的DATA1字段
private String mDataContentData3;// 数据记录中的DATA3字段
private ContentValues mDiffDataValues;// 保存数据记录的差异值
/*
*
* mContentResolverContentProvider
* mIsCreate
*
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
mDataId = INVALID_ID;//mDataId置初始值-99999
=======
=======
>>>>>>> liuyitao-branch
public static final int DATA_ID_COLUMN = 0; public static final int DATA_ID_COLUMN = 0;
@ -159,10 +75,6 @@ public class SqlData {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = true; mIsCreate = true;
mDataId = INVALID_ID; mDataId = INVALID_ID;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
mDataMimeType = DataConstants.NOTE; mDataMimeType = DataConstants.NOTE;
mDataContent = ""; mDataContent = "";
mDataContentData1 = 0; mDataContentData1 = 0;
@ -170,118 +82,6 @@ public class SqlData {
mDiffDataValues = new ContentValues(); mDiffDataValues = new ContentValues();
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
*
* mContentResolverContentProvider
* mIsCreate
*
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();// 获取 ContentResolver 对象
mIsCreate = false;// 将数据记录的新建标识设置为 false
loadFromCursor(c);// 从 Cursor 对象中加载数据记录
mDiffDataValues = new ContentValues();// 创建 ContentValues 对象,用于保存数据记录的差异值
}
/*
*
*
*/
private void loadFromCursor(Cursor c) {
// 获取游标中对应字段位置的字段值,并保存到成员变量中
mDataId = c.getLong(DATA_ID_COLUMN);//获取数据记录的ID值并保存到成员变量 mDataId 中
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);//获取数据记录的MIME类型并保存到成员变量 mDataMimeType 中。
mDataContent = c.getString(DATA_CONTENT_COLUMN);//获取数据记录的内容,并保存到成员变量 mDataContent 中。
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);//获取数据记录中的DATA1字段值并保存到成员变量 mDataContentData1 中。
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);//获取数据记录中的DATA3字段值并保存到成员变量 mDataContentData3 中。
}
/*
*
*
*/
public void setContent(JSONObject js) throws JSONException {
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; // 从JSONObject中获取DataColumns.ID字段的值如果不存在则设置为INVALID_ID
if (mIsCreate || mDataId != dataId) { // 如果是新创建的数据或者mDataId与dataId不相等
mDiffDataValues.put(DataColumns.ID, dataId); // 将dataId添加到差异数据中
}
mDataId = dataId; // 更新mDataId的值
String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE)
: DataConstants.NOTE; // 从JSONObject中获取DataColumns.MIME_TYPE字段的值如果不存在则设置为DataConstants.NOTE
if (mIsCreate || !mDataMimeType.equals(dataMimeType)) { // 如果是新创建的数据或者mDataMimeType与dataMimeType不相等
mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType); // 将dataMimeType添加到差异数据中
}
mDataMimeType = dataMimeType; // 更新mDataMimeType的值
String dataContent = js.has(DataColumns.CONTENT) ? js.getString(DataColumns.CONTENT) : ""; // 从JSONObject中获取DataColumns.CONTENT字段的值如果不存在则设置为空字符串
if (mIsCreate || !mDataContent.equals(dataContent)) { // 如果是新创建的数据或者mDataContent与dataContent不相等
mDiffDataValues.put(DataColumns.CONTENT, dataContent); // 将dataContent添加到差异数据中
}
mDataContent = dataContent; // 更新mDataContent的值
long dataContentData1 = js.has(DataColumns.DATA1) ? js.getLong(DataColumns.DATA1) : 0; // 从JSONObject中获取DataColumns.DATA1字段的值如果不存在则设置为0
if (mIsCreate || mDataContentData1 != dataContentData1) { // 如果是新创建的数据或者mDataContentData1与dataContentData1不相等
mDiffDataValues.put(DataColumns.DATA1, dataContentData1); // 将dataContentData1添加到差异数据中
}
mDataContentData1 = dataContentData1; // 更新mDataContentData1的值
String dataContentData3 = js.has(DataColumns.DATA3) ? js.getString(DataColumns.DATA3) : ""; // 从JSONObject中获取DataColumns.DATA3字段的值如果不存在则设置为空字符串
if (mIsCreate || !mDataContentData3.equals(dataContentData3)) { // 如果是新创建的数据或者mDataContentData3与dataContentData3不相等
mDiffDataValues.put(DataColumns.DATA3, dataContentData3); // 将dataContentData3添加到差异数据中
}
mDataContentData3 = dataContentData3; // 更新mDataContentData3的值
}
/*
*
*
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
// 如果数据还未在数据库中创建则打印错误日志并返回null
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
//创建JSONObject对象。并将相关数据放入其中并返回。
JSONObject js = new JSONObject();
js.put(DataColumns.ID, mDataId); // 将mDataId字段的值放入JSONObject中
js.put(DataColumns.MIME_TYPE, mDataMimeType); // 将mDataMimeType字段的值放入JSONObject中
js.put(DataColumns.CONTENT, mDataContent); // 将mDataContent字段的值放入JSONObject中
js.put(DataColumns.DATA1, mDataContentData1); // 将mDataContentData1字段的值放入JSONObject中
js.put(DataColumns.DATA3, mDataContentData3); // 将mDataContentData3字段的值放入JSONObject中
return js; // 返回JSONObject对象
}
/*
* commit
*
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
// 如果数据还未在数据库中创建,则执行插入操作
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
// 如果mDataId为无效值并且mDiffDataValues中包含DataColumns.ID字段则移除该字段
mDiffDataValues.remove(DataColumns.ID);
}
// 设置DataColumns.NOTE_ID字段的值为noteId
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
// 在Notes.CONTENT_DATA_URI中插入mDiffDataValues并返回Uri对象
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
try {
// 将Uri路径中的第二个片段转换为long类型并赋值给mDataId
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
// 如果获取ID出错则输出错误日志并抛出ActionFailureException异常
=======
=======
>>>>>>> liuyitao-branch
public SqlData(Context context, Cursor c) { public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = false; mIsCreate = false;
@ -356,10 +156,6 @@ public class SqlData {
try { try {
mDataId = Long.valueOf(uri.getPathSegments().get(1)); mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, "Get note id error :" + e.toString()); Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed"); throw new ActionFailureException("create note failed");
} }
@ -367,63 +163,22 @@ public class SqlData {
if (mDiffDataValues.size() > 0) { if (mDiffDataValues.size() > 0) {
int result = 0; int result = 0;
if (!validateVersion) { if (!validateVersion) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果不需要验证版本则直接通过mDataId更新mDiffDataValues到数据库中
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
// 如果需要验证版本则通过noteId和version进行更新
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
=======
=======
>>>>>>> liuyitao-branch
result = mContentResolver.update(ContentUris.withAppendedId( result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else { } else {
result = mContentResolver.update(ContentUris.withAppendedId( result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] { + " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
String.valueOf(noteId), String.valueOf(version) String.valueOf(noteId), String.valueOf(version)
}); });
} }
if (result == 0) { if (result == 0) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果没有更新任何数据,则输出警告日志
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.w(TAG, "there is no update. maybe user updates note when syncing"); Log.w(TAG, "there is no update. maybe user updates note when syncing");
} }
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 清空差异数据
mDiffDataValues.clear();
// 将新建标记设为false
mIsCreate = false;
}
/**
* ID
* @return ID
*/
public long getId() {
return mDataId;
}
=======
=======
>>>>>>> liuyitao-branch
mDiffDataValues.clear(); mDiffDataValues.clear();
mIsCreate = false; mIsCreate = false;
} }
@ -431,8 +186,4 @@ public class SqlData {
public long getId() { public long getId() {
return mDataId; return mDataId;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }

@ -43,116 +43,6 @@ public class SqlNote {
private static final int INVALID_ID = -99999; private static final int INVALID_ID = -99999;
<<<<<<< HEAD
<<<<<<< HEAD
// 定义查询笔记的投影,包含需要查询的列
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, // 笔记ID
NoteColumns.ALERTED_DATE, // 提醒时间
NoteColumns.BG_COLOR_ID, // 背景颜色
NoteColumns.CREATED_DATE, // 创建时间
NoteColumns.HAS_ATTACHMENT, // 是否有附件
NoteColumns.MODIFIED_DATE, // 修改时间
NoteColumns.NOTES_COUNT, // 子笔记数量
NoteColumns.PARENT_ID, // 父笔记ID
NoteColumns.SNIPPET, // 摘要
NoteColumns.TYPE, // 类型
NoteColumns.WIDGET_ID, // Widget ID
NoteColumns.WIDGET_TYPE, // Widget 类型
NoteColumns.SYNC_ID, // 同步ID
NoteColumns.LOCAL_MODIFIED, // 本地修改标记
NoteColumns.ORIGIN_PARENT_ID, // 原始父笔记ID
NoteColumns.GTASK_ID, // Google Task ID
NoteColumns.VERSION // 版本号
};
public static final int ID_COLUMN = 0; // ID 列索引
public static final int ALERTED_DATE_COLUMN = 1; // ALERTED_DATE 列索引
public static final int BG_COLOR_ID_COLUMN = 2; // BG_COLOR_ID 列索引
public static final int CREATED_DATE_COLUMN = 3; // CREATED_DATE 列索引
public static final int HAS_ATTACHMENT_COLUMN = 4; // HAS_ATTACHMENT 列索引
public static final int MODIFIED_DATE_COLUMN = 5; // MODIFIED_DATE 列索引
public static final int NOTES_COUNT_COLUMN = 6; // NOTES_COUNT 列索引
public static final int PARENT_ID_COLUMN = 7; // PARENT_ID 列索引
public static final int SNIPPET_COLUMN = 8; // SNIPPET 列索引
public static final int TYPE_COLUMN = 9; // TYPE 列索引
public static final int WIDGET_ID_COLUMN = 10; // WIDGET_ID 列索引
public static final int WIDGET_TYPE_COLUMN = 11; // WIDGET_TYPE 列索引
public static final int SYNC_ID_COLUMN = 12; // SYNC_ID 列索引
public static final int LOCAL_MODIFIED_COLUMN = 13; // LOCAL_MODIFIED 列索引
public static final int ORIGIN_PARENT_ID_COLUMN = 14; // ORIGIN_PARENT_ID 列索引
public static final int GTASK_ID_COLUMN = 15; // GTASK_ID 列索引
public static final int VERSION_COLUMN = 16; // VERSION 列索引
private Context mContext; // 上下文对象
private ContentResolver mContentResolver; // ContentResolver 对象
private boolean mIsCreate; // 是否是新建数据的标记
private long mId; // 数据ID
private long mAlertDate; // 提醒时间
private int mBgColorId; // 背景颜色
private long mCreatedDate; // 创建时间
private int mHasAttachment; // 是否有附件
private long mModifiedDate; // 修改时间
private long mParentId; // 父笔记ID
private String mSnippet; // 摘要
private int mType; // 类型
private int mWidgetId; // Widget ID
private int mWidgetType; // Widget 类型
private long mOriginParent; // 原始父笔记ID
private long mVersion; // 版本号
private ContentValues mDiffNoteValues; // 笔记数据差异值
private ArrayList<SqlData> mDataList; // SqlData 列表
public SqlNote(Context context) {
mContext = context; // 初始化上下文对象
mContentResolver = context.getContentResolver(); // 初始化 ContentResolver 对象
mIsCreate = true; // 标记为新建数据
mId = INVALID_ID; // 初始化 ID 为无效值
mAlertDate = 0; // 初始化提醒时间为 0
mBgColorId = ResourceParser.getDefaultBgId(context);// 初始化背景颜色为默认值
mCreatedDate = System.currentTimeMillis(); // 初始化创建时间为当前时间
mHasAttachment = 0; // 初始化是否有附件为 0
mModifiedDate = System.currentTimeMillis(); // 初始化修改时间为当前时间
mParentId = 0; // 初始化父笔记 ID 为 0
mSnippet = ""; // 初始化摘要为空字符串
mType = Notes.TYPE_NOTE; // 初始化类型为普通笔记
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; // 初始化 Widget ID 为无效值
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 初始化 Widget 类型为无效类型
mOriginParent = 0; // 初始化原始父笔记 ID 为 0
mVersion = 0; // 初始化版本号为 0
mDiffNoteValues = new ContentValues(); // 初始化笔记数据差异值为空 ContentValues 对象
mDataList = new ArrayList<SqlData>(); // 初始化 SqlData 列表为空列表
}
public SqlNote(Context context, Cursor c) {
mContext = context; // 初始化上下文对象
mContentResolver = context.getContentResolver(); // 初始化 ContentResolver 对象
mIsCreate = false; // 标记为非新建数据
loadFromCursor(c); // 从 Cursor 中加载数据
mDataList = new ArrayList<SqlData>(); // 初始化 SqlData 列表为空列表
if (mType == Notes.TYPE_NOTE) // 如果类型为普通笔记
loadDataContent(); // 加载笔记内容数据
mDiffNoteValues = new ContentValues(); // 初始化笔记数据差异值为新的 ContentValues 对象
}
public SqlNote(Context context, long id) {
mContext = context; // 初始化上下文对象
mContentResolver = context.getContentResolver(); // 初始化 ContentResolver 对象
mIsCreate = false; // 标记为非新建数据
loadFromCursor(id); // 从数据库中加载指定 ID 的数据
mDataList = new ArrayList<SqlData>(); // 初始化 SqlData 列表为空列表
if (mType == Notes.TYPE_NOTE) // 如果类型为普通笔记
loadDataContent(); // 加载笔记内容数据
mDiffNoteValues = new ContentValues(); // 初始化笔记数据差异值为新的 ContentValues 对象
}
private void loadFromCursor(long id) {
Cursor c = null;// 初始化游标对象
try {
// 通过 ID 查询笔记数据
=======
=======
>>>>>>> liuyitao-branch
public static final String[] PROJECTION_NOTE = new String[] { public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID, NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE, NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
@ -279,28 +169,11 @@ public class SqlNote {
private void loadFromCursor(long id) { private void loadFromCursor(long id) {
Cursor c = null; Cursor c = null;
try { try {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)", c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] { new String[] {
String.valueOf(id) String.valueOf(id)
}, null); }, null);
if (c != null) { if (c != null) {
<<<<<<< HEAD
<<<<<<< HEAD
c.moveToNext(); // 移动到第一条数据
loadFromCursor(c); // 载入数据
} else {
Log.w(TAG, "loadFromCursor: cursor = null");// 输出警告日志
}
} finally {
if (c != null)
c.close(); // 关闭游标
=======
=======
>>>>>>> liuyitao-branch
c.moveToNext(); c.moveToNext();
loadFromCursor(c); loadFromCursor(c);
} else { } else {
@ -309,39 +182,10 @@ public class SqlNote {
} finally { } finally {
if (c != null) if (c != null)
c.close(); c.close();
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
private void loadFromCursor(Cursor c) { private void loadFromCursor(Cursor c) {
<<<<<<< HEAD
<<<<<<< HEAD
mId = c.getLong(ID_COLUMN); // 从游标中获取并设置 ID
mAlertDate = c.getLong(ALERTED_DATE_COLUMN); // 从游标中获取并设置提醒日期
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN); // 从游标中获取并设置背景色ID
mCreatedDate = c.getLong(CREATED_DATE_COLUMN); // 从游标中获取并设置创建日期
mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN); // 从游标中获取并设置是否有附件
mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN); // 从游标中获取并设置修改日期
mParentId = c.getLong(PARENT_ID_COLUMN); // 从游标中获取并设置父节点ID
mSnippet = c.getString(SNIPPET_COLUMN); // 从游标中获取并设置摘要
mType = c.getInt(TYPE_COLUMN); // 从游标中获取并设置类型
mWidgetId = c.getInt(WIDGET_ID_COLUMN); // 从游标中获取并设置小部件ID
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); // 从游标中获取并设置小部件类型
mVersion = c.getLong(VERSION_COLUMN); // 从游标中获取并设置版本号
}
private void loadDataContent() {
Cursor c = null; // 初始化游标对象
mDataList.clear(); // 清空数据列表
try {
// 通过笔记ID查询数据内容
=======
=======
>>>>>>> liuyitao-branch
mId = c.getLong(ID_COLUMN); mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN); mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
@ -360,34 +204,12 @@ public class SqlNote {
Cursor c = null; Cursor c = null;
mDataList.clear(); mDataList.clear();
try { try {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] { "(note_id=?)", new String[] {
String.valueOf(mId) String.valueOf(mId)
}, null); }, null);
if (c != null) { if (c != null) {
if (c.getCount() == 0) { if (c.getCount() == 0) {
<<<<<<< HEAD
<<<<<<< HEAD
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();// 关闭游标
=======
=======
>>>>>>> liuyitao-branch
Log.w(TAG, "it seems that the note has not data"); Log.w(TAG, "it seems that the note has not data");
return; return;
} }
@ -401,32 +223,11 @@ public class SqlNote {
} finally { } finally {
if (c != null) if (c != null)
c.close(); c.close();
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
public boolean setContent(JSONObject js) { public boolean setContent(JSONObject js) {
try { try {
<<<<<<< HEAD
<<<<<<< HEAD
// 解析JSON对象中的note字段
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
// 检查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) {
// 如果类型为文件夹类型则更新snippet和type
// for folder we can only update the snnipet and type
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
// 如果正在创建一个新的note或者之前的snippet和当前传入的snippet不相等则更新snippet字段
=======
=======
>>>>>>> liuyitao-branch
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
Log.w(TAG, "cannot set system folder"); Log.w(TAG, "cannot set system folder");
@ -434,10 +235,6 @@ public class SqlNote {
// for folder we can only update the snnipet and type // for folder we can only update the snnipet and type
String snippet = note.has(NoteColumns.SNIPPET) ? note String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : ""; .getString(NoteColumns.SNIPPET) : "";
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mIsCreate || !mSnippet.equals(snippet)) { if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
} }
@ -445,65 +242,25 @@ public class SqlNote {
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE; : Notes.TYPE_NOTE;
<<<<<<< HEAD
<<<<<<< HEAD
// 如果正在创建一个新的note或者之前的type和当前传入的type不相等则更新type字段
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mIsCreate || mType != type) { if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type); mDiffNoteValues.put(NoteColumns.TYPE, type);
} }
mType = type; mType = type;
<<<<<<< HEAD
<<<<<<< HEAD
}else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
// 如果类型为笔记类型则解析data数组
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
// 获取note的ID字段如果没有则设置为INVALID_ID常量值
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
// 如果正在创建一个新的note或者之前的id和当前传入的id不相等则更新ID字段
=======
} 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;
>>>>>>> liuyitao-branch
=======
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
>>>>>>> liuyitao-branch
if (mIsCreate || mId != id) { if (mIsCreate || mId != id) {
mDiffNoteValues.put(NoteColumns.ID, id); mDiffNoteValues.put(NoteColumns.ID, id);
} }
mId = id; mId = id;
<<<<<<< HEAD
<<<<<<< HEAD
// 解析并更新其他成员变量
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note.getLong(NoteColumns.ALERTED_DATE) : 0;
=======
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
.getLong(NoteColumns.ALERTED_DATE) : 0;
>>>>>>> liuyitao-branch
=======
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
.getLong(NoteColumns.ALERTED_DATE) : 0; .getLong(NoteColumns.ALERTED_DATE) : 0;
>>>>>>> liuyitao-branch
if (mIsCreate || mAlertDate != alertDate) { if (mIsCreate || mAlertDate != alertDate) {
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate); mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
} }
mAlertDate = alertDate; mAlertDate = alertDate;
<<<<<<< HEAD
<<<<<<< HEAD
// 解析snippet和type字段
String snippet = note.has(NoteColumns.SNIPPET) ? note.getString(NoteColumns.SNIPPET) : "";
// 如果正在创建一个新的note或者之前的snippet和当前传入的snippet不相等则更新snippet字段
=======
=======
>>>>>>> liuyitao-branch
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext); .getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
if (mIsCreate || mBgColorId != bgColorId) { if (mIsCreate || mBgColorId != bgColorId) {
@ -541,43 +298,18 @@ public class SqlNote {
String snippet = note.has(NoteColumns.SNIPPET) ? note String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : ""; .getString(NoteColumns.SNIPPET) : "";
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mIsCreate || !mSnippet.equals(snippet)) { if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
} }
mSnippet = snippet; mSnippet = snippet;
<<<<<<< HEAD
<<<<<<< HEAD
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) : Notes.TYPE_NOTE;
// 如果正在创建一个新的note或者之前的type和当前传入的type不相等则更新type字段
=======
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
>>>>>>> liuyitao-branch
=======
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE) int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE; : Notes.TYPE_NOTE;
>>>>>>> liuyitao-branch
if (mIsCreate || mType != type) { if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type); mDiffNoteValues.put(NoteColumns.TYPE, type);
} }
mType = type; mType = type;
<<<<<<< HEAD
<<<<<<< HEAD
// 遍历data数组
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null;
// 检查data数组中的id字段并查找对应的SqlData对象
=======
=======
>>>>>>> liuyitao-branch
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID) int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
: AppWidgetManager.INVALID_APPWIDGET_ID; : AppWidgetManager.INVALID_APPWIDGET_ID;
if (mIsCreate || mWidgetId != widgetId) { if (mIsCreate || mWidgetId != widgetId) {
@ -602,10 +334,6 @@ public class SqlNote {
for (int i = 0; i < dataArray.length(); i++) { for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i); JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null; SqlData sqlData = null;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (data.has(DataColumns.ID)) { if (data.has(DataColumns.ID)) {
long dataId = data.getLong(DataColumns.ID); long dataId = data.getLong(DataColumns.ID);
for (SqlData temp : mDataList) { for (SqlData temp : mDataList) {
@ -615,104 +343,19 @@ public class SqlNote {
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 如果未找到对应的SqlData对象则创建一个新的对象并添加到数据列表中
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (sqlData == null) { if (sqlData == null) {
sqlData = new SqlData(mContext); sqlData = new SqlData(mContext);
mDataList.add(sqlData); mDataList.add(sqlData);
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 调用SqlData对象的setContent方法传递JSON数据进行处理
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
sqlData.setContent(data); sqlData.setContent(data);
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
<<<<<<< HEAD
<<<<<<< HEAD
// 处理异常情况打印错误信息并返回false
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 返回true表示设置内容成功
return true;
}
public JSONObject getContent() {// 定义一个返回JSONObject类型的方法getContent()
try {// 尝试执行以下代码块
// 创建一个空的 JSONObject 对象
JSONObject js = new JSONObject();// 实例化一个空的JSONObject对象
// 如果笔记还没有创建到数据库中,则返回 null
if (mIsCreate) {// 判断mIsCreate属性值
Log.e(TAG, "it seems that we haven't created this in database yet");// 打印错误日志
return null;// 返回null
}
// 根据笔记类型创建不同的 JSONObject
JSONObject note = new JSONObject(); // 实例化一个JSONObject对象
if (mType == Notes.TYPE_NOTE) { // 判断mType属性值是否为Notes.TYPE_NOTE
note.put(NoteColumns.ID, mId); // 向note对象中添加ID键值对
note.put(NoteColumns.ALERTED_DATE, mAlertDate); // 添加ALERTED_DATE键值对
note.put(NoteColumns.BG_COLOR_ID, mBgColorId); // 添加BG_COLOR_ID键值对
note.put(NoteColumns.CREATED_DATE, mCreatedDate); // 添加CREATED_DATE键值对
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment); // 添加HAS_ATTACHMENT键值对
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate); // 添加MODIFIED_DATE键值对
note.put(NoteColumns.PARENT_ID, mParentId); // 添加PARENT_ID键值对
note.put(NoteColumns.SNIPPET, mSnippet); // 添加SNIPPET键值对
note.put(NoteColumns.TYPE, mType); // 添加TYPE键值对
note.put(NoteColumns.WIDGET_ID, mWidgetId); // 添加WIDGET_ID键值对
note.put(NoteColumns.WIDGET_TYPE, mWidgetType); // 添加WIDGET_TYPE键值对
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent); // 添加ORIGIN_PARENT_ID键值对
// 将笔记信息添加为 META_HEAD_NOTE 的值
js.put(GTaskStringUtils.META_HEAD_NOTE, note); // 将note对象添加为js对象的META_HEAD_NOTE键值对
// 如果是笔记类型,将其附加数据添加到 META_HEAD_DATA 中
JSONArray dataArray = new JSONArray(); // 实例化一个JSONArray对象
for (SqlData sqlData : mDataList) { // 遍历mDataList列表
JSONObject data = sqlData.getContent(); // 调用sqlData对象的getContent方法并将返回值赋给data
if (data != null) { // 判断data是否为null
dataArray.put(data); // 将data对象添加到dataArray中
}
}
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);// 将dataArray对象添加为js对象的META_HEAD_DATA键值对
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { // 判断mType属性值是否为Notes.TYPE_FOLDER或Notes.TYPE_SYSTEM
note.put(NoteColumns.ID, mId); // 添加ID键值对
note.put(NoteColumns.TYPE, mType); // 添加TYPE键值对
note.put(NoteColumns.SNIPPET, mSnippet); // 添加SNIPPET键值对
// 将笔记信息添加为 META_HEAD_NOTE 的值
js.put(GTaskStringUtils.META_HEAD_NOTE, note); // 将note对象添加为js对象的META_HEAD_NOTE键值对
}
return js;
} catch (JSONException e) { // 捕获JSONException异常
Log.e(TAG, e.toString()); // 打印异常信息
e.printStackTrace(); // 打印异常轨迹
}
// 如果出现异常,则返回 null
return null; // 返回null
=======
=======
>>>>>>> liuyitao-branch
return true; return true;
} }
@ -762,72 +405,16 @@ public class SqlNote {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
public void setParentId(long id) { public void setParentId(long id) {
mParentId = id; mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id); mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
<<<<<<< HEAD
<<<<<<< HEAD
}//设置父节点ID
=======
}
>>>>>>> liuyitao-branch
=======
} }
>>>>>>> liuyitao-branch
public void setGtaskId(String gid) { public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
} }
<<<<<<< HEAD
<<<<<<< HEAD
//设置Google任务ID
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
//设置同步ID
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
//重置本地修改标记
public long getId() {
return mId;
}
//获取笔记ID
public long getParentId() {
return mParentId;
}
//获取父节点ID
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)) {
// 如果mId为无效值并且mDiffNoteValues中包含NoteColumns.ID字段则移除该字段
mDiffNoteValues.remove(NoteColumns.ID);
}
// 在Notes.CONTENT_NOTE_URI中插入mDiffNoteValues并返回Uri对象
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
try {
// 将Uri路径中的第二个片段转换为long类型并赋值给mId
=======
=======
>>>>>>> liuyitao-branch
public void setSyncId(long syncId) { public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
@ -861,10 +448,6 @@ public class SqlNote {
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
try { try {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
mId = Long.valueOf(uri.getPathSegments().get(1)); mId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString()); Log.e(TAG, "Get note id error :" + e.toString());
@ -874,26 +457,12 @@ public class SqlNote {
throw new IllegalStateException("Create thread id failed"); throw new IllegalStateException("Create thread id failed");
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 如果是笔记类型,则循环提交数据内容更改
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mType == Notes.TYPE_NOTE) { if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) { for (SqlData sqlData : mDataList) {
sqlData.commit(mId, false, -1); sqlData.commit(mId, false, -1);
} }
} }
} else { } else {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果不是新建笔记
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
Log.e(TAG, "No such note"); Log.e(TAG, "No such note");
throw new IllegalStateException("Try to update note with invalid id"); throw new IllegalStateException("Try to update note with invalid id");
@ -902,20 +471,6 @@ public class SqlNote {
mVersion ++; mVersion ++;
int result = 0; int result = 0;
if (!validateVersion) { if (!validateVersion) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果不需要验证版本则直接通过mId更新mDiffNoteValues到数据库中
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId)
});
} else {
// 如果需要验证版本则通过mId和mVersion进行更新
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
=======
=======
>>>>>>> liuyitao-branch
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] { + NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId) String.valueOf(mId)
@ -923,10 +478,6 @@ public class SqlNote {
} else { } else {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
new String[] { new String[] {
String.valueOf(mId), String.valueOf(mVersion) String.valueOf(mId), String.valueOf(mVersion)
}); });
@ -936,13 +487,6 @@ public class SqlNote {
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 如果是笔记类型,则循环提交数据内容更改
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (mType == Notes.TYPE_NOTE) { if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) { for (SqlData sqlData : mDataList) {
sqlData.commit(mId, validateVersion, mVersion); sqlData.commit(mId, validateVersion, mVersion);
@ -950,26 +494,11 @@ public class SqlNote {
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 刷新本地信息
=======
// refresh local info
>>>>>>> liuyitao-branch
=======
// refresh local info // refresh local info
>>>>>>> liuyitao-branch
loadFromCursor(mId); loadFromCursor(mId);
if (mType == Notes.TYPE_NOTE) if (mType == Notes.TYPE_NOTE)
loadDataContent(); loadDataContent();
<<<<<<< HEAD
<<<<<<< HEAD
// 清空mDiffNoteValues和将mIsCreate设置为false
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
mDiffNoteValues.clear(); mDiffNoteValues.clear();
mIsCreate = false; mIsCreate = false;
} }

@ -33,122 +33,6 @@ import org.json.JSONObject;
public class Task extends Node { public class Task extends Node {
<<<<<<< HEAD
<<<<<<< HEAD
private static final String TAG = Task.class.getSimpleName(); // 定义一个私有静态常量TAG值为Task.class.getSimpleName()
private boolean mCompleted; // 定义一个私有的boolean类型变量mCompleted
private String mNotes; // 定义一个私有的String类型变量mNotes
private JSONObject mMetaInfo; // 定义一个私有的JSONObject类型变量mMetaInfo
private Task mPriorSibling; // 定义一个私有的Task类型变量mPriorSibling
private TaskList mParent; // 定义一个私有的TaskList类型变量mParent
public Task() { // 定义一个公有的无参构造方法Task()
super(); // 调用父类的无参构造方法
mCompleted = false; // 将mCompleted变量初始化为false
mNotes = null; // 将mNotes变量初始化为null
mPriorSibling = null; // 将mPriorSibling变量初始化为null
mParent = null; // 将mParent变量初始化为null
mMetaInfo = null; // 将mMetaInfo变量初始化为null
}
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject(); // 创建一个JSONObject对象js
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// 将键为GTASK_JSON_ACTION_TYPE的值设置为"create"
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// 将键为GTASK_JSON_ACTION_ID的值设置为actionId
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
// 将键为GTASK_JSON_INDEX的值设置为当前任务在父列表中的位置
// entity_delta
JSONObject entity = new JSONObject(); // 创建一个JSONObject对象entity
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); // 将键为GTASK_JSON_NAME的值设为任务名
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); // 将键为GTASK_JSON_CREATOR_ID的值设为"null"
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_TASK); // 将键为GTASK_JSON_ENTITY_TYPE的值设为"task"
if (getNotes() != null) { // 如果备注信息不为空
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes()); // 将键为GTASK_JSON_NOTES的值设为备注信息
}
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); // 将键为GTASK_JSON_ENTITY_DELTA的值设为entity
// parent_id
js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid()); // 将键为GTASK_JSON_PARENT_ID的值设为父列表的唯一标识符
// dest_parent_type
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
// 将键为GTASK_JSON_DEST_PARENT_TYPE的值设为"group"
// list_id
js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid()); // 将键为GTASK_JSON_LIST_ID的值设为父列表的唯一标识符
// prior_sibling_id
if (mPriorSibling != null) { // 如果前一个兄弟节点不为空
js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid()); // 将键为GTASK_JSON_PRIOR_SIBLING_ID的值设为前一个兄弟节点的唯一标识符
}
} catch (JSONException e) { // 捕捉JSONException异常
Log.e(TAG, e.toString()); // 在日志中输出异常信息
e.printStackTrace();
throw new ActionFailureException("fail to generate task-create jsonobject"); // 抛出ActionFailureException异常
}
return js; // 返回JSONObject对象js
}
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject(); // 创建一个JSONObject对象js
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// 将键为GTASK_JSON_ACTION_TYPE的值设置为"update"
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// 将键为GTASK_JSON_ACTION_ID的值设置为actionId
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// 将键为GTASK_JSON_ID的值设置为当前任务的唯一标识符
// entity_delta
JSONObject entity = new JSONObject(); // 创建一个JSONObject对象entity
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); // 将键为GTASK_JSON_NAME的值设为任务名
if (getNotes() != null) { // 如果备注信息不为空
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes()); // 将键为GTASK_JSON_NOTES的值设为备注信息
}
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted()); // 将键为GTASK_JSON_DELETED的值设置为任务是否被删除的状态
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); // 将键为GTASK_JSON_ENTITY_DELTA的值设为entity
} catch (JSONException e) { // 捕捉JSONException异常
Log.e(TAG, e.toString()); // 在日志中输出异常信息
e.printStackTrace();
throw new ActionFailureException("fail to generate task-update jsonobject"); // 抛出ActionFailureException异常
}
return js; // 返回JSONObject对象js
}
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) { // 如果参数不为空
try {
// 获取Google Task的ID并设置到本地笔记或任务中
=======
=======
>>>>>>> liuyitao-branch
private static final String TAG = Task.class.getSimpleName(); private static final String TAG = Task.class.getSimpleName();
private boolean mCompleted; private boolean mCompleted;
@ -255,86 +139,35 @@ public class Task extends Node {
if (js != null) { if (js != null) {
try { try {
// id // id
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 获取Google Task的最后修改时间戳并设置到本地笔记或任务中
=======
// last_modified // last_modified
>>>>>>> liuyitao-branch
=======
// last_modified
>>>>>>> liuyitao-branch
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 获取Google Task的名称并设置到本地笔记或任务中
=======
// name
>>>>>>> liuyitao-branch
=======
// name // name
>>>>>>> liuyitao-branch
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 获取Google Task的备注信息并设置到本地笔记或任务中
=======
// notes // notes
>>>>>>> liuyitao-branch
=======
// notes
>>>>>>> liuyitao-branch
if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) { if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES)); setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 获取Google Task的删除状态并设置到本地笔记或任务中
=======
// deleted
>>>>>>> liuyitao-branch
=======
// deleted // deleted
>>>>>>> liuyitao-branch
if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) { if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED)); setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 获取Google Task的完成状态并设置到本地笔记或任务中
if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
}
} catch (JSONException e) { // 如果解析过程出现异常
// 记录异常日志并抛出异常
=======
=======
>>>>>>> liuyitao-branch
// completed // completed
if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) { if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED)); setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
} }
} catch (JSONException e) { } catch (JSONException e) {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
throw new ActionFailureException("fail to get task content from jsonobject"); throw new ActionFailureException("fail to get task content from jsonobject");
@ -344,39 +177,6 @@ public class Task extends Node {
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
<<<<<<< HEAD
<<<<<<< HEAD
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) { // 如果参数为空或缺少必要的数据字段
Log.w(TAG, "setContentByLocalJSON: nothing is available"); // 记录警告日志
}
try {
// 从JSON对象中获取笔记和数据数组
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); // 获取数据对象
// 如果数据的MIME类型是笔记类型
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(); // 打印异常堆栈信息
=======
=======
>>>>>>> liuyitao-branch
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) { || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
} }
@ -401,29 +201,10 @@ public class Task extends Node {
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
<<<<<<< HEAD
<<<<<<< HEAD
String name = getName(); // 获取名称
try {
if (mMetaInfo == null) { // 如果元信息为空
// 从Web创建新任务
if (name == null) { // 如果名称为空
Log.w(TAG, "the note seems to be an empty one"); // 记录警告日志
return null; // 返回null
}
// 创建JSON对象并填充数据
=======
=======
>>>>>>> liuyitao-branch
String name = getName(); String name = getName();
try { try {
if (mMetaInfo == null) { if (mMetaInfo == null) {
@ -433,45 +214,15 @@ public class Task extends Node {
return null; return null;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
JSONObject note = new JSONObject(); JSONObject note = new JSONObject();
JSONArray dataArray = new JSONArray(); JSONArray dataArray = new JSONArray();
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
<<<<<<< HEAD
<<<<<<< HEAD
data.put(DataColumns.CONTENT, name); // 设置数据内容为名称
=======
data.put(DataColumns.CONTENT, name);
>>>>>>> liuyitao-branch
=======
data.put(DataColumns.CONTENT, name); data.put(DataColumns.CONTENT, name);
>>>>>>> liuyitao-branch
dataArray.put(data); dataArray.put(data);
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
js.put(GTaskStringUtils.META_HEAD_NOTE, note); js.put(GTaskStringUtils.META_HEAD_NOTE, note);
<<<<<<< HEAD
<<<<<<< HEAD
return js; // 返回JSON对象
} 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);
// 如果数据的MIME类型是笔记类型
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
data.put(DataColumns.CONTENT, getName()); // 设置数据内容为名称
break; // 跳出循环
=======
=======
>>>>>>> liuyitao-branch
return js; return js;
} else { } else {
// synced task // synced task
@ -483,164 +234,34 @@ public class Task extends Node {
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) { if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
data.put(DataColumns.CONTENT, getName()); data.put(DataColumns.CONTENT, getName());
break; break;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE); note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
<<<<<<< HEAD
<<<<<<< HEAD
return mMetaInfo; // 返回元信息对象
}
} catch (JSONException e) { // 如果解析过程出现异常
Log.e(TAG, e.toString()); // 记录异常日志
e.printStackTrace(); // 打印异常堆栈信息
return null; // 返回null
=======
=======
>>>>>>> liuyitao-branch
return mMetaInfo; return mMetaInfo;
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
return null; return null;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
public void setMetaInfo(MetaData metaData) { public void setMetaInfo(MetaData metaData) {
<<<<<<< HEAD
<<<<<<< HEAD
if (metaData != null && metaData.getNotes() != null) { // 如果元数据不为空且笔记不为空
try {
mMetaInfo = new JSONObject(metaData.getNotes()); // 将笔记转换为JSON对象
} catch (JSONException e) { // 如果转换过程出现异常
Log.w(TAG, e.toString()); // 记录警告日志
mMetaInfo = null; // 设置元信息为空
=======
=======
>>>>>>> liuyitao-branch
if (metaData != null && metaData.getNotes() != null) { if (metaData != null && metaData.getNotes() != null) {
try { try {
mMetaInfo = new JSONObject(metaData.getNotes()); mMetaInfo = new JSONObject(metaData.getNotes());
} catch (JSONException e) { } catch (JSONException e) {
Log.w(TAG, e.toString()); Log.w(TAG, e.toString());
mMetaInfo = null; mMetaInfo = null;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
//获取同步操作类型
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
try { try {
JSONObject noteInfo = null; JSONObject noteInfo = null;
if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) { if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
<<<<<<< HEAD
<<<<<<< HEAD
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;
}//获取任务的父任务列表
=======
=======
>>>>>>> liuyitao-branch
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
} }
@ -726,9 +347,5 @@ public class Task extends Node {
public TaskList getParent() { public TaskList getParent() {
return this.mParent; return this.mParent;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }

@ -31,68 +31,6 @@ import java.util.ArrayList;
public class TaskList extends Node { public class TaskList extends Node {
<<<<<<< HEAD
<<<<<<< HEAD
private static final String TAG = TaskList.class.getSimpleName(); // TAG用于在日志中标识类名
private int mIndex; // 任务列表的索引
private ArrayList<Task> mChildren; // 任务列表的子任务集合
/**
* TaskListmChildrenmIndex
*/
public TaskList() {
super(); // 调用父类Node的构造方法
mChildren = new ArrayList<Task>(); // 初始化子任务集合
mIndex = 1; // 初始化索引为1
}
/**
* JSONObject
*
* @param actionId ID
* @return JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject(); // 创建一个JSONObject对象js
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// 将键为GTASK_JSON_ACTION_TYPE的值设置为"create"
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// 将键为GTASK_JSON_ACTION_ID的值设置为actionId
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
// 将键为GTASK_JSON_INDEX的值设置为mIndex
// entity_delta
JSONObject entity = new JSONObject(); // 创建一个JSONObject对象entity
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); // 将键为GTASK_JSON_NAME的值设为任务列表名称
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); // 将键为GTASK_JSON_CREATOR_ID的值设为"null"
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
// 将键为GTASK_JSON_ENTITY_TYPE的值设置为GTASK_JSON_TYPE_GROUP
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
// 将键为GTASK_JSON_ENTITY_DELTA的值设为entity
} catch (JSONException e) { // 捕捉JSONException异常
Log.e(TAG, e.toString()); // 在日志中输出异常信息
e.printStackTrace();
throw new ActionFailureException("fail to generate tasklist-create jsonobject");
// 抛出ActionFailureException异常
}
return js; // 返回JSONObject对象js
}
=======
=======
>>>>>>> liuyitao-branch
private static final String TAG = TaskList.class.getSimpleName(); private static final String TAG = TaskList.class.getSimpleName();
private int mIndex; private int mIndex;
@ -136,46 +74,10 @@ public class TaskList extends Node {
return js; return js;
} }
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
public JSONObject getUpdateAction(int actionId) { public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
try { try {
<<<<<<< HEAD
<<<<<<< HEAD
// 设置操作类型为更新
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// 设置操作的ID
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// 设置任务列表的全局ID
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// 创建一个表示任务列表实体变化的JSON对象
JSONObject entity = new JSONObject();
// 设置任务列表的名称
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
// 设置任务列表是否被删除
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
// 将实体变化JSON对象添加到主JSON对象中
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
// 打印异常信息
Log.e(TAG, e.toString());
e.printStackTrace();
// 抛出自定义异常
=======
=======
>>>>>>> liuyitao-branch
// action_type // action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
@ -195,10 +97,6 @@ public class TaskList extends Node {
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
throw new ActionFailureException("fail to generate tasklist-update jsonobject"); throw new ActionFailureException("fail to generate tasklist-update jsonobject");
} }
@ -210,101 +108,28 @@ public class TaskList extends Node {
try { try {
// id // id
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果JSON对象包含ID字段则将ID设置为相应的值
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
} }
// last_modified // last_modified
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果JSON对象包含last_modified字段则将last_modified设置为相应的值
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
} }
// name // name
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
<<<<<<< HEAD
<<<<<<< HEAD
// 如果JSON对象包含name字段则将name设置为相应的值
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
} }
} catch (JSONException e) { } catch (JSONException e) {
<<<<<<< HEAD
<<<<<<< HEAD
// 打印异常信息
Log.e(TAG, e.toString());
e.printStackTrace();
// 抛出自定义异常
=======
Log.e(TAG, e.toString());
e.printStackTrace();
>>>>>>> liuyitao-branch
=======
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
>>>>>>> liuyitao-branch
throw new ActionFailureException("fail to get tasklist content from jsonobject"); throw new ActionFailureException("fail to get tasklist content from jsonobject");
} }
} }
} }
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
<<<<<<< HEAD
<<<<<<< HEAD
// 检查传入的JSON对象是否为空或者不包含指定的字段
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
// 如果不满足条件,则打印警告信息
Log.w(TAG, "setContentByLocalJSON: nothing is available");
}
try {
// 获取头部注释的JSON对象
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_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) {
// 如果是系统类型则根据特定的系统文件夹ID设置名称
if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
// 如果系统文件夹ID是根文件夹的ID则设置名称为预定义前缀加上默认文件夹名
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
// 如果系统文件夹ID是通话记录文件夹的ID则设置名称为预定义前缀加上通话笔记文件夹名
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
+ GTaskStringUtils.FOLDER_CALL_NOTE);
else
// 如果系统文件夹ID无效则打印错误信息
Log.e(TAG, "invalid system folder");
} else {
// 如果类型既不是文件夹类型也不是系统类型,则打印错误信息
Log.e(TAG, "error type");
}
} catch (JSONException e) {
// 打印异常信息
=======
=======
>>>>>>> liuyitao-branch
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
} }
@ -327,112 +152,37 @@ public class TaskList extends Node {
Log.e(TAG, "error type"); Log.e(TAG, "error type");
} }
} catch (JSONException e) { } catch (JSONException e) {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
* JSON
*/
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
try { try {
// 创建一个空的JSON对象
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
// 创建一个文件夹JSON对象
JSONObject folder = new JSONObject(); JSONObject folder = new JSONObject();
// 获取文件夹的名称
String folderName = getName(); String folderName = getName();
// 检查文件夹名称是否以预定义前缀开头,如果是,则去掉前缀
if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)) if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(), folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
folderName.length()); folderName.length());
// 将文件夹名称放入文件夹JSON对象中
folder.put(NoteColumns.SNIPPET, folderName); folder.put(NoteColumns.SNIPPET, folderName);
// 检查文件夹名称是否为默认文件夹或通话笔记文件夹,如果是,则设置文件夹类型为系统类型,否则设置为文件夹类型
=======
=======
>>>>>>> liuyitao-branch
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
JSONObject folder = new JSONObject();
String folderName = getName();
if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
folderName.length());
folder.put(NoteColumns.SNIPPET, folderName);
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT) if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT)
|| folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE)) || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE))
folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
else else
folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
<<<<<<< HEAD
<<<<<<< HEAD
// 将文件夹JSON对象放入根JSON对象中的头部注释字段中
js.put(GTaskStringUtils.META_HEAD_NOTE, folder); js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
// 返回根JSON对象
return js; return js;
} catch (JSONException e) { } catch (JSONException e) {
// 打印异常信息
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
// 返回空值
=======
=======
>>>>>>> liuyitao-branch
js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
return js;
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
return null; return null;
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
/*
*
* @param c
* @return
*/
public int getSyncAction(Cursor c) {
try {
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
=======
=======
>>>>>>> liuyitao-branch
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
try { try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -446,78 +196,23 @@ public class TaskList extends Node {
} }
} else { } else {
// validate gtask id // validate gtask id
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) { if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match"); Log.e(TAG, "gtask id doesn't match");
return SYNC_ACTION_ERROR; return SYNC_ACTION_ERROR;
} }
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) { if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
<<<<<<< HEAD
<<<<<<< HEAD
// 仅有本地修改
return SYNC_ACTION_UPDATE_REMOTE;
} else {
// 对于文件夹冲突,只应用本地修改
=======
=======
>>>>>>> liuyitao-branch
// local modification only // local modification only
return SYNC_ACTION_UPDATE_REMOTE; return SYNC_ACTION_UPDATE_REMOTE;
} else { } else {
// for folder conflicts, just apply local modification // for folder conflicts, just apply local modification
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
return SYNC_ACTION_UPDATE_REMOTE; return SYNC_ACTION_UPDATE_REMOTE;
} }
} }
} catch (Exception e) { } catch (Exception e) {
<<<<<<< HEAD
<<<<<<< HEAD
// 打印异常信息
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
e.printStackTrace(); e.printStackTrace();
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 返回错误的同步操作类型
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)) {
// 如果满足条件,则将该子任务添加到子任务列表中
ret = mChildren.add(task);
if (ret) {
// 设置子任务的前一个兄弟和父任务
=======
=======
>>>>>>> liuyitao-branch
return SYNC_ACTION_ERROR; return SYNC_ACTION_ERROR;
} }
@ -531,69 +226,25 @@ public class TaskList extends Node {
ret = mChildren.add(task); ret = mChildren.add(task);
if (ret) { if (ret) {
// need to set prior sibling and parent // need to set prior sibling and parent
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
task.setPriorSibling(mChildren.isEmpty() ? null : mChildren task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
.get(mChildren.size() - 1)); .get(mChildren.size() - 1));
task.setParent(this); task.setParent(this);
} }
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 返回是否成功添加子任务的信息
return ret; return ret;
} }
/*
*
* @param task
* @param index
* @return
*/
public boolean addChildTask(Task task, int index) { public boolean addChildTask(Task task, int index) {
// 判断子任务应该插入的位置是否合法
if (index < 0 || index > mChildren.size()) { if (index < 0 || index > mChildren.size()) {
// 如果不合法,则记录日志,返回失败
=======
=======
>>>>>>> liuyitao-branch
return ret;
}
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Log.e(TAG, "add child task: invalid index"); Log.e(TAG, "add child task: invalid index");
return false; return false;
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 查找子任务是否已经在列表中
int pos = mChildren.indexOf(task);
// 如果子任务不为空且不在列表中,则执行以下操作
if (task != null && pos == -1) {
// 在指定位置添加子任务
mChildren.add(index, task);
// 更新任务列表
=======
=======
>>>>>>> liuyitao-branch
int pos = mChildren.indexOf(task); int pos = mChildren.indexOf(task);
if (task != null && pos == -1) { if (task != null && pos == -1) {
mChildren.add(index, task); mChildren.add(index, task);
// update the task list // update the task list
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
Task preTask = null; Task preTask = null;
Task afterTask = null; Task afterTask = null;
if (index != 0) if (index != 0)
@ -601,70 +252,11 @@ public class TaskList extends Node {
if (index != mChildren.size() - 1) if (index != mChildren.size() - 1)
afterTask = mChildren.get(index + 1); afterTask = mChildren.get(index + 1);
<<<<<<< HEAD
<<<<<<< HEAD
// 设置前一个兄弟和后一个兄弟
=======
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
task.setPriorSibling(preTask); task.setPriorSibling(preTask);
if (afterTask != null) if (afterTask != null)
afterTask.setPriorSibling(task); afterTask.setPriorSibling(task);
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 返回是否成功添加子任务的信息
return true;
}
/**
*
*
* @param task
* @return
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task); // 查找子任务在列表中的位置
if (index != -1) {
ret = mChildren.remove(task); // 从列表中移除子任务
if (ret) {
// 重置前一个兄弟和父任务
task.setPriorSibling(null); // 将子任务的前一个兄弟设置为null
task.setParent(null); // 将子任务的父任务设置为null
// 更新任务列表
if (index != mChildren.size()) {
mChildren.get(index).setPriorSibling(
index == 0 ? null : mChildren.get(index - 1)); // 将后一个兄弟的前一个兄弟设置为当前子任务的前一个兄弟
}
}
}
return ret; // 返回是否成功移除子任务的信息
}
/*
*
* @param task
* @param index
* @return
*/
public boolean moveChildTask(Task task, int index) {
// 判断子任务应该移动到的位置是否合法
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "move child task: invalid index"); // 记录日志,返回失败
return false;
}
int pos = mChildren.indexOf(task); // 查找子任务在列表中的位置
// 如果子任务不在列表中,则记录日志,返回失败
=======
=======
>>>>>>> liuyitao-branch
return true; return true;
} }
@ -697,100 +289,11 @@ public class TaskList extends Node {
} }
int pos = mChildren.indexOf(task); int pos = mChildren.indexOf(task);
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
if (pos == -1) { if (pos == -1) {
Log.e(TAG, "move child task: the task should in the list"); Log.e(TAG, "move child task: the task should in the list");
return false; return false;
} }
<<<<<<< HEAD
<<<<<<< HEAD
// 如果子任务本来就在目标位置上,则直接返回成功
if (pos == index)
return true;
// 先移除子任务,再添加到指定位置,返回移除和添加的结果
return (removeChildTask(task) && addChildTask(task, index));
}
/*
* ID
* @param gid ID
* @return null
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
if (t.getGid().equals(gid)) { // 比较子任务的全局ID与给定的gid是否相等
return t; // 如果相等,则返回该子任务
}
}
return null; // 如果未找到匹配的子任务则返回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"); // 记录日志,索引位置无效
return null;
}
return mChildren.get(index); // 返回索引位置对应的子任务
}
/*
* ID
* @param gid ID
* @return null
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {
if (task.getGid().equals(gid)) // 比较子任务的全局ID与给定的gid是否相等
return task; // 如果相等,则返回该子任务
}
return null; // 如果未找到匹配的子任务则返回null
}
/*
*
* @return
*/
public ArrayList<Task> getChildTaskList() {
return this.mChildren; // 返回子任务列表
}
/*
*
* @param index
*/
public void setIndex(int index) {
this.mIndex = index; // 设置索引位置
}
/*
*
* @return
*/
public int getIndex() {
return this.mIndex; // 返回索引位置
=======
=======
>>>>>>> liuyitao-branch
if (pos == index) if (pos == index)
return true; return true;
return (removeChildTask(task) && addChildTask(task, index)); return (removeChildTask(task) && addChildTask(task, index));
@ -836,9 +339,5 @@ public class TaskList extends Node {
public int getIndex() { public int getIndex() {
return this.mIndex; return this.mIndex;
<<<<<<< HEAD
>>>>>>> liuyitao-branch
=======
>>>>>>> liuyitao-branch
} }
} }

@ -77,9 +77,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0); NotesListActivity.class), 0);
} }
//notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
// pendingIntent); pendingIntent);
notification.contentIntent = pendingIntent;
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
} }

Loading…
Cancel
Save