main
commit
f0d966a7f7
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 获取相关的GID
|
||||
public String getRelatedGid() {
|
||||
return mRelatedGid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorthSaving() {
|
||||
return getNotes() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentByRemoteJSON(JSONObject js) {
|
||||
super.setContentByRemoteJSON(js);
|
||||
if (getNotes() != null) {
|
||||
try {
|
||||
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
||||
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
||||
} catch (JSONException e) {
|
||||
Log.w(TAG, "failed to get related gid");
|
||||
mRelatedGid = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentByLocalJSON(JSONObject js) {
|
||||
// 不应调用此函数
|
||||
throw new IllegalAccessError("MetaData:setContentByLocalJSON 不应该被调用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getLocalJSONFromContent() {
|
||||
throw new IllegalAccessError("MetaData:getLocalJSONFromContent 不应该被调用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSyncAction(Cursor c) {
|
||||
throw new IllegalAccessError("MetaData:getSyncAction 不应该被调用");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 org.json.JSONObject;
|
||||
|
||||
public abstract class Node {
|
||||
// 同步操作类型
|
||||
public static final int SYNC_ACTION_NONE = 0;
|
||||
public static final int SYNC_ACTION_ADD_REMOTE = 1;
|
||||
public static final int SYNC_ACTION_ADD_LOCAL = 2;
|
||||
public static final int SYNC_ACTION_DEL_REMOTE = 3;
|
||||
public static final int SYNC_ACTION_DEL_LOCAL = 4;
|
||||
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
|
||||
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
|
||||
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
|
||||
public static final int SYNC_ACTION_ERROR = 8;
|
||||
|
||||
private String mGid; // Google 任务 ID
|
||||
private String mName; // 名称
|
||||
private long mLastModified; // 最后修改时间
|
||||
private boolean mDeleted; // 是否已删除
|
||||
|
||||
// 构造函数
|
||||
public Node() {
|
||||
mGid = null;
|
||||
mName = "";
|
||||
mLastModified = 0;
|
||||
mDeleted = false;
|
||||
}
|
||||
|
||||
// 获取创建操作的 JSON 对象
|
||||
public abstract JSONObject getCreateAction(int actionId);
|
||||
|
||||
// 获取更新操作的 JSON 对象
|
||||
public abstract JSONObject getUpdateAction(int actionId);
|
||||
|
||||
// 根据远程 JSON 设置内容
|
||||
public abstract void setContentByRemoteJSON(JSONObject js);
|
||||
|
||||
// 根据本地 JSON 设置内容
|
||||
public abstract void setContentByLocalJSON(JSONObject js);
|
||||
|
||||
// 获取内容的本地 JSON 对象
|
||||
public abstract JSONObject getLocalJSONFromContent();
|
||||
|
||||
// 根据游标获取同步操作类型
|
||||
public abstract int getSyncAction(Cursor c);
|
||||
|
||||
// 设置 Google 任务 ID
|
||||
public void setGid(String gid) {
|
||||
this.mGid = gid;
|
||||
}
|
||||
|
||||
// 设置名称
|
||||
public void setName(String name) {
|
||||
this.mName = name;
|
||||
}
|
||||
|
||||
// 设置最后修改时间
|
||||
public void setLastModified(long lastModified) {
|
||||
this.mLastModified = lastModified;
|
||||
}
|
||||
|
||||
// 设置是否已删除
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.mDeleted = deleted;
|
||||
}
|
||||
|
||||
// 获取 Google 任务 ID
|
||||
public String getGid() {
|
||||
return this.mGid;
|
||||
}
|
||||
|
||||
// 获取名称
|
||||
public String getName() {
|
||||
return this.mName;
|
||||
}
|
||||
|
||||
// 获取最后修改时间
|
||||
public long getLastModified() {
|
||||
return this.mLastModified;
|
||||
}
|
||||
|
||||
// 获取是否已删除
|
||||
public boolean getDeleted() {
|
||||
return this.mDeleted;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue