|
|
@ -14,35 +14,67 @@
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 该包包含与 Google Tasks 相关的 SQL 笔记数据处理类。
|
|
|
|
|
|
|
|
*/
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入 Android 桌面小部件管理类
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
import android.appwidget.AppWidgetManager;
|
|
|
|
|
|
|
|
// 导入 Android 内容解析器类,用于与内容提供者交互
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
|
|
|
// 导入 Android 内容值类,用于存储键值对数据
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
|
|
|
// 导入 Android 上下文类,提供应用环境信息
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
// 导入 Android 数据库游标类,用于处理查询结果
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
// 导入 Android URI 类,用于标识内容提供者中的数据
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
// 导入 Android 日志工具类,用于记录日志信息
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入应用笔记数据相关类
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
|
|
|
// 导入应用笔记数据列相关类
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
import net.micode.notes.data.Notes.DataColumns;
|
|
|
|
|
|
|
|
// 导入应用笔记列相关类
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
// 导入应用 Google Tasks 操作失败异常类
|
|
|
|
import net.micode.notes.gtask.exception.ActionFailureException;
|
|
|
|
import net.micode.notes.gtask.exception.ActionFailureException;
|
|
|
|
|
|
|
|
// 导入应用 Google Tasks 字符串工具类
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
|
|
|
|
// 导入应用资源解析工具类
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
import net.micode.notes.tool.ResourceParser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入 JSON 数组类,用于处理 JSON 数组数据
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
// 导入 JSON 异常处理类,用于处理 JSON 操作异常
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
// 导入 JSON 对象类,用于处理 JSON 对象数据
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导入 Java 集合框架中的 ArrayList 类
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* SqlNote 类用于处理与 SQL 数据库中笔记数据的交互,包括笔记的创建、加载、更新和提交等操作。
|
|
|
|
|
|
|
|
* 支持从 JSON 对象设置笔记内容,以及将笔记内容转换为 JSON 对象。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class SqlNote {
|
|
|
|
public class SqlNote {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 日志标签,用于在日志记录中标识该类的日志信息。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 无效 ID 的常量值,用于表示未初始化或无效的笔记 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
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, 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,
|
|
|
@ -52,82 +84,193 @@ public class SqlNote {
|
|
|
|
NoteColumns.VERSION
|
|
|
|
NoteColumns.VERSION
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记提醒日期列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记背景颜色 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int BG_COLOR_ID_COLUMN = 2;
|
|
|
|
public static final int BG_COLOR_ID_COLUMN = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记创建日期列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int CREATED_DATE_COLUMN = 3;
|
|
|
|
public static final int CREATED_DATE_COLUMN = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记是否有附件列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
|
|
|
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记修改日期列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int MODIFIED_DATE_COLUMN = 5;
|
|
|
|
public static final int MODIFIED_DATE_COLUMN = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记数量列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int NOTES_COUNT_COLUMN = 6;
|
|
|
|
public static final int NOTES_COUNT_COLUMN = 6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记父 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int PARENT_ID_COLUMN = 7;
|
|
|
|
public static final int PARENT_ID_COLUMN = 7;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记摘要列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int SNIPPET_COLUMN = 8;
|
|
|
|
public static final int SNIPPET_COLUMN = 8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记类型列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int TYPE_COLUMN = 9;
|
|
|
|
public static final int TYPE_COLUMN = 9;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记小部件 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
public static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记小部件类型列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
public static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记同步 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int SYNC_ID_COLUMN = 12;
|
|
|
|
public static final int SYNC_ID_COLUMN = 12;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记本地修改标志列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
|
|
|
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记原始父 ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
|
|
|
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记 Google Tasks ID 列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* PROJECTION_NOTE 数组中笔记版本号列的索引。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 应用上下文对象,提供对应用资源和系统服务的访问。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private Context mContext;
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 内容解析器,用于与内容提供者进行交互,执行数据库操作。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 标识笔记是否为新创建的标志。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private boolean mIsCreate;
|
|
|
|
private boolean mIsCreate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mId;
|
|
|
|
private long mId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的提醒日期。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mAlertDate;
|
|
|
|
private long mAlertDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的背景颜色 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private int mBgColorId;
|
|
|
|
private int mBgColorId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的创建日期。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mCreatedDate;
|
|
|
|
private long mCreatedDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记是否有附件的标志。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private int mHasAttachment;
|
|
|
|
private int mHasAttachment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的修改日期。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mModifiedDate;
|
|
|
|
private long mModifiedDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的父 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mParentId;
|
|
|
|
private long mParentId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的摘要信息。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String mSnippet;
|
|
|
|
private String mSnippet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的类型。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private int mType;
|
|
|
|
private int mType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记关联的小部件 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private int mWidgetId;
|
|
|
|
private int mWidgetId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记关联的小部件类型。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private int mWidgetType;
|
|
|
|
private int mWidgetType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的原始父 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mOriginParent;
|
|
|
|
private long mOriginParent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 笔记的版本号。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private long mVersion;
|
|
|
|
private long mVersion;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 存储笔记差异的内容值对象,用于记录需要更新或插入到数据库的笔记数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 存储笔记关联数据的列表。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 构造函数,用于创建一个新的笔记对象。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param context 应用程序上下文,用于获取内容解析器和资源。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mIsCreate = true;
|
|
|
|
mIsCreate = true;
|
|
|
|
mId = INVALID_ID;
|
|
|
|
mId = INVALID_ID;
|
|
|
|
mAlertDate = 0;
|
|
|
|
mAlertDate = 0;
|
|
|
|
|
|
|
|
// 获取默认的背景颜色 ID
|
|
|
|
mBgColorId = ResourceParser.getDefaultBgId(context);
|
|
|
|
mBgColorId = ResourceParser.getDefaultBgId(context);
|
|
|
|
mCreatedDate = System.currentTimeMillis();
|
|
|
|
mCreatedDate = System.currentTimeMillis();
|
|
|
|
mHasAttachment = 0;
|
|
|
|
mHasAttachment = 0;
|
|
|
@ -143,48 +286,78 @@ public class SqlNote {
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 构造函数,用于从数据库游标中加载笔记数据创建笔记对象。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param context 应用程序上下文,用于获取内容解析器和资源。
|
|
|
|
|
|
|
|
* @param c 数据库游标,包含需要加载的笔记数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mIsCreate = false;
|
|
|
|
mIsCreate = false;
|
|
|
|
|
|
|
|
// 从游标中加载笔记数据
|
|
|
|
loadFromCursor(c);
|
|
|
|
loadFromCursor(c);
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
|
|
|
// 如果是笔记类型,则加载关联的数据内容
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
loadDataContent();
|
|
|
|
loadDataContent();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 构造函数,用于根据笔记 ID 从数据库中加载笔记数据创建笔记对象。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param context 应用程序上下文,用于获取内容解析器和资源。
|
|
|
|
|
|
|
|
* @param id 笔记的 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mIsCreate = false;
|
|
|
|
mIsCreate = false;
|
|
|
|
|
|
|
|
// 根据 ID 从数据库中加载笔记数据
|
|
|
|
loadFromCursor(id);
|
|
|
|
loadFromCursor(id);
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
|
|
|
|
// 如果是笔记类型,则加载关联的数据内容
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
loadDataContent();
|
|
|
|
loadDataContent();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据笔记 ID 从数据库中查询并加载笔记数据。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id 笔记的 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从数据库游标中加载笔记数据到当前对象。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param c 数据库游标,包含需要加载的笔记数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void loadFromCursor(Cursor c) {
|
|
|
|
private void loadFromCursor(Cursor c) {
|
|
|
|
mId = c.getLong(ID_COLUMN);
|
|
|
|
mId = c.getLong(ID_COLUMN);
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
|
|
|
@ -200,39 +373,56 @@ public class SqlNote {
|
|
|
|
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 {
|
|
|
|
|
|
|
|
// 查询与当前笔记关联的数据
|
|
|
|
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 对象并添加到数据列表中
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据 JSON 对象设置笔记内容,并记录数据差异。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param js 包含笔记信息的 JSON 对象。
|
|
|
|
|
|
|
|
* @return 如果设置成功返回 true,否则返回 false。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 获取笔记信息的 JSON 对象
|
|
|
|
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");
|
|
|
|
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_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
|
|
|
|
String snippet = note.has(NoteColumns.SNIPPET) ? note
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
.getString(NoteColumns.SNIPPET) : "";
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
|
if (mIsCreate || !mSnippet.equals(snippet)) {
|
|
|
@ -247,6 +437,7 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mType = type;
|
|
|
|
mType = type;
|
|
|
|
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
|
|
|
|
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
// 获取笔记关联数据的 JSON 数组
|
|
|
|
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;
|
|
|
|
if (mIsCreate || mId != id) {
|
|
|
|
if (mIsCreate || mId != id) {
|
|
|
@ -332,6 +523,7 @@ public class SqlNote {
|
|
|
|
mOriginParent = originParent;
|
|
|
|
mOriginParent = originParent;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
|
|
|
// 获取每个关联数据的 JSON 对象
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
SqlData sqlData = null;
|
|
|
|
SqlData sqlData = null;
|
|
|
|
if (data.has(DataColumns.ID)) {
|
|
|
|
if (data.has(DataColumns.ID)) {
|
|
|
@ -344,14 +536,17 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sqlData == null) {
|
|
|
|
if (sqlData == null) {
|
|
|
|
|
|
|
|
// 如果未找到对应的 SqlData 对象,则创建新的对象并添加到列表中
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置关联数据的内容
|
|
|
|
sqlData.setContent(data);
|
|
|
|
sqlData.setContent(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
// 记录 JSON 异常日志并打印堆栈信息
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -359,17 +554,24 @@ public class SqlNote {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 将当前笔记对象的内容转换为 JSON 对象。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 包含当前笔记信息的 JSON 对象,如果笔记未创建则返回 null。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public JSONObject getContent() {
|
|
|
|
public JSONObject getContent() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsCreate) {
|
|
|
|
if (mIsCreate) {
|
|
|
|
|
|
|
|
// 记录笔记未创建的日志
|
|
|
|
Log.e(TAG, "it seems that we haven't created this in database yet");
|
|
|
|
Log.e(TAG, "it seems that we haven't created this in database yet");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
|
|
|
|
// 将笔记信息放入 JSON 对象
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
|
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
|
|
|
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
|
|
|
@ -384,15 +586,18 @@ public class SqlNote {
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建关联数据的 JSON 数组
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
JSONObject data = sqlData.getContent();
|
|
|
|
JSONObject data = sqlData.getContent();
|
|
|
|
if (data != null) {
|
|
|
|
if (data != null) {
|
|
|
|
|
|
|
|
// 将关联数据的 JSON 对象添加到数组中
|
|
|
|
dataArray.put(data);
|
|
|
|
dataArray.put(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
|
|
|
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
|
|
|
|
|
|
|
// 将文件夹或系统文件夹信息放入 JSON 对象
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.TYPE, mType);
|
|
|
|
note.put(NoteColumns.TYPE, mType);
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);
|
|
|
|
note.put(NoteColumns.SNIPPET, mSnippet);
|
|
|
@ -401,105 +606,164 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
|
|
return js;
|
|
|
|
return js;
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
|
|
|
// 记录 JSON 异常日志并打印堆栈信息
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置笔记的父 ID,并记录数据差异。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param id 笔记的父 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置笔记的 Google Tasks ID,并记录数据差异。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param gid 笔记的 Google Tasks ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置笔记的同步 ID,并记录数据差异。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param syncId 笔记的同步 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 重置笔记的本地修改标志,并记录数据差异。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void resetLocalModified() {
|
|
|
|
public void resetLocalModified() {
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取笔记的 ID。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 笔记的 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public long getId() {
|
|
|
|
public long getId() {
|
|
|
|
return mId;
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取笔记的父 ID。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 笔记的父 ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public long getParentId() {
|
|
|
|
public long getParentId() {
|
|
|
|
return mParentId;
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取笔记的摘要信息。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 笔记的摘要信息。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public String getSnippet() {
|
|
|
|
public String getSnippet() {
|
|
|
|
return mSnippet;
|
|
|
|
return mSnippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断笔记是否为笔记类型。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 如果是笔记类型返回 true,否则返回 false。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public boolean isNoteType() {
|
|
|
|
public boolean isNoteType() {
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 将笔记数据差异提交到数据库,根据笔记是否为新创建执行插入或更新操作。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param validateVersion 是否验证版本号。
|
|
|
|
|
|
|
|
*/
|
|
|
|
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)) {
|
|
|
|
|
|
|
|
// 如果笔记 ID 无效且差异中包含 ID,则移除该差异
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 插入笔记数据到数据库,获取插入后的 URI
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 从 URI 中解析出笔记 ID
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
|
|
|
// 记录获取笔记 ID 错误的日志,并抛出操作失败异常
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mId == 0) {
|
|
|
|
if (mId == 0) {
|
|
|
|
|
|
|
|
// 抛出创建笔记 ID 失败的异常
|
|
|
|
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) {
|
|
|
|
|
|
|
|
// 记录笔记 ID 无效的日志,并抛出异常
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
|
|
|
|
// 版本号加 1
|
|
|
|
mVersion ++;
|
|
|
|
mVersion ++;
|
|
|
|
int result = 0;
|
|
|
|
int result = 0;
|
|
|
|
if (!validateVersion) {
|
|
|
|
if (!validateVersion) {
|
|
|
|
|
|
|
|
// 不验证版本号,执行更新操作
|
|
|
|
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 {
|
|
|
|
|
|
|
|
// 验证版本号,执行更新操作
|
|
|
|
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[] {
|
|
|
|
String.valueOf(mId), String.valueOf(mVersion)
|
|
|
|
String.valueOf(mId), String.valueOf(mVersion)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == 0) {
|
|
|
|
if (result == 0) {
|
|
|
|
|
|
|
|
// 记录可能用户在同步时更新笔记的日志
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// refresh local info
|
|
|
|
// 刷新本地笔记信息
|
|
|
|
loadFromCursor(mId);
|
|
|
|
loadFromCursor(mId);
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
|
|
|
|
// 加载关联的数据内容
|
|
|
|
loadDataContent();
|
|
|
|
loadDataContent();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 清空数据差异
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
|
|
|
|
// 标记为非新创建的笔记
|
|
|
|
mIsCreate = false;
|
|
|
|
mIsCreate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|