|
|
@ -37,7 +37,9 @@ import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* SqlNote类代表一个笔记实体,它可以从数据库中存储和检索。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class SqlNote {
|
|
|
|
public class SqlNote {
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
private static final String TAG = SqlNote.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
@ -121,7 +123,10 @@ public class SqlNote {
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
private ContentValues mDiffNoteValues;
|
|
|
|
|
|
|
|
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
private ArrayList<SqlData> mDataList;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 构造一个新的SqlNote实例。
|
|
|
|
|
|
|
|
* @param context 上下文对象。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
public SqlNote(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
mContext = context;
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
|
mContentResolver = context.getContentResolver();
|
|
|
@ -142,7 +147,11 @@ public class SqlNote {
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
mDataList = new ArrayList<SqlData>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从游标构造SqlNote实例。
|
|
|
|
|
|
|
|
* @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();
|
|
|
@ -153,7 +162,11 @@ public class SqlNote {
|
|
|
|
loadDataContent();
|
|
|
|
loadDataContent();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
mDiffNoteValues = new ContentValues();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从ID加载SqlNote实例。
|
|
|
|
|
|
|
|
* @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();
|
|
|
@ -225,7 +238,11 @@ public class SqlNote {
|
|
|
|
c.close();
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据JSON对象设置笔记内容。
|
|
|
|
|
|
|
|
* @param js JSON对象。
|
|
|
|
|
|
|
|
* @return 设置成功返回true,否则返回false。
|
|
|
|
|
|
|
|
*/
|
|
|
|
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);
|
|
|
@ -358,7 +375,10 @@ public class SqlNote {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取笔记内容的JSON对象。
|
|
|
|
|
|
|
|
* @return 笔记内容的JSON对象。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public JSONObject getContent() {
|
|
|
|
public JSONObject getContent() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
@ -439,7 +459,10 @@ public class SqlNote {
|
|
|
|
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)) {
|
|
|
|