I'm using a Focus Observable from the RxBindings library to react on focus changes. As I want to either validate input and trigger an animation I need the focus events twice. Jake Wharton recommends to use the share() operator for multiple subscriptions on one observable. But if I manipulate the observable after using share() the first subscription is dead.
This is a small example of my usecase
public class ShareTest extends AppCompatActivity {
@Bind(R.id.editTextOne)
EditText editTextOne;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_test);
ButterKnife.bind(this);
Observable<Boolean> focusChangeObservable = RxView.focusChanges(editTextOne);
focusChangeObservable.subscribe(focused -> Log.d("test","Subscriber One: "+focused));
focusChangeObservable.share().skip(1).filter(focused -> focused == false).subscribe(focused -> {
Log.d("test","Subscriber Two: "+focused);
});
}
}
What I need and expected was an output when I gain and loose the focus on the EditText is
Focus gain
Subscriber One: true
Focus loss
Subscriber One: false
Subscriber Two: false
But what I actually get is
Focus gain
Focus loss
Subscriber Two: false
So it seems the manipulation of the second case overrides the first one. What am I doing wrong and what is the intended way to share events between multiple subscribers when they are manipulated differently
Thanks