diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java index f902f541..772ef764 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java @@ -103,9 +103,9 @@ public class NewsListRecyclerAdapter extends RecyclerView.Adapter { layout = R.layout.subscription_detail_list_item_extended_webview; break; } - View view = LayoutInflater.from(parent.getContext()) - .inflate(layout, parent, false); - return new ViewHolder(view,titleLineCount); + View view = LayoutInflater.from(parent.getContext()).inflate(layout, parent, false); + + return new ViewHolder(view, titleLineCount, activity); } @Override diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/ViewHolder.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/ViewHolder.java index 9b5b1f55..8186bb32 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/ViewHolder.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/ViewHolder.java @@ -1,9 +1,13 @@ package de.luhmer.owncloudnewsreader.adapter; +import android.app.Activity; import android.graphics.Typeface; import android.support.v7.widget.RecyclerView; import android.text.Html; +import android.text.Spannable; +import android.text.SpannableString; import android.text.format.DateUtils; +import android.text.style.ForegroundColorSpan; import android.util.Log; import android.view.View; import android.webkit.WebView; @@ -66,9 +70,14 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL private RssItem rssItem; private boolean stayUnread = false; private static FavIconHandler favIconHandler = null; + private final int LengthBody = 400; + private ForegroundColorSpan bodyForegroundColor; - public ViewHolder(View itemView, int titleLineCount) { + public ViewHolder(View itemView, int titleLineCount, Activity activity) { super(itemView); + + bodyForegroundColor = new ForegroundColorSpan(activity.getResources().getColor(android.R.color.secondary_text_dark)); + if(favIconHandler == null) favIconHandler = new FavIconHandler(itemView.getContext()); ButterKnife.inject(this, itemView); @@ -82,7 +91,7 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL @Override public void onClick(View v) { - clickListener.onClick(this,getLayoutPosition()); + clickListener.onClick(this, getLayoutPosition()); } public void setClickListener(RecyclerItemClickListener clickListener) { @@ -137,7 +146,7 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL if(textViewBody != null) // Strip html from String - textViewBody.setText(Html.fromHtml(body).toString()); + textViewBody.setText(getBodyText(body)); if(textViewItemDate != null) textViewItemDate.setText(DateUtils.getRelativeTimeSpanString(rssItem.getPubDate().getTime())); @@ -159,4 +168,19 @@ public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickL this.stayUnread = shouldStayUnread; } + private String getBodyText(String body) + { + body = body.replaceAll("]*>", ""); + body = body.replaceAll("]*>", ""); + + SpannableString bodyStringSpannable = new SpannableString(Html.fromHtml(body)); + bodyStringSpannable.setSpan(bodyForegroundColor, 0, bodyStringSpannable.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); + + String bodyString = bodyStringSpannable.toString().trim(); + + if(bodyString.length() > LengthBody) + bodyString = bodyString.substring(0, LengthBody) + "..."; + + return bodyString; + } }