Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
 private void initFavoritePosts() {
   fFeed = getSharedPreferences("DATA", 0);
   String storeJSON = fFeed.getString("postData", "");
   favoritePosts = new HNFeed(new ArrayList<HNPost>(), null, "");
   if (storeJSON.length() > 0) {
     try {
       postJsonArray = new JSONArray(storeJSON);
       for (int n = 0; n < postJsonArray.length(); n++) {
         JSONObject temp = postJsonArray.getJSONObject(n);
         favoritePosts.addPost(
             new HNPost(
                 temp.getString("url"),
                 temp.getString("title"),
                 temp.getString("urlDomain"),
                 temp.getString("author"),
                 temp.getString("postID"),
                 temp.getInt("commentsCount"),
                 temp.getInt("points"),
                 null));
       }
     } catch (JSONException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 3
0
 @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);
   }
 }
Ejemplo n.º 4
0
    protected void onPostExecute(HNFeed result) {
      if (progress != null && progress.isShowing()) progress.dismiss();

      if (result != null
          && result.getUserAcquiredFor() != null
          && result.getUserAcquiredFor().equals(Settings.getUserName(App.getInstance())))
        showFeed(result);
    }
Ejemplo n.º 5
0
        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);
          }
        }
Ejemplo n.º 6
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;
  }
Ejemplo n.º 7
0
  @Override
  public void onTaskFinished(int taskCode, TaskResultCode code, HNFeed result, Object tag) {
    if (taskCode == TASKCODE_LOAD_FEED) {
      if (code.equals(TaskResultCode.Success) && mPostsListAdapter != null) {
        showFeed(result);
      } else if (!code.equals(TaskResultCode.Success))
        Toast.makeText(this, getString(R.string.error_unable_to_retrieve_feed), Toast.LENGTH_SHORT)
            .show();

      mActionbarRefreshProgress.setVisibility(View.GONE);
      mActionbarRefresh.setVisibility(View.VISIBLE);
    } else if (taskCode == TASKCODE_LOAD_MORE_POSTS) {
      if (!code.equals(TaskResultCode.Success))
        Toast.makeText(this, getString(R.string.error_unable_to_load_more), Toast.LENGTH_SHORT)
            .show();

      mFeed.appendLoadMoreFeed(result);
      mPostsListAdapter.notifyDataSetChanged();
    }
  }
Ejemplo n.º 8
0
 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;
 }