Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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