@Test public void subscribeDisplaysCurrencySelectionForNullState() throws Exception { nullSavedStatePresenter.subscribe(); verify(displayCurrencySelectionConsumer).accept(0); }
@Override @CallSuper public void subscribe() { final ConnectableObservable<List<CharSequence>> currenciesConnectableObservable = Observable.fromCallable(this.databaseHelper::getCurrenciesList) .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .publish(); this.compositeDisposable.add(currenciesConnectableObservable .subscribe(view.displayCurrencies())); this.compositeDisposable.add(currenciesConnectableObservable .map(currenciesList -> { final String currencyCode; if (savedInstanceState != null && savedInstanceState.containsKey(OUT_STATE_SELECTED_CURRENCY_POSITION)) { currencyCode = currenciesList.get(savedInstanceState.getInt(OUT_STATE_SELECTED_CURRENCY_POSITION)).toString(); } else if (lastSelectedCurrencyCodeIndex >= 0) { currencyCode = currenciesList.get(lastSelectedCurrencyCodeIndex).toString(); } else { currencyCode = defaultCurrencyCodeSupplier.get(); } final int currencyPosition = currenciesList.indexOf(currencyCode); if (currencyPosition >= 0) { return currencyPosition; } else { return 0; } }) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable .flatMap(currenciesList -> { return view.currencyClicks() .filter(currencyIndex -> currencyIndex >= 0); }) .doOnNext(currencyIndex -> lastSelectedCurrencyCodeIndex = currencyIndex) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable.connect()); }
CurrencyListEditorPresenter extends BasePresenter<CurrencyListEditorView> { @Override @CallSuper public void subscribe() { final ConnectableObservable<List<CharSequence>> currenciesConnectableObservable = Observable.fromCallable(this.databaseHelper::getCurrenciesList) .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .publish(); this.compositeDisposable.add(currenciesConnectableObservable .subscribe(view.displayCurrencies())); this.compositeDisposable.add(currenciesConnectableObservable .map(currenciesList -> { final String currencyCode; if (savedInstanceState != null && savedInstanceState.containsKey(OUT_STATE_SELECTED_CURRENCY_POSITION)) { currencyCode = currenciesList.get(savedInstanceState.getInt(OUT_STATE_SELECTED_CURRENCY_POSITION)).toString(); } else if (lastSelectedCurrencyCodeIndex >= 0) { currencyCode = currenciesList.get(lastSelectedCurrencyCodeIndex).toString(); } else { currencyCode = defaultCurrencyCodeSupplier.get(); } final int currencyPosition = currenciesList.indexOf(currencyCode); if (currencyPosition >= 0) { return currencyPosition; } else { return 0; } }) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable .flatMap(currenciesList -> { return view.currencyClicks() .filter(currencyIndex -> currencyIndex >= 0); }) .doOnNext(currencyIndex -> lastSelectedCurrencyCodeIndex = currencyIndex) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable.connect()); } }
CurrencyListEditorPresenter extends BasePresenter<CurrencyListEditorView> { @Override @CallSuper public void subscribe() { final ConnectableObservable<List<CharSequence>> currenciesConnectableObservable = Observable.fromCallable(this.databaseHelper::getCurrenciesList) .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .publish(); this.compositeDisposable.add(currenciesConnectableObservable .subscribe(view.displayCurrencies())); this.compositeDisposable.add(currenciesConnectableObservable .map(currenciesList -> { final String currencyCode; if (savedInstanceState != null && savedInstanceState.containsKey(OUT_STATE_SELECTED_CURRENCY_POSITION)) { currencyCode = currenciesList.get(savedInstanceState.getInt(OUT_STATE_SELECTED_CURRENCY_POSITION)).toString(); } else if (lastSelectedCurrencyCodeIndex >= 0) { currencyCode = currenciesList.get(lastSelectedCurrencyCodeIndex).toString(); } else { currencyCode = defaultCurrencyCodeSupplier.get(); } final int currencyPosition = currenciesList.indexOf(currencyCode); if (currencyPosition >= 0) { return currencyPosition; } else { return 0; } }) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable .flatMap(currenciesList -> { return view.currencyClicks() .filter(currencyIndex -> currencyIndex >= 0); }) .doOnNext(currencyIndex -> lastSelectedCurrencyCodeIndex = currencyIndex) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable.connect()); } CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                       @NonNull DatabaseHelper databaseHelper,
                                       @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                       @Nullable Bundle savedInstanceState); @VisibleForTesting  CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                @NonNull DatabaseHelper databaseHelper,
                                @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                @Nullable Bundle savedInstanceState,
                                @NonNull Scheduler subscribeOnScheduler,
                                @NonNull Scheduler observeOnScheduler); }
