Search in sources :

Example 66 with Action0

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");
        }
    });
}
Also used : Action0(rx.functions.Action0) ProgressDialog(android.app.ProgressDialog) InjectView(butterknife.InjectView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextPointView(com.wingjay.jianshi.ui.widget.TextPointView) MultipleRowTextView(com.wingjay.jianshi.ui.widget.MultipleRowTextView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ShareContent(com.wingjay.jianshi.bean.ShareContent) Func1(rx.functions.Func1) File(java.io.File) Pair(android.util.Pair) OnClick(butterknife.OnClick)

Example 67 with Action0

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);
        }
    });
}
Also used : Action0(rx.functions.Action0) ActionBarProvider(com.bluelinelabs.conductor.demo.ActionBarProvider)

Example 68 with Action0

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);
        }
    });
}
Also used : Action0(rx.functions.Action0) ArrayList(java.util.ArrayList) File(java.io.File) OnClick(butterknife.OnClick)

Example 69 with Action0

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);
}
Also used : LzyResponse(com.lzy.demo.model.LzyResponse) Action0(rx.functions.Action0) ServerModel(com.lzy.demo.model.ServerModel) Subscription(rx.Subscription) OnClick(butterknife.OnClick)

Example 70 with Action0

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();
            }
        }
    }));
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) Action0(rx.functions.Action0)

Aggregations

Action0 (rx.functions.Action0)134 Subscription (rx.Subscription)58 Test (org.junit.Test)56 CountDownLatch (java.util.concurrent.CountDownLatch)50 Action1 (rx.functions.Action1)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ArrayList (java.util.ArrayList)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 List (java.util.List)15 Func1 (rx.functions.Func1)13 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)12 Observable (rx.Observable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 OnClick (butterknife.OnClick)10 IOException (java.io.IOException)9 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)8 UiThreadTest (android.support.test.annotation.UiThreadTest)7 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)7 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)7 Method (java.lang.reflect.Method)7