Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
bingdawan | 789035a99b | 8 months ago |
bingdawan | b873c5a665 | 8 months ago |
bingdawan | 8b91dc857d | 8 months ago |
bingdawan | e4cc105b96 | 8 months ago |
bingdawan | 0254ddc1cb | 8 months ago |
bingdawan | 5aa1274c51 | 8 months ago |
bingdawan | 6317399023 | 8 months ago |
bingdawan | 3e8c9bfec8 | 8 months ago |
bingdawan | a8dc1afe98 | 8 months ago |
bingdawan | 2756f5540e | 9 months ago |
bingdawan | faa7f73773 | 9 months ago |
Binary file not shown.
@ -0,0 +1,109 @@
|
||||
/**
|
||||
* 功能:本地内容同步操作
|
||||
* @throws NetworkFailureException
|
||||
* @return 无返回值
|
||||
*/
|
||||
private void syncContent() throws NetworkFailureException { //本地内容同步操作
|
||||
int syncType;
|
||||
Cursor c = null; //数据库指针
|
||||
String gid; //GoogleID
|
||||
Node node; //Node包含Sync_Action的不同类型
|
||||
|
||||
mLocalDeleteIdMap.clear(); //HashSet<Long>类型
|
||||
|
||||
if (mCancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for local deleted note
|
||||
try {
|
||||
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, SqlNote.PROJECTION_NOTE,
|
||||
"(type<>? AND parent_id=?)", new String[] {
|
||||
String.valueOf(Notes.TYPE_SYSTEM), String.valueOf(Notes.ID_TRASH_FOLER)
|
||||
}, null);
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
gid = c.getString(SqlNote.GTASK_ID_COLUMN);
|
||||
node = mGTaskHashMap.get(gid);
|
||||
if (node != null) {
|
||||
mGTaskHashMap.remove(gid);
|
||||
doContentSync(Node.SYNC_ACTION_DEL_REMOTE, node, c);
|
||||
}
|
||||
|
||||
mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN));
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "failed to query trash folder");
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
c = null;
|
||||
}
|
||||
}
|
||||
|
||||
// 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[] {
|
||||
String.valueOf(Notes.TYPE_NOTE), 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)); //通过hashmap建立联系
|
||||
mNidToGid.put(c.getLong(SqlNote.ID_COLUMN), gid); //通过hashmap建立联系
|
||||
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 note in database");
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
c = null;
|
||||
}
|
||||
}
|
||||
|
||||
// go through remaining items
|
||||
Iterator<Map.Entry<String, Node>> iter = mGTaskHashMap.entrySet().iterator(); //Iterator迭代器
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, Node> entry = iter.next();
|
||||
node = entry.getValue();
|
||||
doContentSync(Node.SYNC_ACTION_ADD_LOCAL, node, null);
|
||||
}
|
||||
|
||||
// mCancelled can be set by another thread, so we neet to check one by //thread----线程
|
||||
// one
|
||||
// clear local delete table
|
||||
if (!mCancelled) {
|
||||
if (!DataUtils.batchDeleteNotes(mContentResolver, mLocalDeleteIdMap)) {
|
||||
throw new ActionFailureException("failed to batch-delete local deleted notes");
|
||||
}
|
||||
}
|
||||
|
||||
// refresh local sync id
|
||||
if (!mCancelled) {
|
||||
GTaskClient.getInstance().commitUpdate();
|
||||
refreshLocalSyncId();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
/**
|
||||
* 功能:
|
||||
* @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();
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
demo
|
Loading…
Reference in new issue