use of rx.functions.Action1 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.functions.Action1 in project Android-ReactiveLocation by mcharmas.
the class PlacesResultActivity method onLocationPermissionGranted.
@Override
protected void onLocationPermissionGranted() {
compositeSubscription = new CompositeSubscription();
compositeSubscription.add(reactiveLocationProvider.getPlaceById(placeId).subscribe(new Action1<PlaceBuffer>() {
@Override
public void call(PlaceBuffer buffer) {
Place place = buffer.get(0);
if (place != null) {
placeNameView.setText(place.getName());
placeLocationView.setText(place.getLatLng().latitude + ", " + place.getLatLng().longitude);
placeAddressView.setText(place.getAddress());
}
buffer.release();
}
}));
}
use of rx.functions.Action1 in project archi by ivacf.
the class RepositoryViewModel method loadFullUser.
private void loadFullUser(String url) {
ArchiApplication application = ArchiApplication.get(context);
GithubService githubService = application.getGithubService();
subscription = githubService.userFromUrl(url).observeOn(AndroidSchedulers.mainThread()).subscribeOn(application.defaultSubscribeScheduler()).subscribe(new Action1<User>() {
@Override
public void call(User user) {
Log.i(TAG, "Full user data loaded " + user);
ownerName.set(user.name);
ownerEmail.set(user.email);
ownerLocation.set(user.location);
ownerEmailVisibility.set(user.hasEmail() ? View.VISIBLE : View.GONE);
ownerLocationVisibility.set(user.hasLocation() ? View.VISIBLE : View.GONE);
ownerLayoutVisibility.set(View.VISIBLE);
}
});
}
use of rx.functions.Action1 in project Hystrix by Netflix.
the class HystrixThreadEventStreamTest method testThreadIsolatedResponseFromCache.
@Test
public void testThreadIsolatedResponseFromCache() throws Exception {
CountDownLatch commandLatch = new CountDownLatch(1);
CountDownLatch threadPoolLatch = new CountDownLatch(1);
Subscriber<List<HystrixCommandCompletion>> commandListSubscriber = getLatchedSubscriber(commandLatch);
readCommandStream.observe().buffer(500, TimeUnit.MILLISECONDS).take(1).doOnNext(new Action1<List<HystrixCommandCompletion>>() {
@Override
public void call(List<HystrixCommandCompletion> hystrixCommandCompletions) {
System.out.println("LIST : " + hystrixCommandCompletions);
assertEquals(3, hystrixCommandCompletions.size());
}
}).subscribe(commandListSubscriber);
Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS).setExecutedInThread();
ExecutionResult cache1 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
ExecutionResult cache2 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
writeToStream.executionDone(result, commandKey, threadPoolKey);
writeToStream.executionDone(cache1, commandKey, threadPoolKey);
writeToStream.executionDone(cache2, commandKey, threadPoolKey);
assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
assertTrue(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
use of rx.functions.Action1 in project Hystrix by Netflix.
the class HystrixThreadEventStreamTest method testSemaphoreIsolatedResponseFromCache.
@Test
public void testSemaphoreIsolatedResponseFromCache() throws Exception {
CountDownLatch commandLatch = new CountDownLatch(1);
CountDownLatch threadPoolLatch = new CountDownLatch(1);
Subscriber<List<HystrixCommandCompletion>> commandListSubscriber = getLatchedSubscriber(commandLatch);
readCommandStream.observe().buffer(500, TimeUnit.MILLISECONDS).take(1).doOnNext(new Action1<List<HystrixCommandCompletion>>() {
@Override
public void call(List<HystrixCommandCompletion> hystrixCommandCompletions) {
System.out.println("LIST : " + hystrixCommandCompletions);
assertEquals(3, hystrixCommandCompletions.size());
}
}).subscribe(commandListSubscriber);
Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch);
readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber);
ExecutionResult result = ExecutionResult.from(HystrixEventType.SUCCESS);
ExecutionResult cache1 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
ExecutionResult cache2 = ExecutionResult.from(HystrixEventType.RESPONSE_FROM_CACHE);
writeToStream.executionDone(result, commandKey, threadPoolKey);
writeToStream.executionDone(cache1, commandKey, threadPoolKey);
writeToStream.executionDone(cache2, commandKey, threadPoolKey);
assertTrue(commandLatch.await(1000, TimeUnit.MILLISECONDS));
assertFalse(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS));
}
Aggregations