Skip to content

Instantly share code, notes, and snippets.

@lawloretienne
Created May 23, 2016 20:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawloretienne/ba02c79e4a8829d88f54f5739c6036b1 to your computer and use it in GitHub Desktop.
Save lawloretienne/ba02c79e4a8829d88f54f5739c6036b1 to your computer and use it in GitHub Desktop.
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