use of rx.functions.Action0 in project jianshi by wingjay.
the class ViewActivity method share.
@OnClick(R.id.view_share)
void share() {
Blaster.log(LoggingData.BTN_CLK_SHARE_DIARY_IMAGE);
final View target = verticalStyle ? container : normalContainer;
final ProgressDialog dialog = ProgressDialog.show(this, "", "加载中...");
screenshotManager.shotScreen(target, "temp.jpg").observeOn(Schedulers.io()).filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return !TextUtils.isEmpty(s);
}
}).flatMap(new Func1<String, Observable<Pair<String, ShareContent>>>() {
@Override
public Observable<Pair<String, ShareContent>> call(String path) {
Timber.i("ViewActivity ScreenshotManager 1 %s", Thread.currentThread().getName());
ShareContent shareContent = new ShareContent();
try {
JsonDataResponse<ShareContent> response = userService.getShareContent().toBlocking().first();
if (response.getRc() == Constants.ServerResultCode.RESULT_OK && response.getData() != null) {
shareContent = response.getData();
}
} catch (Exception e) {
Timber.e(e, "getShareContent() error");
return Observable.just(Pair.create(path, shareContent));
}
return Observable.just(Pair.create(path, shareContent));
}
}).observeOn(AndroidSchedulers.mainThread()).doOnTerminate(new Action0() {
@Override
public void call() {
dialog.dismiss();
}
}).subscribe(new Action1<Pair<String, ShareContent>>() {
@Override
public void call(Pair<String, ShareContent> stringShareContentPair) {
Timber.i("ViewActivity ScreenshotManager 2 %s", Thread.currentThread().getName());
if (!isUISafe()) {
return;
}
IntentUtil.shareLinkWithImage(ViewActivity.this, stringShareContentPair.second, Uri.fromFile(new File(stringShareContentPair.first)));
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
makeToast(getString(R.string.share_failure));
Timber.e(throwable, "screenshot share failure");
}
});
}
use of rx.functions.Action0 in project Conductor by bluelinelabs.
the class RxLifecycleController method onAttach.
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
Log.i(TAG, "onAttach() called");
(((ActionBarProvider) getActivity()).getSupportActionBar()).setTitle("RxLifecycle Demo");
Observable.interval(1, TimeUnit.SECONDS).doOnUnsubscribe(new Action0() {
@Override
public void call() {
Log.i(TAG, "Unsubscribing from onAttach()");
}
}).compose(this.<Long>bindUntilEvent(ControllerEvent.DETACH)).subscribe(new Action1<Long>() {
@Override
public void call(Long num) {
Log.i(TAG, "Started in onAttach(), running until onDetach(): " + num);
}
});
}
use of rx.functions.Action0 in project okhttp-OkGo by jeasonlzy.
the class RxFormUploadActivity method formUpload.
@OnClick(R.id.formUpload)
public void formUpload(View view) {
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));
}
}
//拼接参数
//
OkGo.post(Urls.URL_FORM_UPLOAD).tag(//
this).headers("header1", //
"headerValue1").headers("header2", //
"headerValue2").params("param1", //
"paramValue1").params("param2", //
"paramValue2").addFileParams("file", // 这种方式为同一个key,上传多个文件
files).getCall(StringConvert.create(), //
RxAdapter.<String>create()).doOnSubscribe(new Action0() {
@Override
public void call() {
btnFormUpload.setText("正在上传中...\n使用Rx方式做进度监听稍显麻烦,推荐使用回调方式");
}
}).observeOn(//切换到主线程
AndroidSchedulers.mainThread()).subscribe(new Action1<String>() {
@Override
public void call(String s) {
btnFormUpload.setText("上传完成");
handleResponse(s, null, null);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
throwable.printStackTrace();
btnFormUpload.setText("上传出错");
showToast("请求失败");
handleError(null, null);
}
});
}
use of rx.functions.Action0 in project okhttp-OkGo by jeasonlzy.
the class RxCommonActivity method jsonRequest.
@OnClick(R.id.jsonRequest)
public void jsonRequest(View view) {
Subscription subscription = //
OkGo.post(Urls.URL_JSONOBJECT).headers("aaa", //
"111").params("bbb", //一定要注意这里的写法,JsonConvert最后的大括号千万不能忘记
"222").getCall(new JsonConvert<LzyResponse<ServerModel>>() {
}, //
RxAdapter.<LzyResponse<ServerModel>>create()).doOnSubscribe(new Action0() {
@Override
public void call() {
showLoading();
}
}).map(new Func1<LzyResponse<ServerModel>, ServerModel>() {
@Override
public ServerModel call(LzyResponse<ServerModel> response) {
return response.data;
}
}).observeOn(//
AndroidSchedulers.mainThread()).subscribe(new Action1<ServerModel>() {
@Override
public void call(ServerModel serverModel) {
//请求成功
dismissLoading();
handleResponse(serverModel, null, null);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
//请求失败
throwable.printStackTrace();
showToast("请求失败");
dismissLoading();
handleError(null, null);
}
});
addSubscribe(subscription);
}
use of rx.functions.Action0 in project Android-ReactiveLocation by mcharmas.
the class BaseObservable method call.
@Override
public void call(Subscriber<? super T> subscriber) {
final GoogleApiClient apiClient = createApiClient(subscriber);
try {
apiClient.connect();
} catch (Throwable ex) {
subscriber.onError(ex);
}
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
}
}));
}
Aggregations