|
|
|
@ -42,7 +42,11 @@ public class TaskList extends Node {
|
|
|
|
|
mChildren = new ArrayList<Task>();
|
|
|
|
|
mIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取创建操作JSON对象
|
|
|
|
|
* @param actionId 操作ID
|
|
|
|
|
* @return JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject getCreateAction(int actionId) {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
@ -73,7 +77,11 @@ public class TaskList extends Node {
|
|
|
|
|
|
|
|
|
|
return js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取更新操作JSON对象
|
|
|
|
|
* @param actionId 操作ID
|
|
|
|
|
* @return JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject getUpdateAction(int actionId) {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
|
|
|
|
|
@ -102,7 +110,10 @@ public class TaskList extends Node {
|
|
|
|
|
|
|
|
|
|
return js;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据远程JSON对象设置内容
|
|
|
|
|
* @param js JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
|
if (js != null) {
|
|
|
|
|
try {
|
|
|
|
@ -128,7 +139,10 @@ public class TaskList extends Node {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据本地JSON对象设置内容
|
|
|
|
|
* @param js JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
|
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
|
|
|
|
|
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
|
|
|
|
@ -156,7 +170,10 @@ public class TaskList extends Node {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从内容获取本地JSON对象
|
|
|
|
|
* @return JSON对象
|
|
|
|
|
*/
|
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject js = new JSONObject();
|
|
|
|
@ -182,7 +199,11 @@ public class TaskList extends Node {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取同步操作
|
|
|
|
|
* @param c Cursor
|
|
|
|
|
* @return 同步操作
|
|
|
|
|
*/
|
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
|
try {
|
|
|
|
|
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
|
|
|
|
@ -215,11 +236,18 @@ public class TaskList extends Node {
|
|
|
|
|
|
|
|
|
|
return SYNC_ACTION_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取子任务数
|
|
|
|
|
* @return 子任务数
|
|
|
|
|
*/
|
|
|
|
|
public int getChildTaskCount() {
|
|
|
|
|
return mChildren.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加子任务
|
|
|
|
|
* @param task 子任务
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean addChildTask(Task task) {
|
|
|
|
|
boolean ret = false;
|
|
|
|
|
if (task != null && !mChildren.contains(task)) {
|
|
|
|
@ -233,7 +261,12 @@ public class TaskList extends Node {
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在指定位置添加子任务
|
|
|
|
|
* @param task 子任务
|
|
|
|
|
* @param index 位置
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean addChildTask(Task task, int index) {
|
|
|
|
|
if (index < 0 || index > mChildren.size()) {
|
|
|
|
|
Log.e(TAG, "add child task: invalid index");
|
|
|
|
@ -259,7 +292,11 @@ public class TaskList extends Node {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 移除子任务
|
|
|
|
|
* @param task 子任务
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean removeChildTask(Task task) {
|
|
|
|
|
boolean ret = false;
|
|
|
|
|
int index = mChildren.indexOf(task);
|
|
|
|
@ -280,7 +317,12 @@ public class TaskList extends Node {
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 移动子任务位置
|
|
|
|
|
* @param task 子任务
|
|
|
|
|
* @param index 目标位置
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public boolean moveChildTask(Task task, int index) {
|
|
|
|
|
|
|
|
|
|
if (index < 0 || index >= mChildren.size()) {
|
|
|
|
@ -298,7 +340,11 @@ public class TaskList extends Node {
|
|
|
|
|
return true;
|
|
|
|
|
return (removeChildTask(task) && addChildTask(task, index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据GID查找子任务
|
|
|
|
|
* @param gid GID
|
|
|
|
|
* @return 子任务
|
|
|
|
|
*/
|
|
|
|
|
public Task findChildTaskByGid(String gid) {
|
|
|
|
|
for (int i = 0; i < mChildren.size(); i++) {
|
|
|
|
|
Task t = mChildren.get(i);
|
|
|
|
@ -308,11 +354,19 @@ public class TaskList extends Node {
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取子任务位置
|
|
|
|
|
* @param task 子任务
|
|
|
|
|
* @return 位置
|
|
|
|
|
*/
|
|
|
|
|
public int getChildTaskIndex(Task task) {
|
|
|
|
|
return mChildren.indexOf(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据位置获取子任务
|
|
|
|
|
* @param index 位置
|
|
|
|
|
* @return 子任务
|
|
|
|
|
*/
|
|
|
|
|
public Task getChildTaskByIndex(int index) {
|
|
|
|
|
if (index < 0 || index >= mChildren.size()) {
|
|
|
|
|
Log.e(TAG, "getTaskByIndex: invalid index");
|
|
|
|
@ -320,7 +374,11 @@ public class TaskList extends Node {
|
|
|
|
|
}
|
|
|
|
|
return mChildren.get(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据GID获取子任务
|
|
|
|
|
* @param gid GID
|
|
|
|
|
* @return 子任务
|
|
|
|
|
*/
|
|
|
|
|
public Task getChilTaskByGid(String gid) {
|
|
|
|
|
for (Task task : mChildren) {
|
|
|
|
|
if (task.getGid().equals(gid))
|
|
|
|
|