當前位置: 首頁>>代碼示例>>Java>>正文


Java Observable.publish方法代碼示例

本文整理匯總了Java中io.reactivex.Observable.publish方法的典型用法代碼示例。如果您正苦於以下問題:Java Observable.publish方法的具體用法?Java Observable.publish怎麽用?Java Observable.publish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.publish方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadConcertEvent, Result> loadConcert = loadEvents ->
            loadEvents.flatMap(event -> {
                return getRepository().getConcert(concertId)
                        .map(LoadConcertResult::success)
                        .onErrorReturn(LoadConcertResult::error)
                        .toObservable()
                        .startWith(LoadConcertResult.IN_PROGRESS);
            });

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadConcertEvent.class, loadConcert),
            sharedEvents.ofType(Result.class)
    ));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:17,代碼來源:ConcertDetailsPresenter.java

示例2: testRefCount

import io.reactivex.Observable; //導入方法依賴的package包/類
private void testRefCount() {
    Observable<Long> observable = Observable.interval(1, TimeUnit.SECONDS).take(6);
    ConnectableObservable<Long> connectableObservable = observable.publish();
    connectableObservable.connect();
    Observable<Long> longObservable = connectableObservable.refCount();
    longObservable.delaySubscription(2, TimeUnit.SECONDS)
            .compose(Utils.<Long>ioToMain())
            .subscribe(getFirstObserver());
    longObservable.compose(Utils.<Long>ioToMain()).subscribe(getSecondObserver());
}
 
開發者ID:changjiashuai,項目名稱:RxJava2-Android-Sample,代碼行數:11,代碼來源:ConnectableExampleActivity.java

示例3: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadArtistsEvent, Result> loadArtists = loadEvents ->
            loadEvents.flatMap(event ->
                    getRepository().getArtists()
                            .map(LoadArtistsResult::success)
                            .onErrorReturn(LoadArtistsResult::error)
                            .startWith(LoadArtistsResult.IN_PROGRESS)
            );
    ObservableTransformer<DeleteArtistsEvent, Result> deleteArtists = deleteEvents ->
            deleteEvents.flatMap(event -> {
                List<Artist> artists = event.getUiModel().getSelectedArtists();

                return getRepository().deleteArtists(artists)
                        .toSingleDefault(DeleteArtistsResult.SUCCESS)
                        .onErrorReturn(DeleteArtistsResult::error)
                        .toObservable()
                        .startWith(DeleteArtistsResult.IN_PROGRESS);
            });

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadArtistsEvent.class, loadArtists),
            handleEventsOfClass(sharedEvents, DeleteArtistsEvent.class,
                    deleteArtists),
            sharedEvents.ofType(Result.class))
    );
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:28,代碼來源:ArtistsPresenter.java

示例4: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadLocationsEvent, Result> loadLocations = loadEvents ->
            loadEvents.flatMap(event ->
                    getRepository().getAvailableLocations()
                            .map(LoadLocationsResult::success)
                            .onErrorReturn(LoadLocationsResult::error)
                            .toObservable()
                            .startWith(LoadLocationsResult.IN_PROGRESS)
            );
    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadLocationsEvent.class, loadLocations),
            sharedEvents.ofType(Result.class)
    ));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:16,代碼來源:LocationChoicePresenter.java

示例5: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadArtistEvent.class, this::loadArtist),
            handleEventsOfClass(sharedEvents, SaveArtistEvent.class, this::saveArtist),
            sharedEvents.ofType(Result.class)
    ));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:9,代碼來源:EditArtistPresenter.java

