|
|
@ -37,12 +37,13 @@ import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于将得到的类的简写名称存入字符串TAG中
|
|
|
|
public class SqlNote {
|
|
|
|
public class SqlNote {
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
private static final int INVALID_ID = -99999;
|
|
|
|
private static final int INVALID_ID = -99999;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//集合了interface NoteColumns中的17个SF常量
|
|
|
|
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,
|
|
|
@ -86,6 +87,7 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
public static final int VERSION_COLUMN = 16;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下面定义了17个内部变量,其中12个可以在content中获得,5个需要初始化为0或new
|
|
|
|
private Context mContext;
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
@ -122,6 +124,7 @@ public class SqlNote {
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//构造函数,用于对所有的变量进行初始化
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
@ -142,11 +145,14 @@ public class SqlNote {
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//构造函数
|
|
|
|
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;
|
|
|
|
|
|
|
|
//从传入的Cursor对象中加载便签数据
|
|
|
|
loadFromCursor(c);
|
|
|
|
loadFromCursor(c);
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
|
if (mType == Notes.TYPE_NOTE)
|
|
|
@ -154,6 +160,7 @@ public class SqlNote {
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//构造函数,用于标示构造方式
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
public SqlNote(Context context, long id) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
@ -163,16 +170,18 @@ 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;
|
|
|
|
|
|
|
|
//通过ID获得对应的ContentResolver中的cursor
|
|
|
|
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();
|
|
|
|
loadFromCursor(c);
|
|
|
|
loadFromCursor(c);
|
|
|
@ -185,6 +194,7 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于从传入的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);
|
|
|
@ -200,9 +210,12 @@ 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中的数据,以便重新加载新的数据
|
|
|
|
mDataList.clear();
|
|
|
|
mDataList.clear();
|
|
|
|
|
|
|
|
//使用内容解析器对象mContentResolver调用query()方法查询数据库,查询结果将赋值给Cursor对象c,再通过检查c是否为空来判断查询是否成功。如果不为空,表示查询到了结果。然后通过循环遍历c的每一行数据,创建SqlData对象并将其加入mDataList中。
|
|
|
|
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[] {
|
|
|
@ -226,13 +239,16 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于设置便签的内容,接收一个JSONObject对象作为参数,并根据该对象中的数据更新便签的属性。
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
public boolean setContent(JSONObject js) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
//从JSONObject对象中获取名为note的子对象,该子对象包含了便签的各个属性。接着根据便签的类型(系统、文件夹、笔记)进行不同的处理逻辑。
|
|
|
|
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
|
|
|
|
// 如果类型是文件夹,则更新摘要和类型属性。如果是新建笔记或者摘要有变化,则将新的摘要值存入mDiffNoteValues集合,并更新mSnippet的值。同样的,如果是新建便签或者类型有变化,则将新的类型值存入mDiffNoteValues集合,并更新mType的值。
|
|
|
|
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)) {
|
|
|
@ -246,7 +262,8 @@ public class SqlNote {
|
|
|
|
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) {
|
|
|
@ -331,6 +348,7 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mOriginParent = originParent;
|
|
|
|
mOriginParent = originParent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//最后,遍历dataArray数组,该数组包含了便签的内容数据。对于每个数据对象,如果存在ID属性,就在mDataList列表中查找对应的SqlData对象,如果找到则使用该对象,否则创建一个新的SqlData对象并添加到mDataList列表中。然后调用sqlData.setContent(data),将数据对象传递给SqlData对象进行处理。
|
|
|
|
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;
|
|
|
@ -343,7 +361,7 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sqlData == null) {
|
|
|
|
if (sqlData == null) {‘’
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
sqlData = new SqlData(mContext);
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
mDataList.add(sqlData);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -359,16 +377,19 @@ public class SqlNote {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于获取便签的内容
|
|
|
|
public JSONObject getContent() {
|
|
|
|
public JSONObject getContent() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果mIsCreate属性为true,表示该便签还未在数据库中创建,此时打印警告信息并返回null
|
|
|
|
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();
|
|
|
|
|
|
|
|
//如果便签类型是笔记,将便签的各个属性添加到note对象中,然后将note对象添加到js对象中。同时创建一个名为dataArray的JSONArray数组,并遍历mDataList列表中的每个SqlData对象。对于每个SqlData对象,调用getContent获取其内容数据,并将数据对象添加到dataArray数组中。
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
if (mType == Notes.TYPE_NOTE) {
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.ID, mId);
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
|
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
|
|
|
@ -392,7 +413,7 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
|
|
|
|
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
|
|
|
} //如果类型是文件夹和系统,将ID、类型和摘要属性添加到note对象中,然后将note对象添加到js对象中。 else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
|
|
|
|
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);
|
|
|
@ -407,45 +428,56 @@ public class SqlNote {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于给当前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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于给当前ID设置GTASK_ID,
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
public void setGtaskId(String gid) {
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于给当前ID设置同步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
|
|
|
|
public long getId() {
|
|
|
|
public long getId() {
|
|
|
|
return mId;
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于获得当前ID的父ID
|
|
|
|
public long getParentId() {
|
|
|
|
public long getParentId() {
|
|
|
|
return mParentId;
|
|
|
|
return mParentId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数用于显示当前便签的摘要
|
|
|
|
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) {
|
|
|
|
|
|
|
|
//如果便签的ID为无效值(INVALID_ID)且mDiffNoteValues集合中包含键为NoteColumns.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调用ContentResolver的insert将便签的内容插入到数据库中
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
|
mId = Long.valueOf(uri.getPathSegments().get(1));
|
|
|
@ -457,12 +489,14 @@ public class SqlNote {
|
|
|
|
throw new IllegalStateException("Create thread id failed");
|
|
|
|
throw new IllegalStateException("Create thread id failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果便签类型为笔记,则遍历mDataList列表中的每个SqlData对象,并调用commit,将对应的数据保存到数据库中
|
|
|
|
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无效或为根文件夹或通话记录文件夹,则抛出IllegalStateException异常,提示正在尝试使用无效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");
|
|
|
@ -470,6 +504,7 @@ public class SqlNote {
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
if (mDiffNoteValues.size() > 0) {
|
|
|
|
mVersion ++;
|
|
|
|
mVersion ++;
|
|
|
|
int result = 0;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
//如果validateVersion值为false,则直接调用update更新内容到数据库中,否则先查询数据库中该便签的版本号,如果查询得到的版本号小于等于mVersion,则更新笔记到数据库中,否则抛出异常,提示提交失败
|
|
|
|
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[] {
|
|
|
@ -485,8 +520,9 @@ public class SqlNote {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果便签类型为笔记,则遍历mDataList列表中的每个SqlData对象,调用commit,将对应的数据保存到数据库中
|
|
|
|
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);
|
|
|
@ -495,10 +531,12 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// refresh local info
|
|
|
|
// refresh local info
|
|
|
|
|
|
|
|
//调用loadFromCursor重新加载从数据库中获取的数据,并调用loadDataContent重新加载便签的附加数据,以确保对便签修改的完整性和正确性
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|