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