|
|
@ -1,17 +1,15 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* 遵循Apache License, Version 2.0("许可证");
|
|
|
|
* 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
|
|
|
|
* 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;
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
@ -24,59 +22,96 @@ import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 元数据类,继承自Task,用于处理与Google Tasks(GTask)相关的元数据信息
|
|
|
|
|
|
|
|
* 主要功能:管理GTask的关联ID和元数据信息的JSON序列化/反序列化
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class MetaData extends Task {
|
|
|
|
public class MetaData extends Task {
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 关联的GTask全局唯一标识符(GID)
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置元数据信息
|
|
|
|
|
|
|
|
* @param gid GTask的唯一标识符(GID)
|
|
|
|
|
|
|
|
* @param metaInfo 包含元数据的JSON对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 在元数据JSON中添加GTASK_ID字段,值为传入的gid
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将元数据JSON转换为字符串,存储到Task的notes字段
|
|
|
|
setNotes(metaInfo.toString());
|
|
|
|
setNotes(metaInfo.toString());
|
|
|
|
|
|
|
|
// 设置Task的名称为元数据专用名称(常量定义)
|
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取关联的GTask的GID
|
|
|
|
|
|
|
|
* @return 关联的GID,若未设置则返回null
|
|
|
|
|
|
|
|
*/
|
|
|
|
public String getRelatedGid() {
|
|
|
|
public String getRelatedGid() {
|
|
|
|
return mRelatedGid;
|
|
|
|
return mRelatedGid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断元数据是否值得保存(检查notes字段是否存在)
|
|
|
|
|
|
|
|
* @return true if notes字段不为null,否则false
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
return getNotes() != null;
|
|
|
|
return getNotes() != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从远程JSON数据中解析并设置内容(覆写父类方法)
|
|
|
|
|
|
|
|
* @param js 包含远程数据的JSON对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
|
super.setContentByRemoteJSON(js); // 先调用父类实现
|
|
|
|
if (getNotes() != null) {
|
|
|
|
if (getNotes() != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 将notes字段解析为JSON对象
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
|
|
|
|
|
// 从中提取GTASK_ID作为关联的GID
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
|
mRelatedGid = null;
|
|
|
|
mRelatedGid = null; // 解析失败时清空GID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 禁止从本地JSON设置内容(覆写父类方法,抛出异常防止调用)
|
|
|
|
|
|
|
|
* @param js 本地JSON对象(未使用)
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
// this function should not be called
|
|
|
|
|
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 禁止从内容获取本地JSON(覆写父类方法,抛出异常防止调用)
|
|
|
|
|
|
|
|
* @return 永远抛出异常,不返回有效数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 禁止获取同步操作类型(覆写父类方法,抛出异常防止调用)
|
|
|
|
|
|
|
|
* @param c 数据库游标(未使用)
|
|
|
|
|
|
|
|
* @return 永远抛出异常,不返回有效数据
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|