示例#1
0
  private void readPublicMarks() {
    Log.d(TAG, "readPublicMarks Method");
    // marks.setFilter("public");

    if (!DiigoUtil.cacheIsNull(DiigoUtil.DIIGO_BOOKMARKS)) {
      String allMarks = DiigoUtil.readMarksFromFile();

      // 根据Tag,返回遍历后的JsonArr
      JSONArray meJsonArr = new JSONArray();

      JSONArray response = null;
      try {
        response = new JSONArray(allMarks);
        Log.d(TAG, "response Size: " + response.length());
        for (int i = 0; i < response.length(); i++) {

          JSONObject jsonObject = (JSONObject) response.get(i);
          String shared = jsonObject.getString("shared");
          if ("yes".equals(shared)) {
            meJsonArr.put(jsonObject);
          }
        }
        List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(meJsonArr);
        for (DiigoBookMarks mark : markses) {
          marksAdapter.add(mark);
        }
        Log.d(TAG, "readMarksFromFile  Size: " + meJsonArr.length());
      } catch (JSONException e) {
        e.printStackTrace();
      }
    } else {
      marksAdapter.add(new DiigoBookMarks("No Not Sync", " ", " "));
    }
  }
示例#2
0
  private void readPrivateMarks() {
    Log.d(TAG, "readPrivateMarks Method");

    String allMarks = DiigoUtil.readMarksFromFile();

    // 根据Tag,返回遍历后的JsonArr
    JSONArray meJsonArr = new JSONArray();

    JSONArray response = null;
    try {
      response = new JSONArray(allMarks);
      Log.d(TAG, "response Size: " + response.length());
      for (int i = 0; i < response.length(); i++) {

        JSONObject jsonObject = (JSONObject) response.get(i);
        String shared = jsonObject.getString("shared");
        Log.d(TAG, "shared: " + shared);
        if ("no".equals(shared)) {
          meJsonArr.put(jsonObject);
        }
      }
      List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(meJsonArr);
      for (DiigoBookMarks mark : markses) {
        marksAdapter.add(mark);
      }
      Log.d(TAG, "meJsonArr Size: " + meJsonArr.length());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
示例#3
0
  private void readAllMarks() {
    Log.d(TAG, "readAllMarks  Method");

    String allMarks = DiigoUtil.readMarksFromFile();

    // 根据Tag,返回遍历后的JsonArr
    // JSONArray meJsonArr = new JSONArray();

    JSONArray response = null;
    try {
      response = new JSONArray(allMarks);
      Log.d(TAG, "response Size: " + response.length());
      Log.d(TAG, "AllMarks: " + allMarks);

      List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(response);
      //
      // marksList = markses;
      for (DiigoBookMarks mark : markses) {
        marksAdapter.add(mark);
      }
      Log.d(TAG, "readAllMarks meJsonArr Size: " + response.length());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
示例#4
0
  /** 如果网络没有连接,则添加书签到本地文件 */
  private void onAddMarksToFile() {
    String allCacheMarks = null;

    // 将每条数据封装成JsonObj,存入JsonArr
    JSONArray allCacheJsonArr = new JSONArray();

    // 先将文件有的数据读取出来,然后在写入
    String cacheDdata = DiigoUtil.readMarksFromFile(DiigoUtil.CACHE_MARKS_FILES);
    if (cacheDdata != null) {
      try {
        JSONArray cacheJsonArr = new JSONArray(cacheDdata);
        for (int i = 0; i < cacheJsonArr.length(); i++) {
          JSONObject cacheJsonObj = (JSONObject) cacheJsonArr.get(i);
          allCacheJsonArr.put(cacheJsonObj);
          Log.d(TAG, "allCacheJsonArr put readFile: " + cacheJsonObj.toString());
        }
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    marks = new DiigoBookMarks();
    marks.setUrl(getViewString(addUrlEt));
    marks.setTitle(getViewString(addTitleEt));
    marks.setTags(getViewString(tagsAutoTv));
    marks.setDesc(getViewString(addDescEt));
    marks.setShared(getViewString(addSharedBox));
    marks.setReadLater(getViewString(addReadLaterBox));

    JSONObject singleMarks = marksToJson(marks);
    allCacheJsonArr.put(singleMarks);
    Log.d(TAG, "allCacheJsonArr put add: " + singleMarks.toString());

    allCacheMarks = allCacheJsonArr.toString();
    DiigoUtil.writeMarksToFile(allCacheMarks, DiigoUtil.CACHE_MARKS_FILES);

    // 添加成功,返回主页
    /*Intent intent = new Intent(getBaseContext(), MainActivity.class);
    startActivity(intent);
    Toast.makeText(this, "add Cache Marks Sucessful", Toast.LENGTH_SHORT).show();*/
  }
示例#5
0
  public void officeGetMarks(DiigoBookMarks marks) {
    String allMarks = DiigoUtil.readMarksFromFile();

    // 传入的Tag
    String meTag = marks.getTags();
    // 根据Tag,返回遍历后的JsonArr
    JSONArray meJsonArr = new JSONArray();

    JSONArray response = null;
    try {
      response = new JSONArray(allMarks);
      Log.d(TAG, "response Size: " + response.length());
      for (int i = 0; i < response.length(); i++) {

        JSONObject jsonObject = (JSONObject) response.get(i);
        Log.d(TAG, "jsonObject: " + jsonObject);
        String tags = jsonObject.getString("tags");
        String[] tag = tags.split(",");
        for (String s : tag) {

          if (meTag.equals(s)) {
            Log.d(TAG, "meTag: " + meTag + "; s: " + s.toLowerCase());

            // meJsonArr.put(response.getJSONObject(i));
            meJsonArr.put(jsonObject);
          }
        }
      }

      List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(meJsonArr);
      for (DiigoBookMarks mark : markses) {
        allTagsAdapter.add(mark);
        // allTagsAdapter.add(mark);

      }
      Log.d(TAG, "meJsonArr Size: " + meJsonArr.length());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
示例#6
0
  private void readRecentAddMarks() {

    Log.d(TAG, "readRecentAddMarks Method");

    String curDate = InputUtil.getNowDate();
    String allMarks = DiigoUtil.readMarksFromFile();

    // 根据Tag,返回遍历后的JsonArr
    JSONArray meJsonArr = new JSONArray();

    JSONArray response = null;
    try {
      response = new JSONArray(allMarks);
      Log.d(TAG, "response Size: " + response.length());
      for (int i = 0; i < response.length(); i++) {

        JSONObject jsonObject = (JSONObject) response.get(i);
        String recentUpdate = jsonObject.getString("updated_at");
        String subDate = recentUpdate.substring(0, 19);
        // Log.d(TAG, "recent Add: " + recentUpdate + "subDate: " + subDate);
        Log.d(TAG, "curDate: " + curDate + "; marksDate: " + subDate);

        int dateInt = curDate.compareTo(subDate);
        Log.d(TAG, "datInt" + dateInt);
        if (dateInt < 0) {
          meJsonArr.put(jsonObject);
        }
      }
      List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(meJsonArr);
      for (DiigoBookMarks mark : markses) {
        marksAdapter.add(mark);
        // 将获取的数据,复制给全局的DigoBookmarks 对象,传递到下一个Activity 中
        // this.marks = mark;
      }
      Log.d(TAG, "meJsonArr Size: " + meJsonArr.length());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
示例#7
0
  private void readCacheMarks() {

    if (!DiigoUtil.cacheIsNull(DiigoUtil.CACHE_MARKS_FILES)) {
      String cacheAllMarks = DiigoUtil.readMarksFromFile(DiigoUtil.CACHE_MARKS_FILES);
      JSONArray response = null;
      try {
        response = new JSONArray(cacheAllMarks);
        Log.d(TAG, "response Size: " + response.length());
        Log.d(TAG, "AllMarks: " + cacheAllMarks);

        List<DiigoBookMarks> markses = DiigoBookMarks.fromJson(response);
        for (DiigoBookMarks mark : markses) {
          marksAdapter.add(mark);
        }
        Log.d(TAG, "readAllMarks meJsonArr Size: " + response.length());
      } catch (JSONException e) {
        e.printStackTrace();
      }
    } else {
      marksAdapter.add(new DiigoBookMarks("No Not Sync", " ", " "));
    }
  }