From a348748b3e31504b6565f6d5d99e047feff36031 Mon Sep 17 00:00:00 2001 From: pbhqclpae <1054452395@qq.com> Date: Tue, 31 Dec 2024 23:58:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=92=8B=E5=8D=9A=E8=BD=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/net/micode/notes/gtask/data/MetaData.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/net/micode/notes/gtask/data/MetaData.java b/src/net/micode/notes/gtask/data/MetaData.java index 3a2050b..06ec15c 100644 --- a/src/net/micode/notes/gtask/data/MetaData.java +++ b/src/net/micode/notes/gtask/data/MetaData.java @@ -14,68 +14,87 @@ * limitations under the License. */ -package net.micode.notes.gtask.data; +// 导入所需的包 +package net.micode.notes.gtask.data; // 声明该类属于 net.micode.notes.gtask.data 包 -import android.database.Cursor; -import android.util.Log; +import android.database.Cursor; // 导入Cursor类,用于数据库查询结果 +import android.util.Log; // 导入Log类,用于日志记录 -import net.micode.notes.tool.GTaskStringUtils; +import net.micode.notes.tool.GTaskStringUtils; // 导入GTaskStringUtils工具类 -import org.json.JSONException; -import org.json.JSONObject; +import org.json.JSONException; // 导入JSONException,用于捕获JSON相关异常 +import org.json.JSONObject; // 导入JSONObject类,用于JSON数据处理 +// 定义MetaData类,继承自Task类 public class MetaData extends Task { - private final static String TAG = MetaData.class.getSimpleName(); + private final static String TAG = MetaData.class.getSimpleName(); // 定义TAG常量,表示该类的简短名称,用于日志打印 - private String mRelatedGid = null; + private String mRelatedGid = null; // 声明mRelatedGid变量,用于存储相关的Gid + // 设置Meta数据的方法,接受gid和meta信息(JSON对象) public void setMeta(String gid, JSONObject metaInfo) { try { + // 向metaInfo对象中添加一个名为META_HEAD_GTASK_ID的字段,值为传入的gid metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); } catch (JSONException e) { + // 如果发生JSON异常,记录错误日志 Log.e(TAG, "failed to put related gid"); } + // 将metaInfo转为字符串并设置到notes字段中 setNotes(metaInfo.toString()); + // 设置任务的名称为META_NOTE_NAME setName(GTaskStringUtils.META_NOTE_NAME); } + // 获取相关的Gid public String getRelatedGid() { - return mRelatedGid; + return mRelatedGid; // 返回mRelatedGid的值 } + // 重写isWorthSaving方法,判断该任务是否值得保存 @Override public boolean isWorthSaving() { + // 如果notes不为null,返回true;否则返回false return getNotes() != null; } + // 重写setContentByRemoteJSON方法,从远程JSON对象设置内容 @Override public void setContentByRemoteJSON(JSONObject js) { - super.setContentByRemoteJSON(js); + super.setContentByRemoteJSON(js); // 调用父类的setContentByRemoteJSON方法 if (getNotes() != null) { try { + // 尝试将notes字段转为JSONObject对象 JSONObject metaInfo = new JSONObject(getNotes().trim()); + // 从metaInfo中提取Gid并赋值给mRelatedGid mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); } catch (JSONException e) { + // 如果发生JSON异常,记录警告日志,并将mRelatedGid设置为null Log.w(TAG, "failed to get related gid"); mRelatedGid = null; } } } + // 重写setContentByLocalJSON方法,禁止调用此方法 @Override public void setContentByLocalJSON(JSONObject js) { - // this function should not be called + // 抛出IllegalAccessError,表示该方法不应被调用 throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); } + // 重写getLocalJSONFromContent方法,禁止调用此方法 @Override public JSONObject getLocalJSONFromContent() { + // 抛出IllegalAccessError,表示该方法不应被调用 throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); } + // 重写getSyncAction方法,禁止调用此方法 @Override public int getSyncAction(Cursor c) { + // 抛出IllegalAccessError,表示该方法不应被调用 throw new IllegalAccessError("MetaData:getSyncAction should not be called"); }