use of io.reactivex.rxjava3.subjects.BehaviorSubject in project RxJava by ReactiveX.
the class ObservableMapOptionalTest method mapperChashConditional.
@Test
public void mapperChashConditional() {
BehaviorSubject<Integer> source = BehaviorSubject.createDefault(1);
source.mapOptional(v -> {
throw new TestException();
}).filter(v -> true).test().assertFailure(TestException.class);
assertFalse(source.hasObservers());
}
use of io.reactivex.rxjava3.subjects.BehaviorSubject in project RxJava by ReactiveX.
the class BehaviorSubjectTest method onSubscribe.
@Test
public void onSubscribe() {
BehaviorSubject<Object> p = BehaviorSubject.create();
Disposable bs = Disposable.empty();
p.onSubscribe(bs);
assertFalse(bs.isDisposed());
p.onComplete();
bs = Disposable.empty();
p.onSubscribe(bs);
assertTrue(bs.isDisposed());
}
use of io.reactivex.rxjava3.subjects.BehaviorSubject in project RxJava by ReactiveX.
the class SerializedSubjectTest method behaviorSubjectError.
@Test
public void behaviorSubjectError() {
BehaviorSubject<Integer> async = BehaviorSubject.create();
TestException te = new TestException();
async.onError(te);
Subject<Integer> serial = async.toSerialized();
assertFalse(serial.hasObservers());
assertFalse(serial.hasComplete());
assertTrue(serial.hasThrowable());
assertSame(te, serial.getThrowable());
assertNull(async.getValue());
assertFalse(async.hasValue());
}
use of io.reactivex.rxjava3.subjects.BehaviorSubject in project a-medic-log by rh-id.
the class LogPage method createView.
@Override
protected View createView(Activity activity, ViewGroup container) {
View view = activity.getLayoutInflater().inflate(R.layout.page_log, container, false);
ViewGroup rootLayout = view.findViewById(R.id.root_layout);
ViewGroup containerAppBar = view.findViewById(R.id.container_app_bar);
mAppBarSV.setTitle(activity.getString(R.string.title_log_file));
containerAppBar.addView(mAppBarSV.buildView(activity, rootLayout));
ProgressBar progressBar = view.findViewById(R.id.progress_circular);
View noRecord = view.findViewById(R.id.no_record);
ScrollView scrollView = view.findViewById(R.id.scroll_view);
TextView textView = view.findViewById(R.id.text_content);
Provider provider = BaseApplication.of(activity).getProvider();
if (mSvProvider != null) {
mSvProvider.dispose();
}
mSvProvider = Provider.createProvider(activity.getApplicationContext(), new RxProviderModule());
FileHelper fileHelper = provider.get(FileHelper.class);
File logFile = fileHelper.getLogFile();
FloatingActionButton fabClear = view.findViewById(R.id.fab_clear);
FloatingActionButton fabShare = view.findViewById(R.id.fab_share);
fabShare.setOnClickListener(v -> {
try {
UiUtils.shareFile(activity, logFile, activity.getString(R.string.share_log_file));
} catch (Throwable e) {
provider.get(ILogger.class).e(TAG, activity.getString(R.string.error_sharing_log_file), e);
}
});
BehaviorSubject<File> subject = BehaviorSubject.createDefault(logFile);
fabClear.setOnClickListener(view1 -> {
fileHelper.clearLogFile();
provider.get(ILogger.class).i(TAG, activity.getString(R.string.log_file_deleted));
provider.get(Handler.class).post(() -> subject.onNext(logFile));
});
mSvProvider.get(RxDisposer.class).add("readLogFile", subject.observeOn(Schedulers.from(BaseApplication.of(activity).getProvider().get(ExecutorService.class))).map(file -> {
if (!file.exists()) {
return "";
} else {
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
char[] buff = new char[2048];
int b = bufferedReader.read(buff);
while (b != -1) {
stringBuilder.append(buff);
b = bufferedReader.read(buff);
}
return stringBuilder.toString();
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
progressBar.setVisibility(View.GONE);
textView.setText(s);
if (s.isEmpty()) {
noRecord.setVisibility(View.VISIBLE);
scrollView.setVisibility(View.GONE);
fabShare.setVisibility(View.GONE);
fabClear.setVisibility(View.GONE);
} else {
noRecord.setVisibility(View.GONE);
scrollView.setVisibility(View.VISIBLE);
scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN));
fabShare.setVisibility(View.VISIBLE);
fabClear.setVisibility(View.VISIBLE);
}
}));
return view;
}
use of io.reactivex.rxjava3.subjects.BehaviorSubject in project RxJava by ReactiveX.
the class ObservableDoOnUnsubscribeTest method noReentrantDispose.
@Test
public void noReentrantDispose() {
final AtomicInteger disposeCalled = new AtomicInteger();
final BehaviorSubject<Integer> s = BehaviorSubject.create();
s.doOnDispose(new Action() {
@Override
public void run() throws Exception {
disposeCalled.incrementAndGet();
s.onNext(2);
}
}).firstOrError().subscribe().dispose();
assertEquals(1, disposeCalled.get());
}
Aggregations