当前位置: 首页>>代码示例>>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;未经允许,请勿转载。