添加注释

pull/1/head
luchan 2 months ago
parent 5016300f96
commit 75451e31de

@ -24,59 +24,95 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
/**
* MetaData Google Tasks (GTask)
* Task GTask
*/
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();
// 关联的 GTask ID全局唯一标识
private String mRelatedGid = null;
/**
*
* @param gid GTask ID
* @param metaInfo JSON
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将 GTask ID 存入元数据头部
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
Log.e(TAG, "failed to put related gid", e); // 记录异常日志
}
// 将元数据 JSON 转为字符串存储到便签内容中
setNotes(metaInfo.toString());
// 设置便签名称为固定值(元数据便签标识)
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* GTask ID
* @return GTask ID null
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
*
* @return true notes null false
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
return getNotes() != null; // 依赖父类 Task 的 getNotes() 方法
}
/**
* JSON
* @param js JSON
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
super.setContentByRemoteJSON(js); // 先调用父类解析逻辑
if (getNotes() != null) {
try {
// 解析 notes 字段为元数据 JSON 对象
JSONObject metaInfo = new JSONObject(getNotes().trim());
// 提取关联的 GTask ID
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
Log.w(TAG, "failed to get related gid", e); // 记录解析异常
mRelatedGid = null; // 解析失败时置空
}
}
}
/**
* JSON
* @throws IllegalAccessError
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
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");
}
/**
*
* @throws IllegalAccessError
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}
}
Loading…
Cancel
Save