CurrencyListEditorPresenter extends BasePresenter<CurrencyListEditorView> { @Override @CallSuper public void subscribe() { final ConnectableObservable<List<CharSequence>> currenciesConnectableObservable = Observable.fromCallable(this.databaseHelper::getCurrenciesList) .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .publish(); this.compositeDisposable.add(currenciesConnectableObservable .subscribe(view.displayCurrencies())); this.compositeDisposable.add(currenciesConnectableObservable .map(currenciesList -> { final String currencyCode; if (savedInstanceState != null && savedInstanceState.containsKey(OUT_STATE_SELECTED_CURRENCY_POSITION)) { currencyCode = currenciesList.get(savedInstanceState.getInt(OUT_STATE_SELECTED_CURRENCY_POSITION)).toString(); } else if (lastSelectedCurrencyCodeIndex >= 0) { currencyCode = currenciesList.get(lastSelectedCurrencyCodeIndex).toString(); } else { currencyCode = defaultCurrencyCodeSupplier.get(); } final int currencyPosition = currenciesList.indexOf(currencyCode); if (currencyPosition >= 0) { return currencyPosition; } else { return 0; } }) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable .flatMap(currenciesList -> { return view.currencyClicks() .filter(currencyIndex -> currencyIndex >= 0); }) .doOnNext(currencyIndex -> lastSelectedCurrencyCodeIndex = currencyIndex) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable.connect()); } CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                       @NonNull DatabaseHelper databaseHelper,
                                       @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                       @Nullable Bundle savedInstanceState); @VisibleForTesting  CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                @NonNull DatabaseHelper databaseHelper,
                                @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                @Nullable Bundle savedInstanceState,
                                @NonNull Scheduler subscribeOnScheduler,
                                @NonNull Scheduler observeOnScheduler); @Override @CallSuper void subscribe(); void onSaveInstanceState(@NonNull Bundle outState); }
CurrencyListEditorPresenter extends BasePresenter<CurrencyListEditorView> { @Override @CallSuper public void subscribe() { final ConnectableObservable<List<CharSequence>> currenciesConnectableObservable = Observable.fromCallable(this.databaseHelper::getCurrenciesList) .subscribeOn(subscribeOnScheduler) .observeOn(observeOnScheduler) .publish(); this.compositeDisposable.add(currenciesConnectableObservable .subscribe(view.displayCurrencies())); this.compositeDisposable.add(currenciesConnectableObservable .map(currenciesList -> { final String currencyCode; if (savedInstanceState != null && savedInstanceState.containsKey(OUT_STATE_SELECTED_CURRENCY_POSITION)) { currencyCode = currenciesList.get(savedInstanceState.getInt(OUT_STATE_SELECTED_CURRENCY_POSITION)).toString(); } else if (lastSelectedCurrencyCodeIndex >= 0) { currencyCode = currenciesList.get(lastSelectedCurrencyCodeIndex).toString(); } else { currencyCode = defaultCurrencyCodeSupplier.get(); } final int currencyPosition = currenciesList.indexOf(currencyCode); if (currencyPosition >= 0) { return currencyPosition; } else { return 0; } }) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable .flatMap(currenciesList -> { return view.currencyClicks() .filter(currencyIndex -> currencyIndex >= 0); }) .doOnNext(currencyIndex -> lastSelectedCurrencyCodeIndex = currencyIndex) .subscribe(view.displayCurrencySelection())); this.compositeDisposable.add(currenciesConnectableObservable.connect()); } CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                       @NonNull DatabaseHelper databaseHelper,
                                       @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                       @Nullable Bundle savedInstanceState); @VisibleForTesting  CurrencyListEditorPresenter(@NonNull CurrencyListEditorView view,
                                @NonNull DatabaseHelper databaseHelper,
                                @NonNull CurrencyCodeSupplier defaultCurrencyCodeSupplier,
                                @Nullable Bundle savedInstanceState,
                                @NonNull Scheduler subscribeOnScheduler,
                                @NonNull Scheduler observeOnScheduler); @Override @CallSuper void subscribe(); void onSaveInstanceState(@NonNull Bundle outState);  }