use of rx.Observable in project Android-ReactiveLocation by mcharmas.
the class PlacesActivity method onLocationPermissionGranted.
@Override
protected void onLocationPermissionGranted() {
compositeSubscription = new CompositeSubscription();
compositeSubscription.add(reactiveLocationProvider.getCurrentPlace(null).subscribe(new Action1<PlaceLikelihoodBuffer>() {
@Override
public void call(PlaceLikelihoodBuffer buffer) {
PlaceLikelihood likelihood = buffer.get(0);
if (likelihood != null) {
currentPlaceView.setText(likelihood.getPlace().getName());
}
buffer.release();
}
}));
Observable<String> queryObservable = RxTextView.textChanges(queryView).map(new Func1<CharSequence, String>() {
@Override
public String call(CharSequence charSequence) {
return charSequence.toString();
}
}).debounce(1, TimeUnit.SECONDS).filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return !TextUtils.isEmpty(s);
}
});
Observable<Location> lastKnownLocationObservable = reactiveLocationProvider.getLastKnownLocation();
Observable<AutocompletePredictionBuffer> suggestionsObservable = Observable.combineLatest(queryObservable, lastKnownLocationObservable, new Func2<String, Location, QueryWithCurrentLocation>() {
@Override
public QueryWithCurrentLocation call(String query, Location currentLocation) {
return new QueryWithCurrentLocation(query, currentLocation);
}
}).flatMap(new Func1<QueryWithCurrentLocation, Observable<AutocompletePredictionBuffer>>() {
@Override
public Observable<AutocompletePredictionBuffer> call(QueryWithCurrentLocation q) {
if (q.location == null)
return Observable.empty();
double latitude = q.location.getLatitude();
double longitude = q.location.getLongitude();
LatLngBounds bounds = new LatLngBounds(new LatLng(latitude - 0.05, longitude - 0.05), new LatLng(latitude + 0.05, longitude + 0.05));
return reactiveLocationProvider.getPlaceAutocompletePredictions(q.query, bounds, null);
}
});
compositeSubscription.add(suggestionsObservable.subscribe(new Action1<AutocompletePredictionBuffer>() {
@Override
public void call(AutocompletePredictionBuffer buffer) {
List<AutocompleteInfo> infos = new ArrayList<>();
for (AutocompletePrediction prediction : buffer) {
infos.add(new AutocompleteInfo(prediction.getFullText(null).toString(), prediction.getPlaceId()));
}
buffer.release();
placeSuggestionsList.setAdapter(new ArrayAdapter<>(PlacesActivity.this, android.R.layout.simple_list_item_1, infos));
}
}));
}
use of rx.Observable in project jersey by jersey.
the class ObservableAgentResource method observable.
@GET
public void observable(@Suspended final AsyncResponse async) {
final long time = System.nanoTime();
final Queue<String> errors = new ConcurrentLinkedQueue<>();
Observable.just(new AgentResponse()).zipWith(visited(errors), (response, visited) -> {
response.setVisited(visited);
return response;
}).zipWith(recommended(errors), (response, recommendations) -> {
response.setRecommended(recommendations);
return response;
}).observeOn(Schedulers.io()).subscribe(response -> {
response.setProcessingTime((System.nanoTime() - time) / 1000000);
async.resume(response);
}, async::resume);
}
use of rx.Observable in project android-oss by kickstarter.
the class ApiExceptionFactory method badRequestException.
@NonNull
public static ApiException badRequestException() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("bad request")).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, "");
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(400, body);
return new ApiException(envelope, response);
}
use of rx.Observable in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaRequired.
@NonNull
public static ApiException tfaRequired() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_REQUIRED).httpCode(403).errorMessages(Collections.singletonList("Two-factor authentication required.")).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
use of rx.Observable in project android-oss by kickstarter.
the class ApiExceptionFactory method tfaFailed.
@NonNull
public static ApiException tfaFailed() {
final ErrorEnvelope envelope = ErrorEnvelope.builder().ksrCode(ErrorEnvelope.TFA_FAILED).httpCode(400).build();
final ResponseBody body = ResponseBody.create(null, new Gson().toJson(envelope));
final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(envelope.httpCode(), body);
return new ApiException(envelope, response);
}
Aggregations