|
|
|
@ -38,37 +38,11 @@ import org.json.JSONObject;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import android.widget.RemoteViews;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
|
|
import androidx.appcompat.widget.AppCompatDrawableManager;
|
|
|
|
|
|
|
|
import androidx.cursoradapter.widget.SimpleCursorAdapter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SqlNote类用于处理与笔记数据的SQL相关操作,包括从数据库加载、保存、更新笔记信息等
|
|
|
|
|
|
|
|
public class SqlNote {
|
|
|
|
public class SqlNote {
|
|
|
|
// 日志标签,用于标识该类相关的日志信息
|
|
|
|
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
// 无效的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,
|
|
|
|
@ -78,79 +52,76 @@ public class SqlNote {
|
|
|
|
NoteColumns.VERSION
|
|
|
|
NoteColumns.VERSION
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 投影列中ID列的索引
|
|
|
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
// 投影列中提醒日期列的索引
|
|
|
|
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
public static final int ALERTED_DATE_COLUMN = 1;
|
|
|
|
// 投影列中背景颜色ID列的索引
|
|
|
|
|
|
|
|
public static final int BG_COLOR_ID_COLUMN = 2;
|
|
|
|
public static final int BG_COLOR_ID_COLUMN = 2;
|
|
|
|
// 投影列中创建日期列的索引
|
|
|
|
|
|
|
|
public static final int CREATED_DATE_COLUMN = 3;
|
|
|
|
public static final int CREATED_DATE_COLUMN = 3;
|
|
|
|
// 投影列中是否有附件列的索引
|
|
|
|
|
|
|
|
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
|
|
|
public static final int HAS_ATTACHMENT_COLUMN = 4;
|
|
|
|
// 投影列中修改日期列的索引
|
|
|
|
|
|
|
|
public static final int MODIFIED_DATE_COLUMN = 5;
|
|
|
|
public static final int MODIFIED_DATE_COLUMN = 5;
|
|
|
|
// 投影列中文件夹内笔记数量列的索引
|
|
|
|
|
|
|
|
public static final int NOTES_COUNT_COLUMN = 6;
|
|
|
|
public static final int NOTES_COUNT_COLUMN = 6;
|
|
|
|
// 投影列中父级ID列的索引
|
|
|
|
|
|
|
|
public static final int PARENT_ID_COLUMN = 7;
|
|
|
|
public static final int PARENT_ID_COLUMN = 7;
|
|
|
|
// 投影列中文本内容或文件夹名称列的索引
|
|
|
|
|
|
|
|
public static final int SNIPPET_COLUMN = 8;
|
|
|
|
public static final int SNIPPET_COLUMN = 8;
|
|
|
|
// 投影列中类型列的索引
|
|
|
|
|
|
|
|
public static final int TYPE_COLUMN = 9;
|
|
|
|
public static final int TYPE_COLUMN = 9;
|
|
|
|
// 投影列中小部件ID列的索引
|
|
|
|
|
|
|
|
public static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
public static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
// 投影列中小部件类型列的索引
|
|
|
|
|
|
|
|
public static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
public static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
// 投影列中同步ID列的索引
|
|
|
|
|
|
|
|
public static final int SYNC_ID_COLUMN = 12;
|
|
|
|
public static final int SYNC_ID_COLUMN = 12;
|
|
|
|
// 投影列中本地修改标志列的索引
|
|
|
|
|
|
|
|
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
|
|
|
public static final int LOCAL_MODIFIED_COLUMN = 13;
|
|
|
|
// 投影列中原始父级ID列的索引
|
|
|
|
|
|
|
|
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
|
|
|
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
|
|
|
|
// 投影列中gtask ID列的索引
|
|
|
|
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
public static final int GTASK_ID_COLUMN = 15;
|
|
|
|
// 投影列中版本号列的索引
|
|
|
|
|
|
|
|
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;
|
|
|
|
// 用于存储笔记数据差异的ContentValues,用于更新操作
|
|
|
|
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
// 存储与该笔记相关的SqlData对象列表
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
|
|
// 构造函数,用于创建一个新的SqlNote对象,通常用于新笔记的创建
|
|
|
|
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
@ -172,7 +143,6 @@ public class SqlNote {
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 构造函数,通过Cursor对象初始化SqlNote对象,通常用于从数据库加载现有笔记
|
|
|
|
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
public SqlNote(Context context, Cursor c) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
@ -184,7 +154,6 @@ public class SqlNote {
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 构造函数,通过笔记ID从数据库加载笔记并初始化SqlNote对象
|
|
|
|
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
@ -194,31 +163,28 @@ public class SqlNote {
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
loadDataContent();
|
|
|
|
loadDataContent();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据给定的ID从数据库加载笔记数据
|
|
|
|
|
|
|
|
private void loadFromCursor(long id) {
|
|
|
|
private void loadFromCursor(long id) {
|
|
|
|
Cursor c = null;
|
|
|
|
Cursor c = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 使用内容解析器查询笔记数据
|
|
|
|
|
|
|
|
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();
|
|
|
|
// 从Cursor中加载数据
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从Cursor中加载笔记数据到当前对象的属性中
|
|
|
|
|
|
|
|
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);
|
|
|
|
@ -234,23 +200,20 @@ 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -258,113 +221,112 @@ public class SqlNote {
|
|
|
|
Log.w(TAG, "loadDataContent: cursor = null");
|
|
|
|
Log.w(TAG, "loadDataContent: cursor = null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (c!= null)
|
|
|
|
if (c != null)
|
|
|
|
c.close();
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 根据JSONObject设置笔记的内容
|
|
|
|
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
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)) {
|
|
|
|
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;
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.ID, id);
|
|
|
|
mDiffNoteValues.put(NoteColumns.ID, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mId = id;
|
|
|
|
mId = id;
|
|
|
|
|
|
|
|
|
|
|
|
long alertDate = note.has(NoteColumns.ALERTED_DATE)? note
|
|
|
|
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
|
|
|
|
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
|
|
|
.getLong(NoteColumns.ALERTED_DATE) : 0;
|
|
|
|
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
|
|
|
|
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
|
|
|
|
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
|
|
|
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
|
|
|
|
if (mIsCreate || mBgColorId!= bgColorId) {
|
|
|
|
if (mIsCreate || mBgColorId != bgColorId) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
|
|
|
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mBgColorId = bgColorId;
|
|
|
|
mBgColorId = bgColorId;
|
|
|
|
|
|
|
|
|
|
|
|
long createDate = note.has(NoteColumns.CREATED_DATE)? note
|
|
|
|
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
|
|
|
|
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
|
|
|
|
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
|
|
|
|
if (mIsCreate || mCreatedDate!= createDate) {
|
|
|
|
if (mIsCreate || mCreatedDate != createDate) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
|
|
|
|
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCreatedDate = createDate;
|
|
|
|
mCreatedDate = createDate;
|
|
|
|
|
|
|
|
|
|
|
|
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT)? note
|
|
|
|
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
|
|
|
|
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
|
|
|
|
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
|
|
|
|
if (mIsCreate || mHasAttachment!= hasAttachment) {
|
|
|
|
if (mIsCreate || mHasAttachment != hasAttachment) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
|
|
|
|
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mHasAttachment = hasAttachment;
|
|
|
|
mHasAttachment = hasAttachment;
|
|
|
|
|
|
|
|
|
|
|
|
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE)? note
|
|
|
|
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
|
|
|
|
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
|
|
|
|
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
|
|
|
|
if (mIsCreate || mModifiedDate!= modifiedDate) {
|
|
|
|
if (mIsCreate || mModifiedDate != modifiedDate) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
|
|
|
|
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mModifiedDate = modifiedDate;
|
|
|
|
mModifiedDate = modifiedDate;
|
|
|
|
|
|
|
|
|
|
|
|
long parentId = note.has(NoteColumns.PARENT_ID)? note
|
|
|
|
long parentId = note.has(NoteColumns.PARENT_ID) ? note
|
|
|
|
.getLong(NoteColumns.PARENT_ID) : 0;
|
|
|
|
.getLong(NoteColumns.PARENT_ID) : 0;
|
|
|
|
if (mIsCreate || mParentId!= parentId) {
|
|
|
|
if (mIsCreate || mParentId != parentId) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mParentId = parentId;
|
|
|
|
mParentId = parentId;
|
|
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
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;
|
|
|
|
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)
|
|
|
|
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
|
|
|
|
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
: AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
if (mIsCreate || mWidgetId!= widgetId) {
|
|
|
|
if (mIsCreate || mWidgetId != widgetId) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWidgetId = widgetId;
|
|
|
|
mWidgetId = widgetId;
|
|
|
|
|
|
|
|
|
|
|
|
int widgetType = note.has(NoteColumns.WIDGET_TYPE)? note
|
|
|
|
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
|
|
|
|
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
|
|
|
|
if (mIsCreate || mWidgetType!= widgetType) {
|
|
|
|
if (mIsCreate || mWidgetType != widgetType) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
|
|
|
|
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mWidgetType = widgetType;
|
|
|
|
mWidgetType = widgetType;
|
|
|
|
|
|
|
|
|
|
|
|
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID)? note
|
|
|
|
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
|
|
|
|
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
|
|
|
|
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
|
|
|
|
if (mIsCreate || mOriginParent!= originParent) {
|
|
|
|
if (mIsCreate || mOriginParent != originParent) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
|
|
|
|
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mOriginParent = originParent;
|
|
|
|
mOriginParent = originParent;
|
|
|
|
@ -397,25 +359,17 @@ public class SqlNote {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取内容的方法,返回一个表示当前对象内容的JSONObject
|
|
|
|
|
|
|
|
public JSONObject getContent() {
|
|
|
|
public JSONObject getContent() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 创建一个空的JSONObject
|
|
|
|
|
|
|
|
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");
|
|
|
|
// 返回null
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个表示笔记的JSONObject
|
|
|
|
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
// 如果类型是笔记类型
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
// 将笔记的各个属性添加到note JSONObject中
|
|
|
|
|
|
|
|
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);
|
|
|
|
@ -428,179 +382,124 @@ public class SqlNote {
|
|
|
|
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
|
|
|
note.put(NoteColumns.WIDGET_ID, mWidgetId);
|
|
|
|
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
|
|
|
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
|
|
|
|
// 将表示笔记的note JSONObject添加到主JSONObject中,使用GTaskStringUtils.META_HEAD_NOTE作为键
|
|
|
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个JSONArray用于存储数据
|
|
|
|
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
// 遍历数据列表
|
|
|
|
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
for (SqlData sqlData : mDataList) {
|
|
|
|
// 获取每个数据项的内容JSONObject
|
|
|
|
|
|
|
|
JSONObject data = sqlData.getContent();
|
|
|
|
JSONObject data = sqlData.getContent();
|
|
|
|
// 如果数据项的内容JSONObject不为空
|
|
|
|
if (data != null) {
|
|
|
|
if (data!= null) {
|
|
|
|
|
|
|
|
// 将其添加到JSONArray中
|
|
|
|
|
|
|
|
dataArray.put(data);
|
|
|
|
dataArray.put(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 将存储数据的JSONArray添加到主JSONObject中,使用GTaskStringUtils.META_HEAD_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) {
|
|
|
|
// 将文件夹或系统类型的相关属性添加到note JSONObject中
|
|
|
|
|
|
|
|
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);
|
|
|
|
// 将表示文件夹或系统类型的note JSONObject添加到主JSONObject中,使用GTaskStringUtils.META_HEAD_NOTE作为键
|
|
|
|
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 返回构建好的主JSONObject
|
|
|
|
|
|
|
|
return js;
|
|
|
|
return js;
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
// 记录异常日志
|
|
|
|
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
// 打印异常堆栈信息
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果发生异常,返回null
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置父ID的方法
|
|
|
|
|
|
|
|
public void setParentId(long id) {
|
|
|
|
public void setParentId(long id) {
|
|
|
|
// 设置对象的父ID
|
|
|
|
|
|
|
|
mParentId = id;
|
|
|
|
mParentId = id;
|
|
|
|
// 将父ID的变化记录到mDiffNoteValues中,用于后续的更新操作
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
|
|
|
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置GTask ID的方法
|
|
|
|
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
// 将GTask ID的变化记录到mDiffNoteValues中,用于后续的更新操作
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置同步ID的方法
|
|
|
|
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
public void setSyncId(long syncId) {
|
|
|
|
// 将同步ID的变化记录到mDiffNoteValues中,用于后续的更新操作
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 重置本地修改标志的方法
|
|
|
|
|
|
|
|
public void resetLocalModified() {
|
|
|
|
public void resetLocalModified() {
|
|
|
|
// 将本地修改标志设为0,并记录到mDiffNoteValues中,用于后续的更新操作
|
|
|
|
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
|
|
|
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取ID的方法
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
public long getId() {
|
|
|
|
// 返回对象的ID
|
|
|
|
|
|
|
|
return mId;
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取父ID的方法
|
|
|
|
|
|
|
|
public long getParentId() {
|
|
|
|
public long getParentId() {
|
|
|
|
// 返回对象的父ID
|
|
|
|
|
|
|
|
return mParentId;
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取片段内容的方法
|
|
|
|
|
|
|
|
public String getSnippet() {
|
|
|
|
public String getSnippet() {
|
|
|
|
// 返回对象的片段内容
|
|
|
|
|
|
|
|
return mSnippet;
|
|
|
|
return mSnippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为笔记类型的方法
|
|
|
|
|
|
|
|
public boolean isNoteType() {
|
|
|
|
public boolean isNoteType() {
|
|
|
|
// 如果类型是笔记类型,返回true,否则返回false
|
|
|
|
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
return mType == Notes.TYPE_NOTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提交更改的方法,validateVersion用于指定是否验证版本
|
|
|
|
|
|
|
|
public void commit(boolean validateVersion) {
|
|
|
|
public void commit(boolean validateVersion) {
|
|
|
|
// 如果对象是新创建的
|
|
|
|
|
|
|
|
if (mIsCreate) {
|
|
|
|
if (mIsCreate) {
|
|
|
|
// 如果ID无效且mDiffNoteValues中包含ID,移除ID
|
|
|
|
|
|
|
|
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
|
|
|
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
mDiffNoteValues.remove(NoteColumns.ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 向笔记内容Uri插入数据,返回插入后的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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果获取的ID为0,抛出异常
|
|
|
|
|
|
|
|
if (mId == 0) {
|
|
|
|
if (mId == 0) {
|
|
|
|
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 {
|
|
|
|
// 如果ID无效且不是根文件夹或通话记录文件夹的ID
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果有需要更新的变化
|
|
|
|
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
// 版本号加1
|
|
|
|
mVersion ++;
|
|
|
|
mVersion++;
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
int result = 0;
|
|
|
|
// 如果不需要验证版本
|
|
|
|
|
|
|
|
if (!validateVersion) {
|
|
|
|
if (!validateVersion) {
|
|
|
|
// 根据ID更新笔记数据
|
|
|
|
|
|
|
|
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 {
|
|
|
|
// 根据ID和版本号更新笔记数据
|
|
|
|
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 如果更新结果为0,记录警告日志
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
mDiffNoteValues.clear();
|
|
|
|
// 设置对象不再是新创建的状态
|
|
|
|
|
|
|
|
mIsCreate = false;
|
|
|
|
mIsCreate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|