I use the Focus Observable from the RxBindings library to respond to changes in focus. Since I want to either check input and run the animation, I need focus events twice. Jake Wharton recommends using the share () operator for multiple signatures per observable. But if I manipulate the observable after using share (), the first subscription will be dead.
This is a small example of my use.
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 needed and expected was the result when I get and lose focus on the EditText,
Focus gain Subscriber One: true Focus loss Subscriber One: false Subscriber Two: false
But I really get
Focus gain Focus loss Subscriber Two: false
So, it seems that the manipulation of the second case redefines the first. What am I doing wrong and what is the supposed way of exchanging events between multiple subscribers when they manipulate it differently.
thanks
source share