use of io.reactivex.ObservableOnSubscribe in project RxCache by VictorAlbertos.
the class ProcessorProvidersTest method getSubscriberCompleted.
private TestObserver getSubscriberCompleted(boolean hasCache, final boolean evictCache, boolean detailResponse, Loader loader, boolean useExpiredDataIfLoaderNotAvailable) {
Observable observable;
switch(loader) {
case VALID:
observable = Observable.just(new Mock("message"));
break;
case NULL:
observable = Observable.error(new RuntimeException("No data"));
break;
default:
observable = Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> e) throws Exception {
throw new RuntimeException("error");
}
});
break;
}
ConfigProvider configProvider = new ConfigProvider("mockKey", null, null, detailResponse, true, false, "", "", observable, new EvictProvider(evictCache));
if (hasCache)
twoLayersCacheMock.save("mockKey", "", "", new Mock("message"), configProvider.getLifeTimeMillis(), configProvider.isExpirable(), configProvider.isEncrypted());
processorProvidersUT = new ProcessorProvidersBehaviour(twoLayersCacheMock, useExpiredDataIfLoaderNotAvailable, evictExpiredRecordsPersistence, getDeepCopy, doMigrations);
TestObserver observerMock = processorProvidersUT.getData(configProvider).test();
observerMock.awaitTerminalEvent();
return observerMock;
}
use of io.reactivex.ObservableOnSubscribe in project okhttp-OkGo by jeasonlzy.
the class RxFormUploadActivity method formUpload2.
@OnClick(R.id.formUpload2)
public void formUpload2(View view) {
final ArrayList<File> files = new ArrayList<>();
if (imageItems != null && imageItems.size() > 0) {
for (int i = 0; i < imageItems.size(); i++) {
files.add(new File(imageItems.get(i).path));
}
}
Observable.create(new ObservableOnSubscribe<Progress>() {
@Override
public void subscribe(@NonNull final ObservableEmitter<Progress> e) throws Exception {
//
OkGo.<String>post(Urls.URL_FORM_UPLOAD).tag(//
this).headers("header1", //
"headerValue1").headers("header2", //
"headerValue2").params("param1", //
"paramValue1").params("param2", //
"paramValue2").addFileParams("file", //
files).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
e.onComplete();
}
@Override
public void onError(Response<String> response) {
e.onError(response.getException());
}
@Override
public void uploadProgress(Progress progress) {
e.onNext(progress);
}
});
}
}).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
btnFormUpload2.setText("正在上传中...");
}
}).observeOn(//
AndroidSchedulers.mainThread()).subscribe(new Observer<Progress>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
addDisposable(d);
}
@Override
public void onNext(@NonNull Progress progress) {
System.out.println("uploadProgress: " + progress);
String downloadLength = Formatter.formatFileSize(getApplicationContext(), progress.currentSize);
String totalLength = Formatter.formatFileSize(getApplicationContext(), progress.totalSize);
tvDownloadSize.setText(downloadLength + "/" + totalLength);
String speed = Formatter.formatFileSize(getApplicationContext(), progress.speed);
tvNetSpeed.setText(String.format("%s/s", speed));
tvProgress.setText(numberFormat.format(progress.fraction));
pbProgress.setMax(10000);
pbProgress.setProgress((int) (progress.fraction * 10000));
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
btnFormUpload2.setText("上传出错");
showToast(e.getMessage());
}
@Override
public void onComplete() {
btnFormUpload2.setText("上传完成");
}
});
}
use of io.reactivex.ObservableOnSubscribe in project J2ME-Loader by nikita36078.
the class AppsListFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.main, menu);
final MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchViewDisposable = Observable.create((ObservableOnSubscribe<String>) emitter -> searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
emitter.onNext(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
emitter.onNext(newText);
return true;
}
})).debounce(300, TimeUnit.MILLISECONDS).map(String::toLowerCase).distinctUntilChanged().observeOn(AndroidSchedulers.mainThread()).subscribe(charSequence -> adapter.getFilter().filter(charSequence));
}
use of io.reactivex.ObservableOnSubscribe in project SmartCampus by Vegen.
the class EmploymentArticleDetailPresenter method getEmploymentList.
@Override
public void getEmploymentList(String url, int type) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
if (mView != null) {
mView.showEmploymentList(filterData(body, type));
mView.hideLoading(false);
if (type == Constant.FAIR)
mView.loadMoreEnd(true);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
use of io.reactivex.ObservableOnSubscribe in project SmartCampus by Vegen.
the class ArticleDetailPresenter method getNewsContent.
@Override
public void getNewsContent(String url) {
Disposable disposable = Observable.create((ObservableOnSubscribe<Document>) e -> {
Document document = Jsoup.connect(url).get();
e.onNext(document);
e.onComplete();
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(document -> {
Element body = document.body();
// 带有href属性的a元素
Elements links = body.select("a[href]");
for (Element element : links) {
element.attr("href", "");
}
Element author = body.select("#author").first();
Element contentbody = body.select("#contentbody").first();
Element showtag = body.select("#showtag").last();
if (mView != null) {
mView.showNewsContent("</br>" + (author.html() + contentbody.html() + showtag.html()).replace("font-size: 10.5pt", "font-size: 16.5pt").replace("FONT-SIZE: 10.5pt", "FONT-SIZE: 16.5pt").replace("src=\"/files", "src=\"" + Url.ROOT_URL + "/files").replace("href=\"\"", "").replace("【点击:", "【点击:" + SystemUtils.getRandom(5, 30)).replace("发布时间", "</br>发布时间"));
mView.hideLoading(false);
}
}, throwable -> {
if (mView != null) {
mView.showMessage(HttpError.getErrorMessage(throwable));
mView.hideLoading(true);
}
});
mHttpLinkers.add(new DisposableHolder(disposable));
}
Aggregations