Search in sources :

Example 1 with MetaData

use of net.micode.notes.gtask.data.MetaData in project Notes by MiCode.

the class GTaskManager method initGTaskList.

private void initGTaskList() throws NetworkFailureException {
    if (mCancelled)
        return;
    GTaskClient client = GTaskClient.getInstance();
    try {
        JSONArray jsTaskLists = client.getTaskLists();
        // init meta list first
        mMetaList = null;
        for (int i = 0; i < jsTaskLists.length(); i++) {
            JSONObject object = jsTaskLists.getJSONObject(i);
            String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
            String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
            if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) {
                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);
                    MetaData metaData = new MetaData();
                    metaData.setContentByRemoteJSON(object);
                    if (metaData.isWorthSaving()) {
                        mMetaList.addChildTask(metaData);
                        if (metaData.getGid() != null) {
                            mMetaHashMap.put(metaData.getRelatedGid(), metaData);
                        }
                    }
                }
            }
        }
        // create meta list if not existed
        if (mMetaList == null) {
            mMetaList = new TaskList();
            mMetaList.setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META);
            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);
            String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
            if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX) && !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + 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);
                    gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
                    Task task = new Task();
                    task.setContentByRemoteJSON(object);
                    if (task.isWorthSaving()) {
                        task.setMetaInfo(mMetaHashMap.get(gid));
                        tasklist.addChildTask(task);
                        mGTaskHashMap.put(gid, task);
                    }
                }
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new ActionFailureException("initGTaskList: handing JSONObject failed");
    }
}
Also used : Task(net.micode.notes.gtask.data.Task) ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) JSONObject(org.json.JSONObject) MetaData(net.micode.notes.gtask.data.MetaData) TaskList(net.micode.notes.gtask.data.TaskList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 2 with MetaData

use of net.micode.notes.gtask.data.MetaData in project Notes by MiCode.

the class GTaskManager method doContentSync.

private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
    if (mCancelled) {
        return;
    }
    MetaData meta;
    switch(syncType) {
        case Node.SYNC_ACTION_ADD_LOCAL:
            addLocalNode(node);
            break;
        case Node.SYNC_ACTION_ADD_REMOTE:
            addRemoteNode(node, c);
            break;
        case Node.SYNC_ACTION_DEL_LOCAL:
            meta = mMetaHashMap.get(c.getString(SqlNote.GTASK_ID_COLUMN));
            if (meta != null) {
                GTaskClient.getInstance().deleteNode(meta);
            }
            mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN));
            break;
        case Node.SYNC_ACTION_DEL_REMOTE:
            meta = mMetaHashMap.get(node.getGid());
            if (meta != null) {
                GTaskClient.getInstance().deleteNode(meta);
            }
            GTaskClient.getInstance().deleteNode(node);
            break;
        case Node.SYNC_ACTION_UPDATE_LOCAL:
            updateLocalNode(node, c);
            break;
        case Node.SYNC_ACTION_UPDATE_REMOTE:
            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("unkown sync action type");
    }
}
Also used : ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) MetaData(net.micode.notes.gtask.data.MetaData)

Example 3 with MetaData

use of net.micode.notes.gtask.data.MetaData in project Notes by MiCode.

the class GTaskManager method updateRemoteMeta.

private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
    if (sqlNote != null && sqlNote.isNoteType()) {
        MetaData metaData = mMetaHashMap.get(gid);
        if (metaData != null) {
            metaData.setMeta(gid, sqlNote.getContent());
            GTaskClient.getInstance().addUpdateNode(metaData);
        } else {
            metaData = new MetaData();
            metaData.setMeta(gid, sqlNote.getContent());
            mMetaList.addChildTask(metaData);
            mMetaHashMap.put(gid, metaData);
            GTaskClient.getInstance().createTask(metaData);
        }
    }
}
Also used : MetaData(net.micode.notes.gtask.data.MetaData)

Aggregations

MetaData (net.micode.notes.gtask.data.MetaData)3 ActionFailureException (net.micode.notes.gtask.exception.ActionFailureException)2 Task (net.micode.notes.gtask.data.Task)1 TaskList (net.micode.notes.gtask.data.TaskList)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1