|
|
@ -0,0 +1,667 @@
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
import net.micode.notes.gtask.exception.ActionFailureException;
|
|
|
|
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SqlNote {
|
|
|
|
|
|
|
|
// 日志标签,用于调试
|
|
|
|
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义一个无效的ID常量
|
|
|
|
|
|
|
|
private static final int INVALID_ID = -99999;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义笔记查询的投影,即需要查询的列名数组
|
|
|
|
|
|
|
|
public static final String[] PROJECTION_NOTE = new String[] {
|
|
|
|
|
|
|
|
NoteColumns.ID, // 笔记ID
|
|
|
|
|
|
|
|
NoteColumns.ALERTED_DATE, // 提醒日期
|
|
|
|
|
|
|
|
NoteColumns.BG_COLOR_ID, // 背景颜色ID
|
|
|
|
|
|
|
|
NoteColumns.CREATED_DATE, // 创建日期
|
|
|
|
|
|
|
|
NoteColumns.HAS_ATTACHMENT, // 是否有附件
|
|
|
|
|
|
|
|
NoteColumns.MODIFIED_DATE, // 修改日期
|
|
|
|
|
|
|
|
NoteColumns.NOTES_COUNT, // 笔记数量
|
|
|
|
|
|
|
|
NoteColumns.PARENT_ID, // 父笔记ID
|
|
|
|
|
|
|
|
NoteColumns.SNIPPET, // 笔记摘要
|
|
|
|
|
|
|
|
NoteColumns.TYPE, // 笔记类型
|
|
|
|
|
|
|
|
NoteColumns.WIDGET_ID, // 小部件ID
|
|
|
|
|
|
|
|
NoteColumns.WIDGET_TYPE, // 小部件类型
|
|
|
|
|
|
|
|
NoteColumns.SYNC_ID, // 同步ID
|
|
|
|
|
|
|
|
NoteColumns.LOCAL_MODIFIED, // 本地修改标记
|
|
|
|
|
|
|
|
NoteColumns.ORIGIN_PARENT_ID, // 原始父笔记ID
|
|
|
|
|
|
|
|
NoteColumns.GTASK_ID, // GTasks ID
|
|
|
|
|
|
|
|
NoteColumns.VERSION // 版本号
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// 定义投影中各列的索引
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int BG_COLOR_ID_COLUMN = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int CREATED_DATE_COLUMN = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int MODIFIED_DATE_COLUMN = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int NOTES_COUNT_COLUMN = 6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int PARENT_ID_COLUMN = 7;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int SNIPPET_COLUMN = 8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int TYPE_COLUMN = 9;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int SYNC_ID_COLUMN = 12;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 上下文环境
|
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 内容解析器
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 是否为创建操作
|
|
|
|
|
|
|
|
private boolean mIsCreate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记ID
|
|
|
|
|
|
|
|
private long mId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 提醒日期
|
|
|
|
|
|
|
|
private long mAlertDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 背景颜色ID
|
|
|
|
|
|
|
|
private int mBgColorId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建日期
|
|
|
|
|
|
|
|
private long mCreatedDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 是否有附件
|
|
|
|
|
|
|
|
private int mHasAttachment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改日期
|
|
|
|
|
|
|
|
private long mModifiedDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 父笔记ID
|
|
|
|
|
|
|
|
private long mParentId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记摘要
|
|
|
|
|
|
|
|
private String mSnippet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记类型
|
|
|
|
|
|
|
|
private int mType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 小部件ID
|
|
|
|
|
|
|
|
private int mWidgetId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 小部件类型
|
|
|
|
|
|
|
|
private int mWidgetType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 原始父笔记ID
|
|
|
|
|
|
|
|
private long mOriginParent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 笔记版本号
|
|
|
|
|
|
|
|
private long mVersion;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 用于记录笔记差异的ContentValues
|
|
|
|
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SqlData对象列表,用于存储额外的数据
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造函数,用于创建新的SqlNote实例
|
|
|
|
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化上下文
|
|
|
|
|
|
|
|
mContext = context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取内容解析器
|
|
|
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 标记为创建操作
|
|
|
|
|
|
|
|
mIsCreate = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置无效的ID
|
|
|
|
|
|
|
|
mId = INVALID_ID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化提醒日期
|
|
|
|
|
|
|
|
mAlertDate = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取默认背景颜色ID
|
|
|
|
|
|
|
|
mBgColorId = ResourceParser.getDefaultBgId(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置当前时间为创建日期
|
|
|
|
|
|
|
|
mCreatedDate = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化附件标记
|
|
|
|
|
|
|
|
mHasAttachment = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置当前时间为修改日期
|
|
|
|
|
|
|
|
mModifiedDate = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化父笔记ID
|
|
|
|
|
|
|
|
mParentId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化笔记摘要
|
|
|
|
|
|
|
|
mSnippet = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置笔记类型为普通笔记
|
|
|
|
|
|
|
|
mType = Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化小部件ID为无效ID
|
|
|
|
|
|
|
|
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化小部件类型为无效类型
|
|
|
|
|
|
|
|
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化原始父笔记ID
|
|
|
|
|
|
|
|
mOriginParent = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化版本号
|
|
|
|
|
|
|
|
mVersion = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的ContentValues对象用于记录差异
|
|
|
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的SqlData列表
|
|
|
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 构造函数,用于从Cursor加载现有的SqlNote实例
|
|
|
|
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化上下文
|
|
|
|
|
|
|
|
mContext = context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取内容解析器
|
|
|
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 标记为非创建操作
|
|
|
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor加载数据
|
|
|
|
|
|
|
|
loadFromCursor(c);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的SqlData列表
|
|
|
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果笔记类型为普通笔记,则加载数据内容
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
|
|
|
loadDataContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的ContentValues对象用于记录差异
|
|
|
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 构造函数,根据指定的ID创建SqlNote实例
|
|
|
|
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化上下文
|
|
|
|
|
|
|
|
mContext = context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取内容解析器
|
|
|
|
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 标记为非创建操作
|
|
|
|
|
|
|
|
mIsCreate = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据ID加载数据
|
|
|
|
|
|
|
|
loadFromCursor(id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的SqlData列表
|
|
|
|
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果笔记类型为普通笔记,则加载数据内容
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
|
|
|
loadDataContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个新的ContentValues对象用于记录差异
|
|
|
|
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 根据ID从数据库中加载数据
|
|
|
|
|
|
|
|
private void loadFromCursor(long id) {
|
|
|
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
|
|
|
try { // 执行查询操作,获取指定ID的笔记数据
|
|
|
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
|
|
|
|
|
|
|
|
new String[] {
|
|
|
|
|
|
|
|
String.valueOf(id)
|
|
|
|
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
// 如果Cursor不为空,则移动到第一条记录
|
|
|
|
|
|
|
|
if (c != null) {
|
|
|
|
|
|
|
|
c.moveToNext();
|
|
|
|
|
|
|
|
loadFromCursor(c); // 从Cursor中加载数据
|
|
|
|
|
|
|
|
} else {// 如果Cursor为空,则记录日志
|
|
|
|
|
|
|
|
Log.w(TAG, "loadFromCursor: cursor = null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
// 关闭Cursor以释放资源
|
|
|
|
|
|
|
|
if (c != null)
|
|
|
|
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中加载数据到SqlNote实例
|
|
|
|
|
|
|
|
private void loadFromCursor(Cursor c) {
|
|
|
|
|
|
|
|
// 从Cursor中获取笔记的各个字段值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取ID并赋值给mId
|
|
|
|
|
|
|
|
mId = c.getLong(ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取提醒日期并赋值给mAlertDate
|
|
|
|
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取背景颜色ID并赋值给mBgColorId
|
|
|
|
|
|
|
|
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取创建日期并赋值给mCreatedDate
|
|
|
|
|
|
|
|
mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取是否有附件的标记并赋值给mHasAttachment
|
|
|
|
|
|
|
|
mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取修改日期并赋值给mModifiedDate
|
|
|
|
|
|
|
|
mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取父笔记ID并赋值给mParentId
|
|
|
|
|
|
|
|
mParentId = c.getLong(PARENT_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取笔记摘要并赋值给mSnippet
|
|
|
|
|
|
|
|
mSnippet = c.getString(SNIPPET_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取笔记类型并赋值给mType
|
|
|
|
|
|
|
|
mType = c.getInt(TYPE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取小部件ID并赋值给mWidgetId
|
|
|
|
|
|
|
|
mWidgetId = c.getInt(WIDGET_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取小部件类型并赋值给mWidgetType
|
|
|
|
|
|
|
|
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中获取笔记版本号并赋值给mVersion
|
|
|
|
|
|
|
|
mVersion = c.getLong(VERSION_COLUMN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 加载笔记的附加数据内容
|
|
|
|
|
|
|
|
private void loadDataContent() {
|
|
|
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
|
|
|
mDataList.clear(); // 清空现有的数据列表
|
|
|
|
|
|
|
|
try { // 执行查询操作,获取与当前笔记相关的所有附加数据
|
|
|
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
|
|
|
|
|
|
|
|
"(note_id=?)", new String[] {
|
|
|
|
|
|
|
|
String.valueOf(mId)
|
|
|
|
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
if (c != null) { // 如果Cursor不为空,且数据条目不为0
|
|
|
|
|
|
|
|
if (c.getCount() == 0) { // 如果没有数据,记录日志并返回
|
|
|
|
|
|
|
|
Log.w(TAG, "it seems that the note has not data");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
while (c.moveToNext()) { // 遍历Cursor中的所有记录
|
|
|
|
|
|
|
|
SqlData data = new SqlData(mContext, c); // 创建SqlData实例并从Cursor中加载数据
|
|
|
|
|
|
|
|
mDataList.add(data); // 将SqlData实例添加到数据列表中
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // 如果Cursor为空,记录日志
|
|
|
|
|
|
|
|
Log.w(TAG, "loadDataContent: cursor = null");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally { // 关闭Cursor以释放资源
|
|
|
|
|
|
|
|
if (c != null)
|
|
|
|
|
|
|
|
c.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置笔记内容,返回是否设置成功
|
|
|
|
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); // 从JSONObject中获取笔记信息
|
|
|
|
|
|
|
|
// 如果是系统文件夹,则不能设置内容
|
|
|
|
|
|
|
|
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
|
|
|
|
|
|
|
|
Log.w(TAG, "cannot set system folder");
|
|
|
|
|
|
|
|
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
|
|
|
|
|
|
|
|
// for folder we can only update the snnipet and type
|
|
|
|
|
|
|
|
// 对于文件夹,我们只能更新摘要和类型
|
|
|
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
|
|
|
// 如果是新建或者摘要发生变化,则记录差异
|
|
|
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mSnippet = snippet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
|
|
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
// 如果是新建或者类型发生变化,则记录差异
|
|
|
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mType = type;
|
|
|
|
|
|
|
|
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
// 获取笔记的附加数据数组
|
|
|
|
|
|
|
|
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
|
|
|
|
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
|
|
|
|
|
|
|
|
// 如果是新建或者ID发生变化,则记录差异
|
|
|
|
|
|
|
|
if (mIsCreate || mId != id) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ID, id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mId = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
|
|
|
|
|
|
|
|
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
|
|
|
|
|
|
|
// 如果是新建或者提醒日期发生变化,则记录差异
|
|
|
|
|
|
|
|
if (mIsCreate || mAlertDate != alertDate) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mAlertDate = alertDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
|
|
|
|
|
|
|
|
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
|
|
|
|
|
|
|
// 如果是新建或者背景颜色ID发生变化,则记录差异
|
|
|
|
|
|
|
|
if (mIsCreate || mBgColorId != bgColorId) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mBgColorId = bgColorId;// 更新当前便签的背景颜色ID
|
|
|
|
|
|
|
|
// 获取便签的创建日期,如果便签包含创建日期则获取该日期,否则使用当前系统时间
|
|
|
|
|
|
|
|
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;// 更新当前便签的最后修改日期
|
|
|
|
|
|
|
|
// 获取便签的父级ID,如果便签包含该信息则获取,否则默认为无父级
|
|
|
|
|
|
|
|
long parentId = note.has(NoteColumns.PARENT_ID) ? note
|
|
|
|
|
|
|
|
.getLong(NoteColumns.PARENT_ID) : 0;
|
|
|
|
|
|
|
|
// 如果是新建便签或者父级ID有变化,则将变化记录到差异记录中
|
|
|
|
|
|
|
|
if (mIsCreate || mParentId != parentId) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mParentId = parentId;// 更新当前便签的父级ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取便签的摘要信息,如果便签包含该信息则获取,否则默认为空字符串
|
|
|
|
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
|
|
|
|
// 如果是新建便签或者摘要信息有变化,则将变化记录到差异记录中
|
|
|
|
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
|
|
|
|
|
|
|
|
} // 此处代码不完整,下面应该继续记录摘要信息的差异
|
|
|
|
|
|
|
|
mSnippet = snippet;// 更新当前便签的摘要信息
|
|
|
|
|
|
|
|
// 获取便签的类型,如果便签包含类型信息则获取该类型,否则默认为普通便签类型
|
|
|
|
|
|
|
|
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
|
|
|
|
|
|
|
|
: Notes.TYPE_NOTE;
|
|
|
|
|
|
|
|
// 如果是新建便签或者类型有变化,则将变化记录到差异记录中
|
|
|
|
|
|
|
|
if (mIsCreate || mType != type) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.TYPE, type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mType = type;}// 更新当前便签的类型
|
|
|
|
|
|
|
|
// 获取便签的桌面小部件ID,如果便签包含小部件ID则获取该ID,否则默认为无效小部件ID
|
|
|
|
|
|
|
|
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
|
|
|
|
|
|
|
|
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
|
|
|
// 如果是新建便签或者小部件ID有变化,则将变化记录到差异记录中
|
|
|
|
|
|
|
|
if (mIsCreate || mWidgetId != widgetId) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mWidgetId = widgetId;// 更新当前便签的桌面小部件ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取便签的桌面小部件类型,如果便签包含小部件类型信息则获取该类型,否则默认为无效小部件类型
|
|
|
|
|
|
|
|
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;// 更新当前便签的桌面小部件类型
|
|
|
|
|
|
|
|
// 获取便签的原始父级ID,如果便签包含原始父级ID信息则获取该ID,否则默认为0
|
|
|
|
|
|
|
|
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
|
|
|
|
|
|
|
|
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
|
|
|
|
|
|
|
|
// 如果是新建便签或者原始父级ID有变化,则将变化记录到差异记录中
|
|
|
|
|
|
|
|
if (mIsCreate || mOriginParent != originParent) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mOriginParent = originParent;// 更新当前便签的原始父级ID
|
|
|
|
|
|
|
|
// 遍历数据数组,处理每个JSON对象
|
|
|
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
|
|
|
|
SqlData sqlData = null;
|
|
|
|
|
|
|
|
// 如果JSON对象包含ID字段,则尝试从数据列表中找到对应的数据对象
|
|
|
|
|
|
|
|
if (data.has(DataColumns.ID)) {
|
|
|
|
|
|
|
|
long dataId = data.getLong(DataColumns.ID);
|
|
|
|
|
|
|
|
for (SqlData temp : mDataList) {
|
|
|
|
|
|
|
|
if (dataId == temp.getId()) {
|
|
|
|
|
|
|
|
sqlData = temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果没有找到对应的数据对象,则创建一个新的数据对象并添加到数据列表中
|
|
|
|
|
|
|
|
if (sqlData == null) {
|
|
|
|
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlData.setContent(data);// 设置sqlData的内容
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, e.toString());// 打印错误日志
|
|
|
|
|
|
|
|
e.printStackTrace();// 打印异常堆栈信息
|
|
|
|
|
|
|
|
return false;// 返回处理失败
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;// 返回处理成功
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取内容的方法
|
|
|
|
|
|
|
|
public JSONObject getContent() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
JSONObject js = new JSONObject(); // 创建一个新的JSONObject
|
|
|
|
|
|
|
|
// 检查是否已经在数据库中创建
|
|
|
|
|
|
|
|
if (mIsCreate) { // 如果没有创建,打印错误日志并返回null
|
|
|
|
|
|
|
|
Log.e(TAG, "it seems that we haven't created this in database yet");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 创建一个新的JSONObject用于存储笔记信息
|
|
|
|
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
|
|
|
|
// 检查笔记类型
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
// 将笔记信息添加到note对象中
|
|
|
|
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
|
|
|
|
|
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
|
|
|
|
|
|
|
note.put(NoteColumns.CREATED_DATE, mCreatedDate);
|
|
|
|
|
|
|
|
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
|
|
|
|
|
|
|
|
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
|
|
|
|
|
|
|
|
note.put(NoteColumns.PARENT_ID, mParentId);
|
|
|
|
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);
|
|
|
|
|
|
|
|
note.put(NoteColumns.TYPE, mType);
|
|
|
|
|
|
|
|
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
|
|
|
|
|
|
|
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
|
|
|
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
|
|
|
|
// 将note对象添加到js对象中
|
|
|
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
|
|
|
|
// 创建一个新的JSONArray用于存储数据
|
|
|
|
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
|
|
|
|
// 遍历mDataList列表
|
|
|
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
|
|
|
JSONObject data = sqlData.getContent(); // 获取sqlData的内容
|
|
|
|
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
dataArray.put(data); // 如果内容不为空,则添加到dataArray中
|
|
|
|
|
|
|
|
} // 将dataArray添加到js对象中
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
|
|
|
|
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { // 如果类型是文件夹或系统,则只添加ID到note对象中
|
|
|
|
|
|
|
|
note.put(NoteColumns.ID, mId); // 添加ID到note对象
|
|
|
|
|
|
|
|
note.put(NoteColumns.TYPE, mType); // 添加类型到note对象
|
|
|
|
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet); // 添加片段信息到note对象
|
|
|
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note); // 将note对象添加到js对象中
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return js;// 返回构建的JSONObject
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
Log.e(TAG, e.toString()); // 打印错误日志
|
|
|
|
|
|
|
|
e.printStackTrace(); // 打印异常堆栈信息
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;// 如果发生异常,则返回null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置父ID的方法
|
|
|
|
|
|
|
|
public void setParentId(long id) {
|
|
|
|
|
|
|
|
mParentId = id; // 更新父ID
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id); // 在差异值集合中设置父ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置GtaskID的方法
|
|
|
|
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid); // 在差异值集合中设置GtaskID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置同步ID的方法
|
|
|
|
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId); // 在差异值集合中设置同步ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置本地修改状态的方法
|
|
|
|
|
|
|
|
public void resetLocalModified() {
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0); // 在差异值集合中将本地修改状态设置为0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取ID的方法
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
|
|
|
|
return mId; // 返回ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取父ID的方法
|
|
|
|
|
|
|
|
public long getParentId() {
|
|
|
|
|
|
|
|
return mParentId; // 返回父ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取片段信息的方法
|
|
|
|
|
|
|
|
public String getSnippet() {
|
|
|
|
|
|
|
|
return mSnippet; // 返回片段信息
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 检查是否是笔记类型的方法
|
|
|
|
|
|
|
|
public boolean isNoteType() {
|
|
|
|
|
|
|
|
return mType == Notes.TYPE_NOTE; // 如果类型是笔记,则返回true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 提交更改到数据库的方法
|
|
|
|
|
|
|
|
public void commit(boolean validateVersion) {
|
|
|
|
|
|
|
|
// 如果是创建操作
|
|
|
|
|
|
|
|
if (mIsCreate) {
|
|
|
|
|
|
|
|
// 如果ID无效且差异值集合中包含ID,则移除ID
|
|
|
|
|
|
|
|
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
|
|
|
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 向数据库插入新的笔记记录,并获取返回的URI
|
|
|
|
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
|
|
|
|
try { // 从URI中解析出笔记的ID
|
|
|
|
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
|
|
|
|
} catch (NumberFormatException e) {、
|
|
|
|
|
|
|
|
// 如果解析ID失败,记录错误日志并抛出异常
|
|
|
|
|
|
|
|
Log.e(TAG, "Get note id error :" + e.toString());
|
|
|
|
|
|
|
|
throw new ActionFailureException("create note failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果ID为0,则抛出异常
|
|
|
|
|
|
|
|
if (mId == 0) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("Create thread id failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果类型是笔记,则提交所有关联的SqlData
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
|
|
|
sqlData.commit(mId, false, -1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // 如果不是创建操作,检查ID是否有效
|
|
|
|
|
|
|
|
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
|
|
|
Log.e(TAG, "No such note");
|
|
|
|
|
|
|
|
throw new IllegalStateException("Try to update note with invalid id");
|
|
|
|
|
|
|
|
} // 如果差异值集合中有更改,则更新版本号并执行更新操作
|
|
|
|
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
|
|
|
|
mVersion ++;
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
// 如果不需要验证版本,则直接更新
|
|
|
|
|
|
|
|
if (!validateVersion) {
|
|
|
|
|
|
|
|
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
|
|
|
|
|
|
|
+ NoteColumns.ID + "=?)", new String[] {
|
|
|
|
|
|
|
|
String.valueOf(mId)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else { // 如果需要验证版本,则添加版本号的条件
|
|
|
|
|
|
|
|
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
|
|
|
|
|
|
|
|
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
|
|
|
|
|
|
|
|
new String[] {
|
|
|
|
|
|
|
|
String.valueOf(mId), String.valueOf(mVersion)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == 0) {// 如果更新结果为0,表示没有更新任何记录,可能是用户在同步时更新了笔记
|
|
|
|
|
|
|
|
Log.w(TAG, "there is no update. maybe user updates note when syncing");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果类型是笔记,则提交所有关联的SqlData
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
|
|
|
|
sqlData.commit(mId, validateVersion, mVersion); // 对每个SqlData执行提交操作,传入笔记ID、是否验证版本和当前版本号
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// refresh local info
|
|
|
|
|
|
|
|
loadFromCursor(mId);// 刷新本地信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果类型是笔记,则加载数据内容
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
|
|
|
loadDataContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDiffNoteValues.clear();// 清空差异值集合
|
|
|
|
|
|
|
|
mIsCreate = false;// 标记为非创建状态
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|