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.
xiaomi/src/net/micode/notes/gtask/data/MetaData.java

109 lines
3.6 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.

/**
* 文件的版权声明,说明该文件是 MiCode 开源社区的版权所有,并且遵循 Apache License 2.0。
*/
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 类,用于处理任务的元数据。
*/
public class MetaData extends Task {
// 日志标签,用于在 Log 类中记录日志时标识日志来源。
private final static String TAG = MetaData.class.getSimpleName();
// 存储与当前任务相关联的全局ID。
private String mRelatedGid = null;
/**
* 设置元数据信息。
* @param gid 任务的全局ID。
* @param metaInfo 包含元数据的 JSON 对象。
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
// 将全局ID添加到元数据的 JSON 对象中。
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
// 如果在添加全局ID时发生错误记录错误日志。
Log.e(TAG, "failed to put related gid");
}
// 将 JSON 对象转换为字符串并设置为备注。
setNotes(metaInfo.toString());
// 设置任务的名称为元数据的特定名称。
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* 获取与当前任务相关联的全局ID。
* @return 返回全局ID。
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
* 判断任务是否值得保存。
* 如果任务的备注notes不为空则返回 true。
* @return 任务是否值得保存。
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* 从远程 JSON 对象设置内容并尝试从中获取相关任务的全局ID。
* @param js 远程 JSON 对象。
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
// 将备注转换为 JSON 对象并尝试获取全局ID。
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
// 如果在获取全局ID时发生错误记录警告日志并设置全局ID为 null。
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
/**
* 这个方法不应该被调用,如果被调用,会抛出 IllegalAccessError。
* @param js 本地 JSON 对象。
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* 这个方法不应该被调用,如果被调用,会抛出 IllegalAccessError。
* @return 本地 JSON 对象。
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
* 这个方法不应该被调用,如果被调用,会抛出 IllegalAccessError。
* @param c 数据库游标。
* @return 同步操作。
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}
}