From 63389b0fb6a5bbc7a6a1723df122b2bfcf0681b4 Mon Sep 17 00:00:00 2001 From: FXH <230007021@qq.com> Date: Tue, 8 Oct 2024 12:36:43 +0800 Subject: [PATCH] =?UTF-8?q?MetaData=E7=B1=BB=E7=94=A8=E4=BA=8E=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=B8=8E=E4=BB=BB=E5=8A=A1=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E6=AD=A3=E7=A1=AE=E5=9C=B0=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=92=8C=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MetaData.java | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 MetaData.java diff --git a/MetaData.java b/MetaData.java new file mode 100644 index 0000000..b47361a --- /dev/null +++ b/MetaData.java @@ -0,0 +1,103 @@ +// 多行注释,说明版权信息和许可证 +/* + * 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类,用于处理与任务相关的元数据 +public class MetaData extends Task { + // 类的标签,用于日志记录 + private final static String TAG = MetaData.class.getSimpleName(); + + // 用于存储相关任务的全局唯一标识符 + private String mRelatedGid = null; + + // 设置元数据信息 + public void setMeta(String gid, JSONObject metaInfo) { + try { + // 将全局唯一标识符添加到元数据信息中 + 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); + } + + // 获取相关任务的全局唯一标识符 + public String getRelatedGid() { + return mRelatedGid; + } + + // 重写isWorthSaving方法,判断任务是否值得保存 + @Override + public boolean isWorthSaving() { + // 如果任务的备注信息不为空,则认为值得保存 + return getNotes() != null; + } + + // 从远程JSON对象设置内容 + @Override + public void setContentByRemoteJSON(JSONObject js) { + // 首先调用父类的设置内容方法 + super.setContentByRemoteJSON(js); + // 如果备注信息不为空 + if (getNotes() != null) { + try { + // 将备注信息转换为JSON对象,并获取全局唯一标识符 + JSONObject metaInfo = new JSONObject(getNotes().trim()); + mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); + } catch (JSONException e) { + // 如果转换失败,记录警告日志,并设置全局唯一标识符为null + Log.w(TAG, "failed to get related gid"); + mRelatedGid = null; + } + } + } + + // 从本地JSON对象设置内容,此方法不应该被调用 + @Override + public void setContentByLocalJSON(JSONObject js) { + // 如果被调用,抛出异常 + throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); + } + + // 从内容获取本地JSON对象,此方法不应该被调用 + @Override + public JSONObject getLocalJSONFromContent() { + // 如果被调用,抛出异常 + throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); + } + + // 获取同步操作,此方法不应该被调用 + @Override + public int getSyncAction(Cursor c) { + // 如果被调用,抛出异常 + throw new IllegalAccessError("MetaData:getSyncAction should not be called"); + } +} \ No newline at end of file