Example #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", " ", " "));
    }
  }
Example #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();
    }
  }
Example #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();
    }
  }
Example #4
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", " ", " "));
    }
  }
Example #5
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();
    }
  }
Example #6
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    int position = getArguments().getInt("position");
    // Log.d(TAG, "position: " + position);

    String[] list_item = getResources().getStringArray(R.array.list_item);
    // String[] list_item = diigoUtil.addAllTagsToDrawerList();

    // 读取Tag 列表
    if (position == 6) {
      rootView = inflater.inflate(R.layout.fragment_all_bookmarks, container, false);
      allTagsListView = (ListView) rootView.findViewById(R.id.content_list_view);

      allTagsList = new ArrayList<DiigoBookMarks>();
      singleTagsList = new ArrayList<String>();

      singleTagsList = diigoUtil.getTagToPreference();
      singleTagsList = InputUtil.compareTagsList(singleTagsList);
      // allTagsList = new ArrayList<String>();
      allTagsAdapter = new ArrayAdapter(mCtx, R.layout.drawer_list, singleTagsList);
      allTagsListView.setAdapter(allTagsAdapter);

      allTagsListView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

              TagsListFragment tagsListFragment =
                  new TagsListFragment(mCtx.getApplicationContext());
              List<String> list = singleTagsList;

              String[] tags = new String[list.size()];
              for (int i = 0; i < list.size(); i++) {
                tags[i] = list.get(i);
              }

              Bundle data = new Bundle();
              data.putInt("position", position);
              data.putStringArray("tagsList", tags);

              tagsListFragment.setArguments(data);
              Log.d(TAG, "singleTagsList: " + list.toString());

              FragmentManager fManager = getFragmentManager();
              fManager.beginTransaction().replace(R.id.content_frame, tagsListFragment).commit();

              Toast.makeText(mCtx, "Tags is onItemClick" + tags[position], Toast.LENGTH_SHORT)
                  .show();
            }
          });

    } else {
      rootView = inflater.inflate(R.layout.fragment_all_bookmarks, container, false);
      // 如果点击的是All Bookmarks 则跳转掉另一个Fragment

      marksListView = (ListView) rootView.findViewById(R.id.content_list_view);

      marksList = new ArrayList<DiigoBookMarks>();

      marksAdapter = new CustomListAdapter(mCtx.getApplicationContext(), marksList);
      marksListView.setAdapter(marksAdapter);

      if (!DiigoUtil.cacheIsNull(DiigoUtil.DIIGO_BOOKMARKS)) {

        switch (position) {
            // public marks,filter=public
          case 0:
            readPublicMarks();
            break;
            // private marks,filter=private
          case 1:
            // marks.setFilter("private");
            readPrivateMarks();
            break;
            // ReadLater 需要遍历,JsonArray[i].getString(“readlater").equals("yes")
          case 2:
            readLaterMarks();
            break;
            // Recent Add,sort=2,updated_at
          case 3:
            // marks.setSort("2");
            // updated_at
            readRecentAddMarks();
            break;
            // No Sync,未同步的,本地缓存的,从文件读取
          case 4:
            // marksAdapter.add(new DiigoBookMarks("No Not Sync", " ", " "));
            readCacheMarks();
            break;
            // All marks,filter=all/*
          case 5:
            // marks.setFilter("all");
            readAllMarks();
            break;
            // All Tags,遍历并排序
          case 6:
            break;
          default:
            break;
        }
      } else {
        marksAdapter.add(new DiigoBookMarks("No Sync", " ", " "));
      }

      marksListView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

              // DiigoBookMarks marks = marksList.get(position);
              // 需要将数据传递到下一个Activity 中(getItem(position))
              Bundle bundle = diigoUtil.getBundleByMarks(marksAdapter.getItem(position));
              Intent intent = new Intent();

              intent.putExtras(bundle);
              intent.setClass(getActivity(), DetailActivity.class);
              startActivity(intent);
            }
          });
    }
    return rootView;
  }