|
|
package net.micode.notes.gtask.data;
|
|
|
// 定义MetaData类,它继承自Task类
|
|
|
public class MetaData extends Task {
|
|
|
// 定义一个私有静态常量TAG,用于记录类的简单名称,通常用于日志输出
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
// 定义一个私有成员变量mRelatedGid,用于存储相关的Gid,初始化为null
|
|
|
private String mRelatedGid = null;
|
|
|
// 此方法接受一个字符串gid和一个JSONObject类型的metaInfo作为参数
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
try {
|
|
|
// 尝试将gid放入metaInfo对象中,键为GTaskStringUtils.META_HEAD_GTASK_ID
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果发生JSON异常,在日志中记录错误信息,表示无法放入相关gid
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
}
|
|
|
// 将metaInfo转换为字符串后设置为笔记内容
|
|
|
setNotes(metaInfo.toString());
|
|
|
// 设置名称为GTaskStringUtils.META_NOTE_NAME
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
}
|
|
|
// 此方法用于获取相关的Gid
|
|
|
public String getRelatedGid() {
|
|
|
return mRelatedGid;
|
|
|
}
|
|
|
// 重写isWorthSaving方法,判断笔记内容是否不为空,如果不为空则表示值得保存
|
|
|
@Override
|
|
|
public boolean isWorthSaving() {
|
|
|
return getNotes()!= null;
|
|
|
}
|
|
|
// 重写setContentByRemoteJSON方法
|
|
|
@Override
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
if (getNotes()!= null) {
|
|
|
try {
|
|
|
// 如果笔记内容不为空,将其转换为JSONObject类型的metaInfo
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
// 从metaInfo中获取相关的Gid字符串
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
} catch (JSONException e) {
|
|
|
// 如果发生JSON异常,在日志中记录警告信息,表示无法获取相关gid
|
|
|
Log.w(TAG, "failed to get related gid");
|
|
|
mRelatedGid = null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 重写setContentByLocalJSON方法,此方法不应该被调用,如果调用则抛出IllegalAccessError异常
|
|
|
@Override
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
}
|
|
|
// 重写getLocalJSONFromContent方法,此方法不应该被调用,如果调用则抛出IllegalAccessError异常
|
|
|
@Override
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
}
|
|
|
// 重写getSyncAction方法,此方法不应该被调用,如果调用则抛出IllegalAccessError异常
|
|
|
@Override
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
}
|
|
|
|
|
|
} |