You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* 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.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
/**
* 元数据任务类继承自基础Task类
*
* 功能说明:
* - 用于处理与Google Task相关的元数据信息
* - 存储关联任务ID(gid)和元信息JSON数据
* - 作为特殊类型的任务,不参与常规的同步操作
*
* 注意事项:
* - 此类重写了部分父类方法并直接抛出异常,因为元数据不应通过常规方式操作
* - 主要用于在笔记和Google Task之间建立关联关系
*/
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/**
* 设置元数据信息
* @param gid 关联的Google Task ID
* @param metaInfo 要存储的元信息JSON对象
*
* 说明:
* - 将gid存入JSON对象中
* - 设置固定的任务名称标识此为元数据任务
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
public String getRelatedGid() {
return mRelatedGid;
}
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* 从远程JSON数据设置内容
* @param js 包含远程数据的JSON对象
*
* 说明:
* - 解析notes字段中的JSON数据获取关联gid
* - 如果解析失败会清空已存储的gid
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
/**
* (禁止使用)从本地JSON设置内容
* @throws IllegalAccessError 始终抛出因为元数据不应通过本地JSON设置
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* (禁止使用)获取本地JSON内容
* @throws IllegalAccessError 始终抛出因为元数据不应转换为本地JSON
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
* (禁止使用)获取同步动作
* @throws IllegalAccessError 始终抛出,因为元数据不应参与常规同步
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}