use of rx.functions.Action0 in project Rutgers-Course-Tracker by tevjef.
the class SectionInfoPresenterImpl method loadRMP.
public void loadRMP() {
final Iterable<Instructors> professorsNotFound = new ArrayList<>(mSection.getInstructors());
cancePreviousSubscription();
Subscriber<Professor> subscriber = new Subscriber<Professor>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Professor professor) {
if (getView() != null)
getView().addRMPProfessor(professor);
}
};
mSubscription = buildSearchParameters(mSection).flatMap(new Func1<Parameter, Observable<Professor>>() {
@Override
public Observable<Professor> call(Parameter parameter) {
return rmp.getProfessor(parameter);
}
}).doOnNext(new Action1<Professor>() {
@Override
public void call(Professor professor) {
for (final Iterator<Instructors> iterator = professorsNotFound.iterator(); iterator.hasNext(); ) {
Instructors i = iterator.next();
if (StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getLastName()) > .70 || StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getFirstName()) > .70) {
iterator.remove();
}
}
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).doOnTerminate(new Action0() {
@Override
public void call() {
if (getView() != null) {
getView().showRatingsLayout();
getView().hideRatingsLoading();
for (Instructors i : professorsNotFound) {
getView().addErrorProfessor(i.getName());
}
}
}
}).subscribe(subscriber);
}
use of rx.functions.Action0 in project Shuttle by timusus.
the class MusicService method openFile.
/**
* Opens a file and prepares it for playback
*
* @param path The path of the file to open
*/
public void openFile(String path, @Nullable Action0 completion) {
synchronized (this) {
if (path == null) {
return;
}
Uri uri = Uri.parse(path);
long id = -1;
try {
id = Long.valueOf(uri.getLastPathSegment());
} catch (NumberFormatException ignored) {
}
Predicate<Song> predicate;
long finalId = id;
if (finalId != -1 && (path.startsWith(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString()) || path.startsWith(MediaStore.Files.getContentUri("external").toString()))) {
predicate = song -> song.id == finalId;
} else {
if (uri != null && path.startsWith("content://")) {
path = uri.getPath();
}
String finalPath = path;
predicate = song -> song.path.contains(finalPath);
}
DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(predicate).collect(Collectors.toList())).subscribe(songs -> {
if (!songs.isEmpty()) {
currentSong = songs.get(0);
open(currentSong);
if (completion != null) {
completion.call();
}
}
});
}
}
use of rx.functions.Action0 in project RxLifecycle by trello.
the class MainActivity method onResume.
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
// `this.<Long>` is necessary if you're compiling on JDK7 or below.
//
// If you're using JDK8+, then you can safely remove it.
Observable.interval(1, TimeUnit.SECONDS).doOnUnsubscribe(new Action0() {
@Override
public void call() {
Log.i(TAG, "Unsubscribing subscription from onResume()");
}
}).compose(this.<Long>bindUntilEvent(ActivityEvent.DESTROY)).subscribe(new Action1<Long>() {
@Override
public void call(Long num) {
Log.i(TAG, "Started in onResume(), running until in onDestroy(): " + num);
}
});
}
use of rx.functions.Action0 in project RxPermissions by tbruyelle.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.setLogging(true);
setContentView(R.layout.act_main);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
RxView.clicks(findViewById(R.id.enableCamera)).compose(rxPermissions.ensureEach(Manifest.permission.CAMERA)).subscribe(new Action1<Permission>() {
@Override
public void call(Permission permission) {
Log.i(TAG, "Permission result " + permission);
if (permission.granted) {
releaseCamera();
camera = Camera.open(0);
try {
camera.setPreviewDisplay(surfaceView.getHolder());
camera.startPreview();
} catch (IOException e) {
Log.e(TAG, "Error while trying to display the camera preview", e);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
} else {
// Denied permission with ask never again
// Need to go to the settings
Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t) {
Log.e(TAG, "onError", t);
}
}, new Action0() {
@Override
public void call() {
Log.i(TAG, "OnComplete");
}
});
}
use of rx.functions.Action0 in project ribbon by Netflix.
the class NettyClientTest method testLoadBalancerThrottle.
@Test
public void testLoadBalancerThrottle() throws Exception {
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/throttle");
IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().set(IClientConfigKey.Keys.MaxAutoRetriesNextServer, 1).set(IClientConfigKey.Keys.OkToRetryOnAllOperations, true);
BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule());
LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config);
Server server = new Server(host, port);
lb.setServersList(Lists.newArrayList(server, server, server));
Observable<HttpClientResponse<ByteBuf>> response = lbObservables.submit(request);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
response.subscribe(new Action1<HttpClientResponse<ByteBuf>>() {
@Override
public void call(HttpClientResponse<ByteBuf> t1) {
System.err.println("Get response: " + t1.getStatus().code());
latch.countDown();
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
error.set(t1);
latch.countDown();
}
}, new Action0() {
@Override
public void call() {
Thread.dumpStack();
latch.countDown();
}
});
latch.await();
assertTrue(error.get() instanceof ClientException);
ClientException ce = (ClientException) error.get();
assertTrue(ce.toString(), ce.getErrorType() == ClientException.ErrorType.NUMBEROF_RETRIES_NEXTSERVER_EXCEEDED);
assertEquals(2, lbObservables.getServerStats(server).getSuccessiveConnectionFailureCount());
}
Aggregations