|
|
|
@ -32,7 +32,7 @@ import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Task extends Node {
|
|
|
|
|
public class Task extends Node {//继承Node类的属性
|
|
|
|
|
private static final String TAG = Task.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
private boolean mCompleted;
|
|
|
|
@ -54,7 +54,7 @@ public class Task extends Node {
|
|
|
|
|
mMetaInfo = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getCreateAction(int actionId) {
|
|
|
|
|
public JSONObject getCreateAction(int actionId) {//创建一个初始的任务对象,并对它赋初值
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -103,7 +103,7 @@ public class Task extends Node {
|
|
|
|
|
return js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getUpdateAction(int actionId) {
|
|
|
|
|
public JSONObject getUpdateAction(int actionId) {//更新任务
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -120,7 +120,7 @@ public class Task extends Node {
|
|
|
|
|
// entity_delta
|
|
|
|
|
JSONObject entity = new JSONObject();
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
|
|
|
|
|
if (getNotes() != null) {
|
|
|
|
|
if (getNotes() != null) {//如果笔记不为空,更新笔记
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
|
|
|
|
|
}
|
|
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
|
|
|
|
@ -135,11 +135,11 @@ public class Task extends Node {
|
|
|
|
|
return js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {//通过远端的json设置内容的值
|
|
|
|
|
if (js != null) {
|
|
|
|
|
try {
|
|
|
|
|
// id
|
|
|
|
|
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
|
|
|
|
|
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {//如果值已经被json对象所具备,则直接进行设置
|
|
|
|
|
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -175,7 +175,7 @@ public class Task extends Node {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {//通过本地的json文件来设置内容
|
|
|
|
|
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|
|
|
|
|
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
|
|
|
|
|
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
|
|
|
|
@ -204,7 +204,7 @@ public class Task extends Node {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
|
public JSONObject getLocalJSONFromContent() {//通过本地的内容,生成json文件
|
|
|
|
|
String name = getName();
|
|
|
|
|
try {
|
|
|
|
|
if (mMetaInfo == null) {
|
|
|
|
@ -216,7 +216,7 @@ public class Task extends Node {
|
|
|
|
|
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
JSONObject note = new JSONObject();
|
|
|
|
|
JSONArray dataArray = new JSONArray();
|
|
|
|
|
JSONArray dataArray = new JSONArray();//声明所有所要用到的变量
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
data.put(DataColumns.CONTENT, name);
|
|
|
|
|
dataArray.put(data);
|
|
|
|
@ -227,7 +227,7 @@ public class Task extends Node {
|
|
|
|
|
} else {
|
|
|
|
|
// synced task
|
|
|
|
|
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
|
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
|
|
|
|
|
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);//提取出所有的信息
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
JSONObject data = dataArray.getJSONObject(i);
|
|
|
|
@ -258,11 +258,11 @@ public class Task extends Node {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
|
public int getSyncAction(Cursor c) {//同步缓存
|
|
|
|
|
try {
|
|
|
|
|
JSONObject noteInfo = null;
|
|
|
|
|
if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
|
|
|
|
|
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
|
|
|
|
|
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);//更新到最新的笔记信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (noteInfo == null) {
|
|
|
|
@ -311,14 +311,14 @@ public class Task extends Node {
|
|
|
|
|
return SYNC_ACTION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
|
public boolean isWorthSaving() {//只要有信息就认为是值得保存的,返回true
|
|
|
|
|
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|
|
|
|
|
|| (getNotes() != null && getNotes().trim().length() > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCompleted(boolean completed) {
|
|
|
|
|
this.mCompleted = completed;
|
|
|
|
|
}
|
|
|
|
|
}//进行前面使用过的调用函数返回值的对应
|
|
|
|
|
|
|
|
|
|
public void setNotes(String notes) {
|
|
|
|
|
this.mNotes = notes;
|
|
|
|
|