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 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; }