|
|
|
@ -47,57 +47,46 @@ import java.util.HashSet;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class GTaskManager {
|
|
|
|
|
// 日志标签,用于调试和日志记录
|
|
|
|
|
private static final String TAG = GTaskManager.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
// 同步状态常量
|
|
|
|
|
public static final int STATE_SUCCESS = 0;
|
|
|
|
|
|
|
|
|
|
public static final int STATE_NETWORK_ERROR = 1;
|
|
|
|
|
|
|
|
|
|
public static final int STATE_INTERNAL_ERROR = 2;
|
|
|
|
|
|
|
|
|
|
public static final int STATE_SYNC_IN_PROGRESS = 3;
|
|
|
|
|
|
|
|
|
|
public static final int STATE_SYNC_CANCELLED = 4;
|
|
|
|
|
|
|
|
|
|
// 单例实例
|
|
|
|
|
private static GTaskManager mInstance = null;
|
|
|
|
|
|
|
|
|
|
// 当前活动的Activity
|
|
|
|
|
private Activity mActivity;
|
|
|
|
|
|
|
|
|
|
// 上下文环境
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
// 内容解析器
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
|
|
|
|
|
// 同步状态
|
|
|
|
|
private boolean mSyncing;
|
|
|
|
|
|
|
|
|
|
// 是否取消同步
|
|
|
|
|
private boolean mCancelled;
|
|
|
|
|
|
|
|
|
|
// GTask列表映射
|
|
|
|
|
private HashMap<String, TaskList> mGTaskListHashMap;
|
|
|
|
|
|
|
|
|
|
// GTask映射
|
|
|
|
|
private HashMap<String, Node> mGTaskHashMap;
|
|
|
|
|
|
|
|
|
|
// 元数据映射
|
|
|
|
|
private HashMap<String, MetaData> mMetaHashMap;
|
|
|
|
|
|
|
|
|
|
// 元数据列表
|
|
|
|
|
private TaskList mMetaList;
|
|
|
|
|
|
|
|
|
|
// 本地删除ID集合
|
|
|
|
|
private HashSet<Long> mLocalDeleteIdMap;
|
|
|
|
|
|
|
|
|
|
// GID到NID的映射
|
|
|
|
|
private HashMap<String, Long> mGidToNid;
|
|
|
|
|
|
|
|
|
|
// NID到GID的映射
|
|
|
|
|
private HashMap<Long, String> mNidToGid;
|
|
|
|
|
|
|
|
|
|
// 私有构造方法,用于单例模式
|
|
|
|
|
private GTaskManager() {
|
|
|
|
|
mSyncing = false;
|
|
|
|
|
mCancelled = false;
|
|
|
|
@ -110,7 +99,6 @@ public class GTaskManager {
|
|
|
|
|
mNidToGid = new HashMap<Long, String>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取单例实例
|
|
|
|
|
public static synchronized GTaskManager getInstance() {
|
|
|
|
|
if (mInstance == null) {
|
|
|
|
|
mInstance = new GTaskManager();
|
|
|
|
@ -118,12 +106,11 @@ public class GTaskManager {
|
|
|
|
|
return mInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置活动的Activity
|
|
|
|
|
public synchronized void setActivityContext(Activity activity) {
|
|
|
|
|
// used for getting authtoken
|
|
|
|
|
mActivity = activity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行同步操作
|
|
|
|
|
public int sync(Context context, GTaskASyncTask asyncTask) {
|
|
|
|
|
if (mSyncing) {
|
|
|
|
|
Log.d(TAG, "Sync is in progress");
|
|
|
|
@ -144,18 +131,18 @@ public class GTaskManager {
|
|
|
|
|
GTaskClient client = GTaskClient.getInstance();
|
|
|
|
|
client.resetUpdateArray();
|
|
|
|
|
|
|
|
|
|
// 登录Google Tasks
|
|
|
|
|
// login google task
|
|
|
|
|
if (!mCancelled) {
|
|
|
|
|
if (!client.login(mActivity)) {
|
|
|
|
|
throw new NetworkFailureException("login google task failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化GTask列表
|
|
|
|
|
// get the task list from google
|
|
|
|
|
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
|
|
|
|
|
initGTaskList();
|
|
|
|
|
|
|
|
|
|
// 执行内容同步
|
|
|
|
|
// do content sync work
|
|
|
|
|
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_syncing));
|
|
|
|
|
syncContent();
|
|
|
|
|
} catch (NetworkFailureException e) {
|
|
|
|
@ -181,7 +168,6 @@ public class GTaskManager {
|
|
|
|
|
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化GTask列表
|
|
|
|
|
private void initGTaskList() throws NetworkFailureException {
|
|
|
|
|
if (mCancelled)
|
|
|
|
|
return;
|
|
|
|
@ -189,7 +175,7 @@ public class GTaskManager {
|
|
|
|
|
try {
|
|
|
|
|
JSONArray jsTaskLists = client.getTaskLists();
|
|
|
|
|
|
|
|
|
|
// 初始化元数据列表
|
|
|
|
|
// init meta list first
|
|
|
|
|
mMetaList = null;
|
|
|
|
|
for (int i = 0; i < jsTaskLists.length(); i++) {
|
|
|
|
|
JSONObject object = jsTaskLists.getJSONObject(i);
|
|
|
|
@ -201,7 +187,7 @@ public class GTaskManager {
|
|
|
|
|
mMetaList = new TaskList();
|
|
|
|
|
mMetaList.setContentByRemoteJSON(object);
|
|
|
|
|
|
|
|
|
|
// 加载元数据
|
|
|
|
|
// load meta data
|
|
|
|
|
JSONArray jsMetas = client.getTaskList(gid);
|
|
|
|
|
for (int j = 0; j < jsMetas.length(); j++) {
|
|
|
|
|
object = (JSONObject) jsMetas.getJSONObject(j);
|
|
|
|
@ -217,7 +203,7 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建元数据列表(如果不存在)
|
|
|
|
|
// create meta list if not existed
|
|
|
|
|
if (mMetaList == null) {
|
|
|
|
|
mMetaList = new TaskList();
|
|
|
|
|
mMetaList.setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
|
|
|
|
@ -225,7 +211,7 @@ public class GTaskManager {
|
|
|
|
|
GTaskClient.getInstance().createTaskList(mMetaList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化任务列表
|
|
|
|
|
// init task list
|
|
|
|
|
for (int i = 0; i < jsTaskLists.length(); i++) {
|
|
|
|
|
JSONObject object = jsTaskLists.getJSONObject(i);
|
|
|
|
|
String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
|
|
|
|
@ -233,13 +219,13 @@ public class GTaskManager {
|
|
|
|
|
|
|
|
|
|
if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)
|
|
|
|
|
&& !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX
|
|
|
|
|
+ GTaskStringUtils.FOLDERMETA)) {
|
|
|
|
|
+ GTaskStringUtils.FOLDER_META)) {
|
|
|
|
|
TaskList tasklist = new TaskList();
|
|
|
|
|
tasklist.setContentByRemoteJSON(object);
|
|
|
|
|
mGTaskListHashMap.put(gid, tasklist);
|
|
|
|
|
mGTaskHashMap.put(gid, tasklist);
|
|
|
|
|
|
|
|
|
|
// 加载任务
|
|
|
|
|
// load tasks
|
|
|
|
|
JSONArray jsTasks = client.getTaskList(gid);
|
|
|
|
|
for (int j = 0; j < jsTasks.length(); j++) {
|
|
|
|
|
object = (JSONObject) jsTasks.getJSONObject(j);
|
|
|
|
@ -261,7 +247,6 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行内容同步
|
|
|
|
|
private void syncContent() throws NetworkFailureException {
|
|
|
|
|
int syncType;
|
|
|
|
|
Cursor c = null;
|
|
|
|
@ -274,7 +259,7 @@ public class GTaskManager {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步本地删除的便签
|
|
|
|
|
// for local deleted note
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
|
|
|
|
|
"(type<>? AND parent_id=?)", new String[] {
|
|
|
|
@ -301,10 +286,10 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步文件夹
|
|
|
|
|
// sync folder first
|
|
|
|
|
syncFolder();
|
|
|
|
|
|
|
|
|
|
// 同步便签
|
|
|
|
|
// for note existing in database
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
|
|
|
|
|
"(type=? AND parent_id<>?)", new String[] {
|
|
|
|
@ -321,8 +306,10 @@ public class GTaskManager {
|
|
|
|
|
syncType = node.getSyncAction(c);
|
|
|
|
|
} else {
|
|
|
|
|
if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) {
|
|
|
|
|
// local add
|
|
|
|
|
syncType = Node.SYNC_ACTION_ADD_REMOTE;
|
|
|
|
|
} else {
|
|
|
|
|
// remote delete
|
|
|
|
|
syncType = Node.SYNC_ACTION_DEL_LOCAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -339,7 +326,7 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步剩余项目
|
|
|
|
|
// go through remaining items
|
|
|
|
|
Iterator<Map.Entry<String, Node>> iter = mGTaskHashMap.entrySet().iterator();
|
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
|
Map.Entry<String, Node> entry = iter.next();
|
|
|
|
@ -347,21 +334,23 @@ public class GTaskManager {
|
|
|
|
|
doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除本地删除表
|
|
|
|
|
// mCancelled can be set by another thread, so we neet to check one by
|
|
|
|
|
// one
|
|
|
|
|
// clear local delete table
|
|
|
|
|
if (!mCancelled) {
|
|
|
|
|
if (!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) {
|
|
|
|
|
throw new ActionFailureException("failed to batch-delete local deleted notes");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 刷新本地同步ID
|
|
|
|
|
// refresh local sync id
|
|
|
|
|
if (!mCancelled) {
|
|
|
|
|
GTaskClient.getInstance().commitUpdate();
|
|
|
|
|
refreshLocalSyncId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步文件夹
|
|
|
|
|
private void syncFolder() throws NetworkFailureException {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
String gid;
|
|
|
|
@ -372,7 +361,7 @@ public class GTaskManager {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步根文件夹
|
|
|
|
|
// for root folder
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
Notes.ID_ROOT_FOLDER), SqlNote.PROJECTION_NOTE, null, null, null);
|
|
|
|
@ -384,6 +373,7 @@ public class GTaskManager {
|
|
|
|
|
mGTaskHashMap.remove(gid);
|
|
|
|
|
mGidToNid.put(gid, (long) Notes.ID_ROOT_FOLDER);
|
|
|
|
|
mNidToGid.put((long) Notes.ID_ROOT_FOLDER, gid);
|
|
|
|
|
// for system folder, only update remote name if necessary
|
|
|
|
|
if (!node.getName().equals(
|
|
|
|
|
GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT))
|
|
|
|
|
doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c);
|
|
|
|
@ -400,11 +390,11 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步通话记录文件夹
|
|
|
|
|
// for call-note folder
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE, "(_id=?)",
|
|
|
|
|
new String[] {
|
|
|
|
|
String.valueOf(Notes.ID_CALL_RECORD_FOLDER)
|
|
|
|
|
String.valueOf(Notes.ID_CALL_RECORD_FOLDER)
|
|
|
|
|
}, null);
|
|
|
|
|
if (c != null) {
|
|
|
|
|
if (c.moveToNext()) {
|
|
|
|
@ -414,6 +404,8 @@ public class GTaskManager {
|
|
|
|
|
mGTaskHashMap.remove(gid);
|
|
|
|
|
mGidToNid.put(gid, (long) Notes.ID_CALL_RECORD_FOLDER);
|
|
|
|
|
mNidToGid.put((long) Notes.ID_CALL_RECORD_FOLDER, gid);
|
|
|
|
|
// for system folder, only update remote name if
|
|
|
|
|
// necessary
|
|
|
|
|
if (!node.getName().equals(
|
|
|
|
|
GTaskStringUtils.MIUI_FOLDER_PREFFIX
|
|
|
|
|
+ GTaskStringUtils.FOLDER_CALL_NOTE))
|
|
|
|
@ -432,7 +424,7 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步本地现有文件夹
|
|
|
|
|
// for local existing folders
|
|
|
|
|
try {
|
|
|
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
|
|
|
|
|
"(type=? AND parent_id<>?)", new String[] {
|
|
|
|
@ -449,8 +441,10 @@ public class GTaskManager {
|
|
|
|
|
syncType = node.getSyncAction(c);
|
|
|
|
|
} else {
|
|
|
|
|
if (c.getString(SqlNote.GTASK_ID_COLUMN).trim().length() == 0) {
|
|
|
|
|
// local add
|
|
|
|
|
syncType = Node.SYNC_ACTION_ADD_REMOTE;
|
|
|
|
|
} else {
|
|
|
|
|
// remote delete
|
|
|
|
|
syncType = Node.SYNC_ACTION_DEL_LOCAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -466,7 +460,7 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 同步远程添加的文件夹
|
|
|
|
|
// for remote add folders
|
|
|
|
|
Iterator<Map.Entry<String, TaskList>> iter = mGTaskListHashMap.entrySet().iterator();
|
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
|
Map.Entry<String, TaskList> entry = iter.next();
|
|
|
|
@ -482,7 +476,6 @@ public class GTaskManager {
|
|
|
|
|
GTaskClient.getInstance().commitUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行内容同步操作
|
|
|
|
|
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
@ -517,17 +510,18 @@ public class GTaskManager {
|
|
|
|
|
updateRemoteNode(node, c);
|
|
|
|
|
break;
|
|
|
|
|
case Node.SYNC_ACTION_UPDATE_CONFLICT:
|
|
|
|
|
// merging both modifications maybe a good idea
|
|
|
|
|
// right now just use local update simply
|
|
|
|
|
updateRemoteNode(node, c);
|
|
|
|
|
break;
|
|
|
|
|
case Node.SYNC_ACTION_NONE:
|
|
|
|
|
break;
|
|
|
|
|
case Node.SYNC_ACTION_ERROR:
|
|
|
|
|
default:
|
|
|
|
|
throw new ActionFailureException("unknown sync action type");
|
|
|
|
|
throw new ActionFailureException("unkown sync action type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加本地节点
|
|
|
|
|
private void addLocalNode(Node node) throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
@ -555,6 +549,7 @@ public class GTaskManager {
|
|
|
|
|
if (note.has(NoteColumns.ID)) {
|
|
|
|
|
long id = note.getLong(NoteColumns.ID);
|
|
|
|
|
if (DataUtils.existInNoteDatabase(mContentResolver, id)) {
|
|
|
|
|
// the id is not available, have to create a new one
|
|
|
|
|
note.remove(NoteColumns.ID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -567,6 +562,8 @@ public class GTaskManager {
|
|
|
|
|
if (data.has(DataColumns.ID)) {
|
|
|
|
|
long dataId = data.getLong(DataColumns.ID);
|
|
|
|
|
if (DataUtils.existInDataDatabase(mContentResolver, dataId)) {
|
|
|
|
|
// the data id is not available, have to create
|
|
|
|
|
// a new one
|
|
|
|
|
data.remove(DataColumns.ID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -587,22 +584,26 @@ public class GTaskManager {
|
|
|
|
|
sqlNote.setParentId(parentId.longValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create the local node
|
|
|
|
|
sqlNote.setGtaskId(node.getGid());
|
|
|
|
|
sqlNote.commit(false);
|
|
|
|
|
|
|
|
|
|
// update gid-nid mapping
|
|
|
|
|
mGidToNid.put(node.getGid(), sqlNote.getId());
|
|
|
|
|
mNidToGid.put(sqlNote.getId(), node.getGid());
|
|
|
|
|
|
|
|
|
|
// update meta
|
|
|
|
|
updateRemoteMeta(node.getGid(), sqlNote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新本地节点
|
|
|
|
|
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SqlNote sqlNote = new SqlNote(mContext, c);
|
|
|
|
|
SqlNote sqlNote;
|
|
|
|
|
// update the note locally
|
|
|
|
|
sqlNote = new SqlNote(mContext, c);
|
|
|
|
|
sqlNote.setContent(node.getLocalJSONFromContent());
|
|
|
|
|
|
|
|
|
|
Long parentId = (node instanceof Task) ? mGidToNid.get(((Task) node).getParent().getGid())
|
|
|
|
@ -614,10 +615,10 @@ public class GTaskManager {
|
|
|
|
|
sqlNote.setParentId(parentId.longValue());
|
|
|
|
|
sqlNote.commit(true);
|
|
|
|
|
|
|
|
|
|
// update meta info
|
|
|
|
|
updateRemoteMeta(node.getGid(), sqlNote);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加远程节点
|
|
|
|
|
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
@ -626,6 +627,7 @@ public class GTaskManager {
|
|
|
|
|
SqlNote sqlNote = new SqlNote(mContext, c);
|
|
|
|
|
Node n;
|
|
|
|
|
|
|
|
|
|
// update remotely
|
|
|
|
|
if (sqlNote.isNoteType()) {
|
|
|
|
|
Task task = new Task();
|
|
|
|
|
task.setContentByLocalJSON(sqlNote.getContent());
|
|
|
|
@ -640,10 +642,12 @@ public class GTaskManager {
|
|
|
|
|
GTaskClient.getInstance().createTask(task);
|
|
|
|
|
n = (Node) task;
|
|
|
|
|
|
|
|
|
|
// add meta
|
|
|
|
|
updateRemoteMeta(task.getGid(), sqlNote);
|
|
|
|
|
} else {
|
|
|
|
|
TaskList tasklist = null;
|
|
|
|
|
|
|
|
|
|
// we need to skip folder if it has already existed
|
|
|
|
|
String folderName = GTaskStringUtils.MIUI_FOLDER_PREFFIX;
|
|
|
|
|
if (sqlNote.getId() == Notes.ID_ROOT_FOLDER)
|
|
|
|
|
folderName += GTaskStringUtils.FOLDER_DEFAULT;
|
|
|
|
@ -667,6 +671,7 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no match we can add now
|
|
|
|
|
if (tasklist == null) {
|
|
|
|
|
tasklist = new TaskList();
|
|
|
|
|
tasklist.setContentByLocalJSON(sqlNote.getContent());
|
|
|
|
@ -676,16 +681,17 @@ public class GTaskManager {
|
|
|
|
|
n = (Node) tasklist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update local note
|
|
|
|
|
sqlNote.setGtaskId(n.getGid());
|
|
|
|
|
sqlNote.commit(false);
|
|
|
|
|
sqlNote.resetLocalModified();
|
|
|
|
|
sqlNote.commit(true);
|
|
|
|
|
|
|
|
|
|
// gid-id mapping
|
|
|
|
|
mGidToNid.put(n.getGid(), sqlNote.getId());
|
|
|
|
|
mNidToGid.put(sqlNote.getId(), n.getGid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新远程节点
|
|
|
|
|
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
@ -693,11 +699,14 @@ public class GTaskManager {
|
|
|
|
|
|
|
|
|
|
SqlNote sqlNote = new SqlNote(mContext, c);
|
|
|
|
|
|
|
|
|
|
// update remotely
|
|
|
|
|
node.setContentByLocalJSON(sqlNote.getContent());
|
|
|
|
|
GTaskClient.getInstance().addUpdateNode(node);
|
|
|
|
|
|
|
|
|
|
// update meta
|
|
|
|
|
updateRemoteMeta(node.getGid(), sqlNote);
|
|
|
|
|
|
|
|
|
|
// move task if necessary
|
|
|
|
|
if (sqlNote.isNoteType()) {
|
|
|
|
|
Task task = (Task) node;
|
|
|
|
|
TaskList preParentList = task.getParent();
|
|
|
|
@ -716,11 +725,11 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clear local modified flag
|
|
|
|
|
sqlNote.resetLocalModified();
|
|
|
|
|
sqlNote.commit(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新远程元数据
|
|
|
|
|
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
|
|
|
|
|
if (sqlNote != null && sqlNote.isNoteType()) {
|
|
|
|
|
MetaData metaData = mMetaHashMap.get(gid);
|
|
|
|
@ -737,12 +746,12 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 刷新本地同步ID
|
|
|
|
|
private void refreshLocalSyncId() throws NetworkFailureException {
|
|
|
|
|
if (mCancelled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get the latest gtask list
|
|
|
|
|
mGTaskHashMap.clear();
|
|
|
|
|
mGTaskListHashMap.clear();
|
|
|
|
|
mMetaHashMap.clear();
|
|
|
|
@ -781,13 +790,11 @@ public class GTaskManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取同步账户名称
|
|
|
|
|
public String getSyncAccount() {
|
|
|
|
|
return GTaskClient.getInstance().getSyncAccount().name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取消同步
|
|
|
|
|
public void cancelSync() {
|
|
|
|
|
mCancelled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|