You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
5.2 KiB
130 lines
5.2 KiB
/**
|
|
* 功能:
|
|
* @author TTS
|
|
* @throws NetworkFailureException
|
|
*/
|
|
private void syncFolder() throws NetworkFailureException {
|
|
Cursor c = null;
|
|
String gid;
|
|
Node node;
|
|
int syncType;
|
|
|
|
if (mCancelled) {
|
|
return;
|
|
}
|
|
|
|
// for root folder
|
|
try {
|
|
c = mContentResolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI,
|
|
Notes.ID_ROOT_FOLDER), SqlNote.PROJECTION_NOTE, null, null, null);
|
|
if (c != null) {
|
|
c.moveToNext();
|
|
gid = c.getString(SqlNote.GTASK_ID_COLUMN);
|
|
node = mGTaskHashMap.get(gid);
|
|
if (node != null) {
|
|
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);
|
|
} else {
|
|
doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c);
|
|
}
|
|
} else {
|
|
Log.w(TAG, "failed to query root folder"); //查询根文件夹失败
|
|
}
|
|
} finally {
|
|
if (c != null) {
|
|
c.close();
|
|
c = null;
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}, null);
|
|
if (c != null) {
|
|
if (c.moveToNext()) {
|
|
gid = c.getString(SqlNote.GTASK_ID_COLUMN);
|
|
node = mGTaskHashMap.get(gid);
|
|
if (node != null) {
|
|
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))
|
|
doContentSync(Node.SYNC_ACTION_UPDATE_REMOTE, node, c);
|
|
} else {
|
|
doContentSync(Node.SYNC_ACTION_ADD_REMOTE, node, c);
|
|
}
|
|
}
|
|
} else {
|
|
Log.w(TAG, "failed to query call note folder"); //查询失败
|
|
}
|
|
} finally {
|
|
if (c != null) {
|
|
c.close();
|
|
c = null;
|
|
}
|
|
}
|
|
|
|
// for local existing folders //对本地已存在
|
|
try {
|
|
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
|
|
"(type=? AND parent_id<>?)", new String[] {
|
|
String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)
|
|
}, NoteColumns.TYPE + " DESC");
|
|
if (c != null) {
|
|
while (c.moveToNext()) {
|
|
gid = c.getString(SqlNote.GTASK_ID_COLUMN);
|
|
node = mGTaskHashMap.get(gid);
|
|
if (node != null) {
|
|
mGTaskHashMap.remove(gid);
|
|
mGidToNid.put(gid, c.getLong(SqlNote.ID_COLUMN));
|
|
mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid);
|
|
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;
|
|
}
|
|
}
|
|
doContentSync(syncType, node, c);
|
|
}
|
|
} else {
|
|
Log.w(TAG, "failed to query existing folder");
|
|
}
|
|
} finally {
|
|
if (c != null) {
|
|
c.close();
|
|
c = null;
|
|
}
|
|
}
|
|
|
|
// for remote add folders //用于添加远程文件夹
|
|
Iterator<Map.Entry<String, TaskList>> iter = mGTaskListHashMap.entrySet().iterator();
|
|
while (iter.hasNext()) {
|
|
Map.Entry<String, TaskList> entry = iter.next();
|
|
gid = entry.getKey();
|
|
node = entry.getValue();
|
|
if (mGTaskHashMap.containsKey(gid)) {
|
|
mGTaskHashMap.remove(gid);
|
|
doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
|
|
}
|
|
}
|
|
|
|
if (!mCancelled)
|
|
GTaskClient.getInstance().commitUpdate();
|
|
}
|