|
|
@ -13,7 +13,6 @@
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
package net.micode.notes.gtask.data;
|
|
|
|
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
@ -24,36 +23,65 @@ import net.micode.notes.tool.GTaskStringUtils;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* MetaData类继承自Task类,用于处理与Google Tasks(GTask)相关的元数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class MetaData extends Task {
|
|
|
|
public class MetaData extends Task {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 类的TAG,用于日志记录。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
private final static String TAG = MetaData.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 与GTask相关的ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
private String mRelatedGid = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置元数据信息。
|
|
|
|
|
|
|
|
* @param gid 与元数据关联的ID。
|
|
|
|
|
|
|
|
* @param metaInfo 包含元数据信息的JSONObject。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
public void setMeta(String gid, JSONObject metaInfo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 将GTask的ID放入元数据中。
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
|
Log.e(TAG, "failed to put related gid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置笔记内容为元数据的字符串表示。
|
|
|
|
setNotes(metaInfo.toString());
|
|
|
|
setNotes(metaInfo.toString());
|
|
|
|
|
|
|
|
// 设置笔记名称为特定的元数据名称。
|
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
|
setName(GTaskStringUtils.META_NOTE_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取与元数据关联的GTask ID。
|
|
|
|
|
|
|
|
* @return 相关的GTask ID。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public String getRelatedGid() {
|
|
|
|
public String getRelatedGid() {
|
|
|
|
return mRelatedGid;
|
|
|
|
return mRelatedGid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断当前对象是否值得保存。
|
|
|
|
|
|
|
|
* @return 如果笔记内容不为空,则返回true。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
public boolean isWorthSaving() {
|
|
|
|
return getNotes() != null;
|
|
|
|
return getNotes() != null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从远程JSON对象设置内容。
|
|
|
|
|
|
|
|
* @param js 包含远程数据的JSONObject。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
public void setContentByRemoteJSON(JSONObject js) {
|
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
|
super.setContentByRemoteJSON(js);
|
|
|
|
if (getNotes() != null) {
|
|
|
|
if (getNotes() != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 从笔记内容中提取元数据信息,并获取相关GTask ID。
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
|
JSONObject metaInfo = new JSONObject(getNotes().trim());
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
|
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
@ -63,20 +91,30 @@ public class MetaData extends Task {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从本地JSON对象设置内容(不应该被调用)。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
public void setContentByLocalJSON(JSONObject js) {
|
|
|
|
// this function should not be called
|
|
|
|
// 抛出异常,因为此方法不应该被调用。
|
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从内容获取本地JSON对象(不应该被调用)。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
public JSONObject getLocalJSONFromContent() {
|
|
|
|
|
|
|
|
// 抛出异常,因为此方法不应该被调用。
|
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取同步操作(不应该被调用)。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
public int getSyncAction(Cursor c) {
|
|
|
|
|
|
|
|
// 抛出异常,因为此方法不应该被调用。
|
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
|
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|