public boolean addFavoritePost(int nPost) { fFeed = getSharedPreferences("DATA", 0); if (postJsonArray == null) { postJsonArray = new JSONArray(); } HNPost temp = mFeed.getPosts().get(nPost); if (!isPostinFavorite(temp.getURL())) { // New hnPOST JSONObject jsonObject = new JSONObject(); try { jsonObject.put("url", temp.getURL()); jsonObject.put("title", temp.getTitle()); jsonObject.put("urlDomain", temp.getURLDomain()); jsonObject.put("author", temp.getAuthor()); jsonObject.put("postID", temp.getPostID()); jsonObject.put("commentsCount", temp.getCommentsCount()); jsonObject.put("points", temp.getPoints()); jsonObject.put("upvoteURL", null); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // put in jsonArray postJsonArray.put(jsonObject); fFeed.edit().putString("postData", postJsonArray.toString()).commit(); favoritePosts.addPost(temp); return true; } return false; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == NEXTPAGE && resultCode == RESULT_OK) { int position = (int) data.getIntExtra(ARTICAL_POSITION, -1); HNPost post = mFeed.getPosts().get(position); openPostInApp(position, post, null, MainActivity.this); } }
public void run() { List<HNPost> mPosts = mFeed.getPosts(); HNFeedParser parser = new HNFeedParser(); for (int i = 0; i < mPosts.size(); i++) { HNPost post = mPosts.get(i); post.setContent(parser.getURLContent(post.getURL())); getURLContent_ThreadHandler.sendEmptyMessage(0); } }
@Override protected void onResume() { super.onResume(); boolean registeredUserChanged = mFeed.getUserAcquiredFor() != null && (!mFeed.getUserAcquiredFor().equals(Settings.getUserName(this))); // We want to reload the feed if a new user logged in if (HNCredentials.isInvalidated() || registeredUserChanged) { showFeed(new HNFeed(new ArrayList<HNPost>(), null, "")); startFeedLoading(); } // refresh if font size changed if (refreshFontSizes()) mPostsListAdapter.notifyDataSetChanged(); // Ramesh kumar coding part for change background color using radio button if (refreshBackgroundColor()) mPostsListAdapter.notifyDataSetChanged(); // ------------- kevin's codes. refresh the setup when changing the setting ----------------- if (refreshHTMLContent()) { if (mCurrentHTMLContent.equals("display")) { new Thread(getURLContent_Thread).start(); } else { List<HNPost> mPosts = mFeed.getPosts(); for (int i = 0; i < mPosts.size(); i++) { mPosts.get(i).setContent(""); } showFeed(mFeed); } } // restore vertical scrolling position if applicable if (mListState != null) mPostsList.onRestoreInstanceState(mListState); mListState = null; }
public boolean isPostinFavorite(String postUrl) { for (int p = 0; p < favoritePosts.getPosts().size(); p++) { if (favoritePosts.getPosts().get(p).getURL().equals(postUrl)) return true; } return false; }