Search in sources :

Example 1 with ShareContent

use of com.wingjay.jianshi.bean.ShareContent 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)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 Pair (android.util.Pair)1 View (android.view.View)1 HorizontalScrollView (android.widget.HorizontalScrollView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 OnClick (butterknife.OnClick)1 ShareContent (com.wingjay.jianshi.bean.ShareContent)1 MultipleRowTextView (com.wingjay.jianshi.ui.widget.MultipleRowTextView)1 TextPointView (com.wingjay.jianshi.ui.widget.TextPointView)1 File (java.io.File)1 Action0 (rx.functions.Action0)1 Func1 (rx.functions.Func1)1