ZhengLiJie_branch
zlj 3 months ago
parent 0cde5fa75e
commit 94767859bc

@ -24,7 +24,15 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
/**
* MetaData Google Tasks
* Task GIDGoogle ID
*
*
* - Google Task GID
* - JSON
* - JSON GID
*/
public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName();

@ -28,7 +28,16 @@ import net.micode.notes.R;
import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* GTaskASyncTask AsyncTask
* Google Tasks
*
*
* - Google Tasks
* - /
* -
* -
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;

@ -60,7 +60,16 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/**
* GTaskClient Google Tasks
* Google Tasks API HTTP
*
*
* - Google Token
* - Google Tasks HTTP GET/POST
* - JSON
* -
*/
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();

@ -48,17 +48,36 @@ import java.util.Iterator;
import java.util.Map;
/**
* GTaskManager Google Google Tasks
*
*/
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;
@ -87,6 +106,9 @@ public class GTaskManager {
private HashMap<Long, String> mNidToGid;
/**
*
*/
private GTaskManager() {
mSyncing = false;
mCancelled = false;
@ -99,6 +121,10 @@ public class GTaskManager {
mNidToGid = new HashMap<Long, String>();
}
/**
* GTaskManager
* @return GTaskManager
*/
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
@ -106,11 +132,20 @@ public class GTaskManager {
return mInstance;
}
/**
*
* @param activity
*/
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
/**
* Google
* @param context
* @param asyncTask
* @return
*/
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
Log.d(TAG, "Sync is in progress");
@ -168,6 +203,10 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/**
* Google
* @throws NetworkFailureException
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
@ -247,6 +286,10 @@ public class GTaskManager {
}
}
/**
* Google
* @throws NetworkFailureException
*/
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;
@ -351,6 +394,10 @@ public class GTaskManager {
}
/**
*
* @throws NetworkFailureException
*/
private void syncFolder() throws NetworkFailureException {
Cursor c = null;
String gid;
@ -476,6 +523,13 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate();
}
/**
*
* @param syncType Node SYNC_ACTION
* @param node Google
* @param c
* @throws NetworkFailureException
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -522,6 +576,11 @@ public class GTaskManager {
}
}
/**
*
* @param node
* @throws NetworkFailureException
*/
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@ -596,6 +655,12 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
*
* @param node
* @param c
* @throws NetworkFailureException
*/
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -619,6 +684,12 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
*
* @param node
* @param c
* @throws NetworkFailureException
*/
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -692,6 +763,12 @@ public class GTaskManager {
mNidToGid.put(sqlNote.getId(), n.getGid());
}
/**
*
* @param node
* @param c
* @throws NetworkFailureException
*/
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -730,6 +807,12 @@ public class GTaskManager {
sqlNote.commit(true);
}
/**
*
* @param gid Google ID
* @param sqlNote
* @throws NetworkFailureException
*/
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@ -746,6 +829,10 @@ public class GTaskManager {
}
}
/**
* ID
* @throws NetworkFailureException
*/
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
@ -790,10 +877,17 @@ public class GTaskManager {
}
}
/**
*
* @return
*/
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
/**
*
*/
public void cancelSync() {
mCancelled = true;
}

@ -23,6 +23,16 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
/**
* GTaskSyncService Android Service Google Tasks
* 广 Intent Activity
*
*
* - GTaskASyncTask /
* -
* - 广 UI
* -
*/
public class GTaskSyncService extends Service {
public final static String ACTION_STRING_NAME = "sync_action_type";

Loading…
Cancel
Save