use of io.reactivex.rxjava3.disposables.Disposable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerScheduleOnceWithDelayDisposedDoesNotRun.
@Test
public void workerScheduleOnceWithDelayDisposedDoesNotRun() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
Disposable disposable = worker.schedule(counter, 1, MINUTES);
idleMainLooper(30, SECONDS);
disposable.dispose();
idleMainLooper(30, SECONDS);
runUiThreadTasks();
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.disposables.Disposable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
Worker worker = scheduler.createWorker();
final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
CountingRunnable counter = new CountingRunnable() {
@Override
public void run() {
super.run();
if (get() == 2) {
disposableRef.get().dispose();
}
}
};
Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);
disposableRef.set(disposable);
runUiThreadTasks();
assertEquals(0, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(1, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(2, counter.get());
// Dispose will have happened here during the last run() execution.
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(2, counter.get());
}
use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.
the class EnterPhoneNumberFragment method requestVerificationCode.
private void requestVerificationCode(@NonNull Mode mode) {
NavController navController = NavHostFragment.findNavController(this);
Disposable request = viewModel.requestVerificationCode(mode).doOnSubscribe(unused -> SignalStore.account().setRegistered(false)).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
if (processor.hasResult()) {
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
} else if (processor.localRateLimit()) {
Log.i(TAG, "Unable to request sms code due to local rate limit");
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
} else if (processor.captchaRequired()) {
Log.i(TAG, "Unable to request sms code due to captcha required");
SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionRequestCaptcha());
} else if (processor.rateLimit()) {
Log.i(TAG, "Unable to request sms code due to rate limit");
Toast.makeText(register.getContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
} else if (processor.isImpossibleNumber()) {
Log.w(TAG, "Impossible number", processor.getError());
Dialogs.showAlertDialog(requireContext(), getString(R.string.RegistrationActivity_invalid_number), String.format(getString(R.string.RegistrationActivity_the_number_you_specified_s_is_invalid), viewModel.getNumber().getFullFormattedNumber()));
} else if (processor.isNonNormalizedNumber()) {
handleNonNormalizedNumberError(processor.getOriginalNumber(), processor.getNormalizedNumber(), mode);
} else {
Log.i(TAG, "Unknown error during verification code request", processor.getError());
Toast.makeText(register.getContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();
}
cancelSpinning(register);
enableAllEntries();
});
disposables.add(request);
}
use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.
the class BaseEnterSmsCodeFragment method handlePhoneCallRequestAfterConfirm.
private void handlePhoneCallRequestAfterConfirm() {
Disposable request = viewModel.requestVerificationCode(VerifyAccountRepository.Mode.PHONE_CALL).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
if (processor.hasResult()) {
Toast.makeText(requireContext(), R.string.RegistrationActivity_call_requested, Toast.LENGTH_LONG).show();
} else if (processor.captchaRequired()) {
navigateToCaptcha();
} else if (processor.rateLimit()) {
Toast.makeText(requireContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
} else {
Log.w(TAG, "Unable to request phone code", processor.getError());
Toast.makeText(requireContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();
}
});
disposables.add(request);
}
use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.
the class SignalWebSocket method getUnidentifiedWebSocket.
private synchronized WebSocketConnection getUnidentifiedWebSocket() throws WebSocketUnavailableException {
if (!canConnect) {
throw new WebSocketUnavailableException();
}
if (unidentifiedWebSocket == null || unidentifiedWebSocket.isDead()) {
unidentifiedWebSocketStateDisposable.dispose();
unidentifiedWebSocket = webSocketFactory.createUnidentifiedWebSocket();
unidentifiedWebSocketStateDisposable = new CompositeDisposable();
Disposable state = unidentifiedWebSocket.connect().subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).subscribe(unidentifiedWebSocketState::onNext);
unidentifiedWebSocketStateDisposable.add(state);
}
return unidentifiedWebSocket;
}
Aggregations