本文整理汇总了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)
));
}
示例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());
}
示例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))
);
}
示例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)
));
}
示例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)
));
}
示例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))
);
}
示例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)
));
}
示例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)
));
}