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", " ", " ")); } }
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(); } }
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(); } }
/** 如果网络没有连接,则添加书签到本地文件 */ 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();*/ }
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", " ", " ")); } }
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(); } }
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(); } }
@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; }