示例6: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadArtistsEvent, Result> loadArtists = loadEvents ->
            loadEvents.flatMap(event ->
                    getRepository().loadArtistsFromGoogleMusic()
                            .map(LoadArtistsResult::success)
                            .onErrorReturn(LoadArtistsResult::error)
                            .toObservable()
                            .startWith(LoadArtistsResult.IN_PROGRESS)
            );

    ObservableTransformer<SaveArtistsEvent, Result> saveArtists = saveEvents ->
            saveEvents.flatMap(event -> {
                List<String> names = event.getUiModel().getSelectedArtists();

                if (names.isEmpty()) {
                    return Observable.just(SaveArtistsResult.error(
                            R.string.artist_import_error_no_artists_to_save));
                }

                List<Artist> artists = Observable.fromIterable(names)
                        .map(Artist::new)
                        .toList()
                        .blockingGet();

                return getRepository().saveArtists(artists)
                        .toSingleDefault(SaveArtistsResult.SUCCESS)
                        .onErrorReturnItem(SaveArtistsResult.error(R.string.error_saving_data))
                        .toObservable()
                        .startWith(SaveArtistsResult.IN_PROGRESS);
            });

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadArtistsEvent.class, loadArtists),
            handleEventsOfClass(sharedEvents, SaveArtistsEvent.class, saveArtists),
            sharedEvents.ofType(Result.class))
    );
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:39,代碼來源:ArtistImportPresenter.java

示例7: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadConcertsEvent, Result> loadConcerts = loadEvents ->
            loadEvents.flatMap(event ->
                    getRepository().getConcerts()
                            .map(LoadConcertsResult::success)
                            .onErrorReturn(LoadConcertsResult::error)
                            .startWith(LoadConcertsResult.IN_PROGRESS)
            );

    Observable<Result> syncing = SyncEventBus.getEventBus()
            .flatMap(busEvent -> {
                if (busEvent instanceof SyncStartEvent) {
                    return Observable.just(SyncResult.create(true));
                } else if (busEvent instanceof SyncFinishEvent) {
                    return Observable.just(SyncResult.create(false));
                }

                return Observable.empty();
            });

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadConcertsEvent.class, loadConcerts),
            syncing,
            sharedEvents.ofType(Result.class)
    ));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:28,代碼來源:ConcertsPresenter.java

示例8: handleEvents

import io.reactivex.Observable; //導入方法依賴的package包/類
@Override
protected Observable<Result> handleEvents(Observable<UiEvent> events) {
    ObservableTransformer<LoadLocationsEvent, Result> loadLocations = loadEvents ->
            loadEvents.flatMap(event ->
                    getRepository().getLocations()
                            .map(LoadLocationsResult::success)
                            .onErrorReturn(LoadLocationsResult::error)
                            .startWith(LoadLocationsResult.IN_PROGRESS)
            );
    ObservableTransformer<DeleteLocationEvent, Result> deleteLocation = deleteEvents ->
            deleteEvents
                    .flatMap(event -> {
                        int position = event.getPosition();
                        LocationsUiModel model = event.getUiModel();
                        int maxPosition = model.getLocations().size() - 1;

                        if (position > maxPosition) {
                            return Observable.empty();
                        }

                        Location location = model.getLocations().get(position);

                        return Observable.just(location);
                    })
                    .flatMap(location ->
                            getRepository().deleteLocation(location)
                                    .toSingleDefault(DeleteLocationResult.SUCCESS)
                                    .onErrorReturn(DeleteLocationResult::error)
                                    .toObservable()
                                    .startWith(DeleteLocationResult.IN_PROGRESS)
                    );
    ObservableTransformer<SaveLocationEvent, Result> saveLocation = saveEvents ->
            saveEvents.flatMap(event ->
                    getRepository().saveLocation(event.getLocation())
                            .toSingleDefault(SaveLocationResult.SUCCESS)
                            .onErrorReturn(SaveLocationResult::error)
                            .toObservable()
                            .startWith(SaveLocationResult.IN_PROGRESS)
            );

    return events.publish(sharedEvents -> Observable.merge(
            handleEventsOfClass(sharedEvents, LoadLocationsEvent.class, loadLocations),
            handleEventsOfClass(sharedEvents, DeleteLocationEvent.class, deleteLocation),
            handleEventsOfClass(sharedEvents, SaveLocationEvent.class, saveLocation),
            sharedEvents.ofType(Result.class)
    ));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:48,代碼來源:LocationsPresenter.java


注:本文中的io.reactivex.Observable.publish方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。