本文整理匯總了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)
));
}