headlines: use flavor image tag for a slight performance improvement, hopefully

This commit is contained in:
Andrew Dolgov 2015-06-05 14:48:21 +03:00
parent 3b37e33d6b
commit 79f4b94a34

View File

@ -657,6 +657,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT; private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT;
private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round(); private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round();
private final DisplayImageOptions displayImageOptions;
public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) { public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) {
super(context, textViewResourceId, items); super(context, textViewResourceId, items);
@ -666,6 +667,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
TypedValue tv = new TypedValue(); TypedValue tv = new TypedValue();
theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true); theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true);
titleHighScoreUnreadColor = tv.data; titleHighScoreUnreadColor = tv.data;
displayImageOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.build();
} }
public int getViewTypeCount() { public int getViewTypeCount() {
@ -908,7 +915,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT")); boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"));
if (showFlavorImage && holder.flavorImageView != null) { if (showFlavorImage && holder.flavorImageView != null) {
holder.flavorImageArrow.setVisibility(View.GONE); holder.flavorImageArrow.setVisibility(View.GONE);
if (article.noValidFlavorImage) { if (article.noValidFlavorImage) {
@ -935,7 +941,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
if (article.flavorImage != null) { if (article.flavorImage != null) {
String imgSrc = article.flavorImage.attr("src"); String imgSrc = article.flavorImage.attr("src");
final String imgSrcFirst = imgSrc; final String imgSrcFirst = imgSrc;
@ -943,12 +948,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (imgSrc.indexOf("//") == 0) if (imgSrc.indexOf("//") == 0)
imgSrc = "http:" + imgSrc; imgSrc = "http:" + imgSrc;
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.build();
ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_IMAGES_PAGER"); ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_IMAGES_PAGER");
holder.flavorImageView.setOnClickListener(new OnClickListener() { holder.flavorImageView.setOnClickListener(new OnClickListener() {
@ -974,47 +973,54 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
final ViewGroup flavorImageHolder = holder.flavorImageHolder; final ViewGroup flavorImageHolder = holder.flavorImageHolder;
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar; final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); if (holder.flavorImageView.getTag() == null || !holder.flavorImageView.getTag().equals(imgSrc)) {
ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() { holder.flavorImageView.setTag(imgSrc);
@Override ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
public void onLoadingCancelled(String arg0,
View arg1) {
// TODO Auto-generated method stub
} ImageLoader.getInstance().displayImage(imgSrc, imageAware, displayImageOptions, new ImageLoadingListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override
@Override public void onLoadingCancelled(String arg0,
public void onLoadingComplete(String arg0, View arg1) {
View arg1, Bitmap arg2) { // TODO Auto-generated method stub
if (!isAdded() || arg2 == null) return;
flavorImageLoadingBar.setVisibility(View.INVISIBLE); }
if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) { @TargetApi(Build.VERSION_CODES.HONEYCOMB)
flavorImageHolder.setVisibility(View.VISIBLE); @Override
} else { public void onLoadingComplete(String arg0,
flavorImageHolder.setVisibility(View.GONE); View arg1, Bitmap arg2) {
} if (!isAdded() || arg2 == null) return;
}
@Override flavorImageLoadingBar.setVisibility(View.INVISIBLE);
public void onLoadingFailed(String arg0,
View arg1, FailReason arg2) {
flavorImageHolder.setVisibility(View.GONE);
article.noValidFlavorImage = true;
}
@Override if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) {
public void onLoadingStarted(String arg0, flavorImageHolder.setVisibility(View.VISIBLE);
View arg1) { } else {
// TODO Auto-generated method stub flavorImageHolder.setVisibility(View.GONE);
}
}
} @Override
public void onLoadingFailed(String arg0,
View arg1, FailReason arg2) {
flavorImageHolder.setVisibility(View.GONE);
article.noValidFlavorImage = true;
}
@Override
public void onLoadingStarted(String arg0,
View arg1) {
// TODO Auto-generated method stub
}
});
}
});
} else{ } else{
article.noValidFlavorImage = true; article.noValidFlavorImage = true;
holder.flavorImageHolder.setVisibility(View.GONE); holder.flavorImageHolder.setVisibility(View.GONE);