|
|
|
@ -1,130 +0,0 @@
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MetaData 类继承自 Task,用于处理与任务相关的元数据。
|
|
|
|
|
* 主要功能包括设置和获取与任务关联的全局唯一标识符(GID)。
|
|
|
|
|
*/
|
|
|
|
|
public class MetaData extends Task {
|
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 存储与任务关联的全局唯一标识符(GID)。
|
|
|
|
|
*/
|
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置任务的元数据信息,并将 GID 添加到元数据中。
|
|
|
|
|
*
|
|
|
|
|
* @param gid 任务的全局唯一标识符(GID)
|
|
|
|
|
* @param metaInfo 包含任务元数据的 JSON 对象
|
|
|
|
|
*/
|
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
|
try {
|
|
|
|
|
// 将 GID 添加到元数据中
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取与任务关联的全局唯一标识符(GID)。
|
|
|
|
|
*
|
|
|
|
|
* @return 返回任务的 GID
|
|
|
|
|
*/
|
|
|
|
|
public String getRelatedGid() {
|
|
|
|
|
return mRelatedGid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否有值得保存的笔记内容。
|
|
|
|
|
*
|
|
|
|
|
* @return 如果有笔记内容则返回 true,否则返回 false
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
|
return getNotes() != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通过远程 JSON 数据设置任务内容,并解析出 GID。
|
|
|
|
|
*
|
|
|
|
|
* @param js 包含任务内容的 JSON 对象
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
|
|
if (getNotes() != null) {
|
|
|
|
|
try {
|
|
|
|
|
// 解析笔记内容中的元数据并提取 GID
|
|
|
|
|
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 数据设置任务内容的方法不应被调用。
|
|
|
|
|
*
|
|
|
|
|
* @param js 包含任务内容的 JSON 对象
|
|
|
|
|
* @throws IllegalAccessError 抛出异常表示该方法不应被调用
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从任务内容生成本地 JSON 数据的方法不应被调用。
|
|
|
|
|
*
|
|
|
|
|
* @throws IllegalAccessError 抛出异常表示该方法不应被调用
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取同步操作的方法不应被调用。
|
|
|
|
|
*
|
|
|
|
|
* @param c 游标对象
|
|
|
|
|
* @throws IllegalAccessError 抛出异常表示该方法不应被调用
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|