add another check for flavor images maybe loading in the wrong list entry because of recycling

This commit is contained in:
Andrew Dolgov 2015-07-17 19:15:27 +03:00
parent 0c72504421
commit aa3e9d0c7c

View File

@ -1147,6 +1147,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (!posterUri.equals(holder.flavorImageView.getTag())) { if (!posterUri.equals(holder.flavorImageView.getTag())) {
holder.flavorImageView.setTag("LOADING:" + posterUri);
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
m_imageLoader.displayImage(posterUri, imageAware, displayImageOptions, new ImageLoadingListener() { m_imageLoader.displayImage(posterUri, imageAware, displayImageOptions, new ImageLoadingListener() {
@ -1161,7 +1162,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
@Override @Override
public void onLoadingComplete(String s, View view, Bitmap bitmap) { public void onLoadingComplete(String imageUri, View view, Bitmap bitmap) {
if (("LOADING:" + imageUri).equals(view.getTag())) {
holder.flavorImageLoadingBar.setVisibility(View.GONE); holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorImageView.setTag(posterUri); holder.flavorImageView.setTag(posterUri);
holder.flavorImageView.setVisibility(View.VISIBLE); holder.flavorImageView.setVisibility(View.VISIBLE);
@ -1169,6 +1172,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
maybeRepositionFlavorImage(view, bitmap, holder); maybeRepositionFlavorImage(view, bitmap, holder);
} }
}
@Override @Override
public void onLoadingCancelled(String s, View view) { public void onLoadingCancelled(String s, View view) {
@ -1252,6 +1256,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.flavorVideoKindView.setImageResource(R.drawable.ic_youtube_play); holder.flavorVideoKindView.setImageResource(R.drawable.ic_youtube_play);
if (!thumbUri.equals(holder.flavorImageView.getTag())) { if (!thumbUri.equals(holder.flavorImageView.getTag())) {
holder.flavorImageView.setTag("LOADING:" + thumbUri);
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
m_imageLoader.displayImage(thumbUri, imageAware, displayImageOptions, new ImageLoadingListener() { m_imageLoader.displayImage(thumbUri, imageAware, displayImageOptions, new ImageLoadingListener() {
@Override @Override
@ -1265,7 +1271,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
@Override @Override
public void onLoadingComplete(String s, View view, Bitmap bitmap) { public void onLoadingComplete(String imageUri, View view, Bitmap bitmap) {
if (("LOADING:" + imageUri).equals(view.getTag())) {
holder.flavorImageLoadingBar.setVisibility(View.GONE); holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorImageView.setTag(thumbUri); holder.flavorImageView.setTag(thumbUri);
holder.flavorImageView.setVisibility(View.VISIBLE); holder.flavorImageView.setVisibility(View.VISIBLE);
@ -1273,6 +1280,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
maybeRepositionFlavorImage(view, bitmap, holder); maybeRepositionFlavorImage(view, bitmap, holder);
} }
}
@Override @Override
public void onLoadingCancelled(String s, View view) { public void onLoadingCancelled(String s, View view) {
@ -1366,6 +1374,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (!imgSrc.equals(holder.flavorImageView.getTag())) { if (!imgSrc.equals(holder.flavorImageView.getTag())) {
holder.flavorImageView.setTag("LOADING:" + imgSrc);
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
final String finalImgSrc = imgSrc; final String finalImgSrc = imgSrc;
@ -1379,9 +1388,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
@Override @Override
public void onLoadingComplete(String arg0, public void onLoadingComplete(String imageUri,
View view, Bitmap bitmap) { View view, Bitmap bitmap) {
if (!isAdded() || bitmap == null) return;
if (("LOADING:" + imageUri).equals(view.getTag())) {
holder.flavorImageLoadingBar.setVisibility(View.GONE); holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorImageView.setTag(finalImgSrc); holder.flavorImageView.setTag(finalImgSrc);
@ -1399,6 +1409,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.flavorImageView.setImageDrawable(null); holder.flavorImageView.setImageDrawable(null);
} }
} }
}
@Override @Override
public void onLoadingFailed(String arg0, public void onLoadingFailed(String arg0,