|
|
/*
|
|
|
* Copyright (c) 2010 - 2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
* You may obtain a copy of the License at
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
import android.util.Log;
|
|
|
import net.micode.notes.data.Notes;
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
import net.micode.notes.gtask.exception.ActionFailureException;
|
|
|
import net.micode.notes.tool.GTaskStringUtils;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
// TaskList类继承自Node类,用于表示任务列表,包含任务列表的属性和操作方法
|
|
|
public class TaskList extends Node {
|
|
|
// 用于日志记录的标签,简化类名获取
|
|
|
private static final String TAG = TaskList.class.getSimpleName();
|
|
|
// 任务列表的索引
|
|
|
private int mIndex;
|
|
|
// 存储任务列表中的任务
|
|
|
private ArrayList<Task> mChildren;
|
|
|
|
|
|
// 任务列表类的构造函数,初始化任务列表的属性
|
|
|
public TaskList() {
|
|
|
super();
|
|
|
mChildren = new ArrayList<Task>();
|
|
|
mIndex = 1;
|
|
|
}
|
|
|
|
|
|
// 获取创建任务列表的操作信息,以JSON对象形式返回
|
|
|
public JSONObject getCreateAction(int actionId) {
|
|
|
JSONObject js = new JSONObject();
|
|
|
try {
|
|
|
// 设置操作类型为创建
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
|
|
|
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
|
|
|
// 设置操作ID
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
|
|
|
// 设置任务列表的索引
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
|
|
|
// 设置任务列表实体的变更信息
|
|
|
JSONObject entity = new JSONObject();
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
|
|
|
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
|
|
|
} catch (JSONException e) {
|
|
|
Log.e(TAG, e.toString());
|
|
|
e.printStackTrace();
|
|
|
// 如果生成JSON对象失败,抛出异常
|
|
|
throw new ActionFailureException("fail to generate tasklist-create jsonobject");
|
|
|
}
|
|
|
return js;
|
|
|
}
|
|
|
|
|
|
// 获取更新任务列表的操作信息,以JSON对象形式返回
|
|
|
public JSONObject getUpdateAction(int actionId) {
|
|
|
JSONObject js = new JSONObject();
|
|
|
try {
|
|
|
// 设置操作类型为更新
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
|
|
|
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
|
|
|
// 设置操作ID
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
|
|
|
// 设置任务列表的ID
|
|
|
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
|
|
|
// 设置任务列表实体的变更信息
|
|
|
JSONObject entity = new JSONObject();
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
|
|
|
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
|
|
|
js.put(GTaskStringUtils.GT |