|
|
|
@ -43,116 +43,6 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
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[] {
|
|
|
|
|
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
|
|
|
|
|
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
|
|
|
|
@ -279,28 +169,11 @@ public class SqlNote {
|
|
|
|
|
private void loadFromCursor(long id) {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
try {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
|
|
|
|
|
new String[] {
|
|
|
|
|
String.valueOf(id)
|
|
|
|
|
}, 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();
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
} else {
|
|
|
|
@ -309,39 +182,10 @@ public class SqlNote {
|
|
|
|
|
} finally {
|
|
|
|
|
if (c != null)
|
|
|
|
|
c.close();
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
@ -360,34 +204,12 @@ public class SqlNote {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
mDataList.clear();
|
|
|
|
|
try {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
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) {
|
|
|
|
|
<<<<<<< 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");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -401,32 +223,11 @@ public class SqlNote {
|
|
|
|
|
} finally {
|
|
|
|
|
if (c != null)
|
|
|
|
|
c.close();
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
|
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);
|
|
|
|
|
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
|
|
|
|
|
Log.w(TAG, "cannot set system folder");
|
|
|
|
@ -434,10 +235,6 @@ public class SqlNote {
|
|
|
|
|
// for folder we can only update the snnipet and type
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
|
|
|
|
}
|
|
|
|
@ -445,65 +242,25 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果正在创建一个新的note,或者之前的type和当前传入的type不相等,则更新type字段
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, 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) {
|
|
|
|
|
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
|
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || mId != id) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ID, 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
|
|
|
|
|
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || mAlertDate != alertDate) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, 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
|
|
|
|
|
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
|
|
|
|
if (mIsCreate || mBgColorId != bgColorId) {
|
|
|
|
@ -541,43 +298,18 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, 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)
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, 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)
|
|
|
|
|
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
if (mIsCreate || mWidgetId != widgetId) {
|
|
|
|
@ -602,10 +334,6 @@ public class SqlNote {
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
|
SqlData sqlData = null;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (data.has(DataColumns.ID)) {
|
|
|
|
|
long dataId = data.getLong(DataColumns.ID);
|
|
|
|
|
for (SqlData temp : mDataList) {
|
|
|
|
@ -615,104 +343,19 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果未找到对应的SqlData对象,则创建一个新的对象并添加到数据列表中
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (sqlData == null) {
|
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 调用SqlData对象的setContent方法,传递JSON数据进行处理
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
sqlData.setContent(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 处理异常情况,打印错误信息并返回false
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -762,72 +405,16 @@ public class SqlNote {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setParentId(long id) {
|
|
|
|
|
mParentId = id;
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
}//设置父节点ID
|
|
|
|
|
=======
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
|
|
|
|
|
public void setGtaskId(String 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) {
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
@ -861,10 +448,6 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
|
try {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
Log.e(TAG, "Get note id error :" + e.toString());
|
|
|
|
@ -874,26 +457,12 @@ public class SqlNote {
|
|
|
|
|
throw new IllegalStateException("Create thread id failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果是笔记类型,则循环提交数据内容更改
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
sqlData.commit(mId, false, -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果不是新建笔记
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
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");
|
|
|
|
@ -902,20 +471,6 @@ public class SqlNote {
|
|
|
|
|
mVersion ++;
|
|
|
|
|
int result = 0;
|
|
|
|
|
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, "("
|
|
|
|
|
+ NoteColumns.ID + "=?)", new String[] {
|
|
|
|
|
String.valueOf(mId)
|
|
|
|
@ -923,10 +478,6 @@ public class SqlNote {
|
|
|
|
|
} else {
|
|
|
|
|
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
|
|
|
|
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
new String[] {
|
|
|
|
|
String.valueOf(mId), String.valueOf(mVersion)
|
|
|
|
|
});
|
|
|
|
@ -936,13 +487,6 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果是笔记类型,则循环提交数据内容更改
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
sqlData.commit(mId, validateVersion, mVersion);
|
|
|
|
@ -950,26 +494,11 @@ public class SqlNote {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 刷新本地信息
|
|
|
|
|
=======
|
|
|
|
|
// refresh local info
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
// refresh local info
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
loadFromCursor(mId);
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
loadDataContent();
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 清空mDiffNoteValues和将mIsCreate设置为false
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> liuyitao-branch
|
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
}
|
|
|
|
|