package com.afollestad.aesthetic; import android.content.Context; import android.util.AttributeSet; import android.widget.ListView; import io.reactivex.annotations.NonNull; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import static com.afollestad.aesthetic.Rx.onErrorLogAndRethrow; /** @author Aidan Follestad (afollestad) */ public class AestheticListView extends ListView { private Disposable subscription; public AestheticListView(Context context) { super(context); } public AestheticListView(Context context, AttributeSet attrs) { super(context, attrs); } public AestheticListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } private void invalidateColors(int color) { EdgeGlowUtil.setEdgeGlowColor(this, color); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); subscription = Aesthetic.get() .colorAccent() .compose(Rx.<Integer>distinctToMainThread()) .subscribe( new Consumer<Integer>() { @Override public void accept(@NonNull Integer color) { invalidateColors(color); } }, onErrorLogAndRethrow()); } @Override protected void onDetachedFromWindow() { subscription.dispose(); super.onDetachedFromWindow(); } }