Skip to content

Suggest update to ArticleListAdapter #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 43 additions & 28 deletions src/com/nerdability/android/adapter/ArticleListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,59 @@


public class ArticleListAdapter extends ArrayAdapter<Article> {


private Activity myContext;

public ArticleListAdapter(Activity activity, List<Article> articles) {
super(activity, 0, articles);
myContext = activity;
}


static class ViewHolder{
TextView textView, dateView;
LinearLayout row;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Activity activity = (Activity) getContext();
LayoutInflater inflater = activity.getLayoutInflater();

View rowView = inflater.inflate(R.layout.fragment_article_list, null);
Article article = getItem(position);
ViewHolder viewHolder;


TextView textView = (TextView) rowView.findViewById(R.id.article_title_text);
textView.setText(article.getTitle());

TextView dateView = (TextView) rowView.findViewById(R.id.article_listing_smallprint);
String pubDate = article.getPubDate();
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss Z", Locale.ENGLISH);
Date pDate;
try {
pDate = df.parse(pubDate);
pubDate = "published " + DateUtils.getDateDifference(pDate) + " by " + article.getAuthor();
} catch (ParseException e) {
Log.e("DATE PARSING", "Error parsing date..");
pubDate = "published by " + article.getAuthor();
if(convertView == null){
LayoutInflater inflater = myContext.getLayoutInflater();
convertView = inflater.inflate(R.layout.fragment_article_list, null);

viewHolder = new ViewHolder();
viewHolder.textView = (TextView) convertView.findViewById(R.id.article_title_text);
viewHolder.dateView = (TextView) convertView.findViewById(R.id.article_listing_smallprint);
viewHolder.row = (LinearLayout) convertView.findViewById(R.id.article_row_layout);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder)convertView.getTag();
}
dateView.setText(pubDate);


if (!article.isRead()){
LinearLayout row = (LinearLayout) rowView.findViewById(R.id.article_row_layout);
row.setBackgroundColor(Color.WHITE);
textView.setTypeface(Typeface.DEFAULT_BOLD);
Article article = getItem(position);
if(article != null){
viewHolder.textView.setText(article.getTitle());

String pubDate = article.getPubDate();
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss Z", Locale.ENGLISH);
Date pDate;
try {
pDate = df.parse(pubDate);
pubDate = "published " + DateUtils.getDateDifference(pDate) + " by " + article.getAuthor();
} catch (ParseException e) {
Log.e("DATE PARSING", "Error parsing date..");
pubDate = "published by " + article.getAuthor();
}
viewHolder.dateView.setText(pubDate);

if (!article.isRead()){
viewHolder.row.setBackgroundColor(Color.WHITE);
viewHolder.textView.setTypeface(Typeface.DEFAULT_BOLD);
}
}
return rowView;
return convertView;

}
}
}