main
pbhqclpae 7 months ago
parent 819523fbc1
commit a348748b3e

@ -14,68 +14,87 @@
* limitations under the License. * 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.database.Cursor; // 导入Cursor类用于数据库查询结果
import android.util.Log; 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.JSONException; // 导入JSONException用于捕获JSON相关异常
import org.json.JSONObject; import org.json.JSONObject; // 导入JSONObject类用于JSON数据处理
// 定义MetaData类继承自Task类
public class MetaData extends 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) { public void setMeta(String gid, JSONObject metaInfo) {
try { try {
// 向metaInfo对象中添加一个名为META_HEAD_GTASK_ID的字段值为传入的gid
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) { } catch (JSONException e) {
// 如果发生JSON异常记录错误日志
Log.e(TAG, "failed to put related gid"); Log.e(TAG, "failed to put related gid");
} }
// 将metaInfo转为字符串并设置到notes字段中
setNotes(metaInfo.toString()); setNotes(metaInfo.toString());
// 设置任务的名称为META_NOTE_NAME
setName(GTaskStringUtils.META_NOTE_NAME); setName(GTaskStringUtils.META_NOTE_NAME);
} }
// 获取相关的Gid
public String getRelatedGid() { public String getRelatedGid() {
return mRelatedGid; return mRelatedGid; // 返回mRelatedGid的值
} }
// 重写isWorthSaving方法判断该任务是否值得保存
@Override @Override
public boolean isWorthSaving() { public boolean isWorthSaving() {
// 如果notes不为null返回true否则返回false
return getNotes() != null; return getNotes() != null;
} }
// 重写setContentByRemoteJSON方法从远程JSON对象设置内容
@Override @Override
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js); super.setContentByRemoteJSON(js); // 调用父类的setContentByRemoteJSON方法
if (getNotes() != null) { if (getNotes() != null) {
try { try {
// 尝试将notes字段转为JSONObject对象
JSONObject metaInfo = new JSONObject(getNotes().trim()); JSONObject metaInfo = new JSONObject(getNotes().trim());
// 从metaInfo中提取Gid并赋值给mRelatedGid
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) { } catch (JSONException e) {
// 如果发生JSON异常记录警告日志并将mRelatedGid设置为null
Log.w(TAG, "failed to get related gid"); Log.w(TAG, "failed to get related gid");
mRelatedGid = null; mRelatedGid = null;
} }
} }
} }
// 重写setContentByLocalJSON方法禁止调用此方法
@Override @Override
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
// this function should not be called // 抛出IllegalAccessError表示该方法不应被调用
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
} }
// 重写getLocalJSONFromContent方法禁止调用此方法
@Override @Override
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
// 抛出IllegalAccessError表示该方法不应被调用
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
} }
// 重写getSyncAction方法禁止调用此方法
@Override @Override
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
// 抛出IllegalAccessError表示该方法不应被调用
throw new IllegalAccessError("MetaData:getSyncAction should not be called"); throw new IllegalAccessError("MetaData:getSyncAction should not be called");
} }

Loading…
Cancel
Save