Created
May 23, 2016 20:46
-
-
Save lawloretienne/ba02c79e4a8829d88f54f5739c6036b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RxImageView extends ImageView { | |
// region Member Variables | |
private PublishSubject<Boolean> publishSubject = PublishSubject.create(); | |
// endregion | |
// region Constructors | |
public RxImageView(Context context) { | |
super(context); | |
} | |
public RxImageView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public RxImageView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
// endregion | |
@Override | |
public void setImageBitmap(Bitmap bm) { | |
super.setImageBitmap(bm); | |
if(publishSubject != null) | |
publishSubject.onNext(true); | |
} | |
@Override | |
public void setImageResource(@DrawableRes int resId) { | |
super.setImageResource(resId); | |
if(publishSubject != null) | |
publishSubject.onNext(true); | |
} | |
@Override | |
public void setImageDrawable(Drawable drawable) { | |
super.setImageDrawable(drawable); | |
Drawable resDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_placholder); | |
if (!(drawable.getConstantState().equals(resDrawable.getConstantState()))){ | |
if(publishSubject != null) | |
publishSubject.onNext(true); | |
} | |
} | |
// region Helper Methods | |
public PublishSubject<Boolean> getPublishSubject() { | |
return publishSubject; | |
} | |
// endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment