画像ロード中にViewと画像URLの組み合わせが変わったらロードされた画像を無視する

This commit is contained in:
tateisu 2017-05-21 10:31:58 +09:00
parent 3da3f2c3ed
commit 57b6ff7283
2 changed files with 10 additions and 6 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 25
versionCode 63
versionName "0.6.3"
versionCode 64
versionName "0.6.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -12,8 +12,6 @@ import android.view.ViewGroup;
import android.support.v7.widget.AppCompatImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
@ -21,6 +19,7 @@ import com.bumptech.glide.request.target.Target;
import java.util.concurrent.atomic.AtomicBoolean;
import jp.juggler.subwaytooter.Pref;
import jp.juggler.subwaytooter.util.Utils;
public class MyNetworkImageView extends AppCompatImageView {
@ -144,6 +143,9 @@ public class MyNetworkImageView extends AppCompatImageView {
.into(
new SimpleTarget< Bitmap >( desiredWidth, desiredHeight ) {
@Override public void onLoadFailed( Exception e, Drawable errorDrawable ){
// このViewは別の画像を表示するように指定が変わっていた
if( mTargetUrl == null || ! mTargetUrl.equals( mUrl ) ) return;
e.printStackTrace();
if( mErrorImageId != 0 ) setImageResource( mErrorImageId );
}
@ -154,14 +156,16 @@ public class MyNetworkImageView extends AppCompatImageView {
){
if( isImmediate.get() && isInLayoutPass ){
post( new Runnable() {
@Override
public void run(){
@Override public void run(){
onResourceReady( bitmap, glideAnimation );
}
} );
return;
}
// このViewは別の画像を表示するように指定が変わっていた
if( mTargetUrl == null || ! mTargetUrl.equals( mUrl ) ) return;
if( bitmap == null ){
setDefaultImageOrNull();
}else if( mCornerRadius <= 0f ){