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; }
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); } }
public LongPressMenuListAdapter(HNPost post, int position) { pos = position; mPost = post; mIsLoggedIn = Settings.isUserLoggedIn(MainActivity.this); mUpVotingEnabled = !mIsLoggedIn || (mPost.getUpvoteURL(Settings.getUserName(MainActivity.this)) != null && !mUpvotedPosts.contains(mPost)); mItems = new ArrayList<CharSequence>(); if (mUpVotingEnabled) mItems.add(getString(R.string.upvote)); else mItems.add(getString(R.string.already_upvoted)); mItems.addAll( Arrays.asList( getString(R.string.pref_htmlprovider_original_url), getString(R.string.pref_htmlprovider_viewtext), getString(R.string.pref_htmlprovider_google), getString(R.string.pref_htmlprovider_instapaper), getString(R.string.external_browser))); }
@Override public void onClick(DialogInterface dialog, int item) { switch (item) { case 0: if (!mIsLoggedIn) Toast.makeText(MainActivity.this, R.string.please_log_in, Toast.LENGTH_LONG).show(); else if (mUpVotingEnabled) vote(mPost.getUpvoteURL(Settings.getUserName(MainActivity.this)), mPost); break; case 1: case 2: case 3: case 4: openPostInApp(pos, mPost, getItem(item).toString(), MainActivity.this); break; case 5: openURLInBrowser(getArticleViewURL(mPost), MainActivity.this); break; default: break; } }
@Override public View getView(final int position, View convertView, ViewGroup parent) { switch (getItemViewType(position)) { case VIEWTYPE_POST: if (convertView == null) { convertView = (LinearLayout) mInflater.inflate(R.layout.main_list_item, null); PostViewHolder holder = new PostViewHolder(); holder.titleView = (TextView) convertView.findViewById(R.id.main_list_item_title); holder.contentView = (TextView) convertView.findViewById(R.id.main_list_item_content); holder.urlView = (TextView) convertView.findViewById(R.id.main_list_item_url); holder.textContainer = (LinearLayout) convertView.findViewById(R.id.main_list_item_textcontainer); holder.commentsButton = (Button) convertView.findViewById(R.id.main_list_item_comments_button); holder.commentsButton.setTypeface(FontHelper.getComfortaa(MainActivity.this, false)); holder.commentsContainer = (LinearLayout) convertView.findViewById(R.id.main_list_item_comments_container); // ramesh holder.pointsView = (TextView) convertView.findViewById(R.id.main_list_item_points); holder.pointsView.setTypeface(FontHelper.getComfortaa(MainActivity.this, true)); convertView.setTag(holder); } HNPost item = getItem(position); PostViewHolder holder = (PostViewHolder) convertView.getTag(); holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizeTitle); holder.titleView.setText(item.getTitle()); holder.contentView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizeDetails); holder.contentView.setText(item.getContent()); holder.urlView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizeDetails); holder.urlView.setText(item.getURLDomain()); holder.pointsView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizeDetails); holder.textContainer.setBackgroundColor( mColorDetails); // Ramesh kumar coding part for change background color using radio // button holder.commentsContainer.setBackgroundColor(mColorDetails); if (item.getPoints() != BaseHTMLParser.UNDEFINED) holder.pointsView.setText(item.getPoints() + ""); else holder.pointsView.setText("-"); holder.commentsButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizeTitle); if (item.getCommentsCount() != BaseHTMLParser.UNDEFINED) { holder.commentsButton.setVisibility(View.VISIBLE); holder.commentsButton.setText(item.getCommentsCount() + ""); } else holder.commentsButton.setVisibility(View.INVISIBLE); holder.commentsButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { Intent i = new Intent(MainActivity.this, CommentsActivity_.class); i.putExtra(CommentsActivity.EXTRA_HNPOST, getItem(position)); startActivity(i); } }); holder.textContainer.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (Settings.getHtmlViewer(MainActivity.this) .equals(getString(R.string.pref_htmlviewer_browser))) openURLInBrowser(getArticleViewURL(getItem(position)), MainActivity.this); else openPostInApp(position, getItem(position), null, MainActivity.this); } }); holder.textContainer.setOnLongClickListener( new OnLongClickListener() { public boolean onLongClick(View v) { System.out.println("onLongClick"); if (!startSlide) { longClick = true; final HNPost post = getItem(position); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); LongPressMenuListAdapter adapter = new LongPressMenuListAdapter(post, position); builder.setAdapter(adapter, adapter).show(); return true; } return false; } }); break; case VIEWTYPE_LOADMORE: // I don't use the preloaded convertView here because it's // only one cell convertView = (FrameLayout) mInflater.inflate(R.layout.main_list_item_loadmore, null); final TextView textView = (TextView) convertView.findViewById(R.id.main_list_item_loadmore_text); textView.setTypeface(FontHelper.getComfortaa(MainActivity.this, true)); final ImageView imageView = (ImageView) convertView.findViewById(R.id.main_list_item_loadmore_loadingimage); if (HNFeedTaskLoadMore.isRunning(MainActivity.this, TASKCODE_LOAD_MORE_POSTS)) { textView.setVisibility(View.INVISIBLE); imageView.setVisibility(View.VISIBLE); convertView.setClickable(false); } final View convertViewFinal = convertView; convertView.setOnClickListener( new OnClickListener() { public void onClick(View v) { textView.setVisibility(View.INVISIBLE); imageView.setVisibility(View.VISIBLE); convertViewFinal.setClickable(false); HNFeedTaskLoadMore.start( MainActivity.this, MainActivity.this, mFeed, TASKCODE_LOAD_MORE_POSTS); } }); break; default: break; } return convertView; }