Search in sources :

Example 36 with TaskException

use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.

the class MenuHeaderView method setupHeaderView.

public void setupHeaderView(Context context, FrameLayout parent) {
    LayoutInflater inflater = LayoutInflater.from(menuFragment.getActivity());
    // 初始化View
    if (mHeaderView == null) {
        mHeaderView = inflater.inflate(R.layout.layout_menu_header, parent, false);
        int height = GlobalContext.getInstance().getResources().getDimensionPixelSize(R.dimen.material_drawer_account_header_height);
        if (Build.VERSION.SDK_INT >= 19) {
            height += SystemUtils.getStatusBarHeight(menuFragment.getActivity());
        }
        parent.addView(mHeaderView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height));
        // 绑定视图
        InjectUtility.initInjectedView(context, this, mHeaderView);
    }
    View view = mHeaderView.findViewById(R.id.material_drawer_account_header);
    if (Build.VERSION.SDK_INT >= 19) {
        view.setPadding(view.getPaddingStart(), SystemUtils.getStatusBarHeight(menuFragment.getActivity()), view.getPaddingRight(), view.getPaddingBottom());
    }
    final WeiBoUser user = AppContext.getAccount().getUser();
    // 头像
    ImageView imgPhoto = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_current);
    imgPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (txtFollowersNewHint != null && txtFollowersNewHint.getVisibility() == View.VISIBLE) {
                ((MainActivity) menuFragment.getActivity()).closeDrawer();
                FriendshipPagerFragment.launch(menuFragment.getActivity(), AppContext.getAccount().getUser(), 1);
            } else {
                BizFragment.createBizFragment(menuFragment).launchProfile(AppContext.getAccount().getUser());
            }
        }
    });
    BitmapLoader.getInstance().display(menuFragment, user.getAvatar_large(), imgPhoto, ImageConfigUtils.getLargePhotoConfig());
    // 名字
    TextView txtName = (TextView) mHeaderView.findViewById(R.id.material_drawer_account_header_name);
    txtName.setText(user.getScreen_name());
    // 背景
    final ImageView imgCover = (ImageView) mHeaderView.findViewById(R.id.material_drawer_account_header_background);
    new WorkTask<Void, Void, Bitmap>() {

        @Override
        public Bitmap workInBackground(Void... params) throws TaskException {
            try {
                BitmapLoader.BitmapBytesAndFlag bitmapBytesAndFlag = BitmapLoader.getInstance().doDownload(user.getCover_image_phone(), new ImageConfig());
                return BitmapFactory.decodeByteArray(bitmapBytesAndFlag.bitmapBytes, 0, bitmapBytesAndFlag.bitmapBytes.length);
            } catch (Exception e) {
            }
            throw new TaskException("", "");
        }

        @Override
        protected void onSuccess(Bitmap bitmap) {
            super.onSuccess(bitmap);
            new FadeInDisplayer().loadCompletedisplay(imgCover, new BitmapDrawable(GlobalContext.getInstance().getResources(), bitmap));
        }

        @Override
        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            imgCover.setImageDrawable(new BitmapDrawable(GlobalContext.getInstance().getResources(), BitmapFactory.decodeResource(GlobalContext.getInstance().getResources(), R.drawable.bg_banner_dialog)));
        }
    }.execute();
    // 显示账号
    mHeaderView.findViewById(R.id.material_drawer_account_header_text_section).setOnClickListener(this);
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) FadeInDisplayer(org.aisen.android.component.bitmaploader.display.FadeInDisplayer) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TaskException(org.aisen.android.network.task.TaskException) Bitmap(android.graphics.Bitmap) TaskException(org.aisen.android.network.task.TaskException) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 37 with TaskException

use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.

the class TimelinePicActivity method parseShortUrl.

private void parseShortUrl(final String url) {
    while (BizFragment.createBizFragment(this).getActivity() == null) {
    }
    // 检测Cookie
    new IAction(this, new WebLoginAction(this, BizFragment.createBizFragment(this))) {

        @Override
        public void doAction() {
            new WorkTask<Void, Integer, String>() {

                @Override
                protected void onProgressUpdate(Integer... values) {
                    super.onProgressUpdate(values);
                    if (values != null && values[0] == 100) {
                        ViewUtils.createProgressDialog(TimelinePicActivity.this, "正在解析图片", ThemeUtils.getThemeColor()).show();
                    }
                }

                @Override
                public String workInBackground(Void... params) throws TaskException {
                    String id = KeyGenerator.generateMD5(url);
                    VideoBean videoBean = SinaDB.getDB().selectById(null, VideoBean.class, id);
                    if (videoBean == null) {
                        videoBean = new VideoBean();
                        videoBean.setIdStr(id);
                        videoBean.setShortUrl(url);
                    }
                    // 根据短链接解析
                    if (TextUtils.isEmpty(videoBean.getImage())) {
                        try {
                            publishProgress(100);
                            VideoService.getPicture(videoBean);
                        } catch (Exception e) {
                            throw new TaskException("");
                        }
                    }
                    if (TextUtils.isEmpty(videoBean.getImage())) {
                        throw new TaskException("");
                    }
                    SinaDB.getDB().update(null, videoBean);
                    return videoBean.getImage();
                }

                @Override
                protected void onFailure(TaskException exception) {
                    super.onFailure(exception);
                    if (isDestory())
                        return;
                    new MaterialDialog.Builder(TimelinePicActivity.this).forceStacking(true).content(R.string.video_short_faild).positiveText(R.string.video2browser).negativeText(R.string.video_again).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            toBrowser(url);
                        }
                    }).onNegative(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(MaterialDialog dialog, DialogAction which) {
                            loadPicture(url);
                        }
                    }).show();
                }

                @Override
                protected void onSuccess(String s) {
                    super.onSuccess(s);
                    if (isDestory())
                        return;
                    loadPicture(s);
                }

                @Override
                protected void onFinished() {
                    super.onFinished();
                    ViewUtils.dismissProgressDialog();
                }
            }.execute();
        }
    }.run();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IAction(org.aisen.android.support.action.IAction) TaskException(org.aisen.android.network.task.TaskException) TaskException(org.aisen.android.network.task.TaskException) VideoBean(org.aisen.weibo.sina.support.bean.VideoBean) DialogAction(com.afollestad.materialdialogs.DialogAction) WorkTask(org.aisen.android.network.task.WorkTask) WebLoginAction(org.aisen.weibo.sina.support.action.WebLoginAction)

Example 38 with TaskException

use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.

the class PictureFragment method loadPicture.

void loadPicture(View v) {
    // 下载路径
    String url = null;
    Uri uri = Uri.parse(image.getThumbnail_pic());
    ImageConfig config = new ImageConfig();
    File file = origFile;
    // 原图存在,就下载原图
    if (file.exists()) {
        url = getOrigImage();
    } else // 原图不存在,就下载中图
    {
        file = BitmapLoader.getInstance().getCacheFile(getImage());
        config.setId("Picture");
        url = getImage();
        pictureSize = SinaDB.getDB().selectById(null, PictureSize.class, getOrigImage());
        if (pictureSize == null)
            new LoadPictureSizeTask().execute();
    }
    if (!file.exists()) {
        progressView.setVisibility(View.VISIBLE);
        // 如果网络不是WIFI,且原图和中图都没缓存,那么只加载当前看的那个图片
        if (SystemUtils.NetWorkType.wifi != SystemUtils.getNetworkType(getActivity())) {
            if (getActivity() instanceof PicsActivity) {
                PicsActivity picsActivity = (PicsActivity) getActivity();
                if (!picsActivity.getCurrent().getThumbnail_pic().equalsIgnoreCase(image.getThumbnail_pic()))
                    return;
            } else if (getActivity() instanceof PhotosActivity) {
                PhotosActivity picsActivity = (PhotosActivity) getActivity();
                if (!picsActivity.getCurrent().getThumbnail_pic().equalsIgnoreCase(image.getThumbnail_pic()))
                    return;
            }
        }
    }
    viewFailure.setVisibility(View.GONE);
    if ("file".equals(uri.getScheme().toLowerCase())) {
        url = uri.getPath();
        final File origF = new File(url);
        new WorkTask<Void, Void, byte[]>() {

            @Override
            public byte[] workInBackground(Void... params) throws TaskException {
                return FileUtils.readFileToBytes(origF);
            }

            @Override
            protected void onSuccess(byte[] bytes) {
                super.onSuccess(bytes);
                onDownloadPicture(bytes, origF);
                mStatus = PictureStatus.success;
            }
        }.execute();
    } else {
        ImageView imgView = new ImageView(getActivity());
        config.setProgress(new PictureDownloadProgress(file));
        BitmapLoader.getInstance().display(null, url, imgView, config);
    }
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) PicsActivity(org.aisen.weibo.sina.ui.activity.picture.PicsActivity) Uri(android.net.Uri) PictureSize(org.aisen.weibo.sina.support.bean.PictureSize) TaskException(org.aisen.android.network.task.TaskException) ImageView(android.widget.ImageView) File(java.io.File) PhotosActivity(org.aisen.weibo.sina.ui.activity.picture.PhotosActivity)

Example 39 with TaskException

use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.

the class BizFragment method destoryFriendship.

/* 结束查看用户微博 */
// XXX /*取消对某用户的关注*/
public void destoryFriendship(final WeiBoUser user, final OnDestoryFriendshipCallback callback) {
    Token token = AppContext.getAccount().getAccessToken();
    if (AppContext.getAccount().getAdvancedToken() != null)
        token = AppContext.getAccount().getAdvancedToken();
    final Token trueToken = token;
    new MaterialDialog.Builder(getRealActivity()).content(R.string.biz_destory_friend).negativeText(R.string.no).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            new WorkTask<Void, Void, WeiBoUser>() {

                @Override
                public WeiBoUser workInBackground(Void... params) throws TaskException {
                    return SinaSDK.getInstance(trueToken).friendshipsDestroy(user.getIdstr());
                }

                @Override
                protected void onPrepare() {
                    super.onPrepare();
                    ViewUtils.createProgressDialog(getRealActivity(), getRealString(R.string.biz_destory_friendship), ThemeUtils.getThemeColor()).show();
                }

                @Override
                protected void onFailure(TaskException exception) {
                    super.onFailure(exception);
                    showMessage(exception.getMessage());
                }

                @Override
                protected void onSuccess(WeiBoUser result) {
                    super.onSuccess(result);
                    if (getRealActivity() == null) {
                        return;
                    }
                    callback.onFriendshipDestoryed(result);
                }

                @Override
                protected void onFinished() {
                    super.onFinished();
                    if (getRealActivity() == null) {
                        return;
                    }
                    ViewUtils.dismissProgressDialog();
                }
            }.execute();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TaskException(org.aisen.android.network.task.TaskException) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) Token(org.aisen.weibo.sina.sinasdk.bean.Token)

Example 40 with TaskException

use of org.aisen.android.network.task.TaskException in project AisenWeiBo by wangdan.

the class BizFragment method statusDestory.

/* 结束回复评论 */
// XXX /*删除微博*/
/* 开始删除微博 */
public void statusDestory(final String id, final OnStatusDestoryCallback callback) {
    final WeiBoUser user = AppContext.getAccount().getUser();
    new WorkTask<String, Void, StatusContent>() {

        protected void onPrepare() {
            super.onPrepare();
            ViewUtils.createProgressDialog(getRealActivity(), getRealString(R.string.biz_delete_status_loading), ThemeUtils.getThemeColor()).show();
        }

        protected void onFinished() {
            super.onFinished();
            ViewUtils.dismissProgressDialog();
        }

        protected void onSuccess(StatusContent result) {
            super.onSuccess(result);
            if (getRealActivity() == null) {
                return;
            }
            callback.onStatusDestory(result);
            showMessage(R.string.delete_success);
            SinaDB.getTimelineDB().deleteById(new Extra(user.getIdstr(), null), StatusContent.class, result.getId());
        }

        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            if (getRealActivity() == null) {
                return;
            }
            if (exception != null && "20101".equals(exception.getMessage())) {
                StatusContent status = new StatusContent();
                status.setId(Long.parseLong(id));
                onSuccess(status);
            } else if (!callback.onFaild(exception)) {
                showMessage(exception.getMessage());
            }
        }

        @Override
        public StatusContent workInBackground(String... params) throws TaskException {
            return SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).statusDestroy(params[0]);
        }
    }.execute(id);
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) Extra(org.aisen.android.component.orm.extra.Extra) TaskException(org.aisen.android.network.task.TaskException) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)

Aggregations

TaskException (org.aisen.android.network.task.TaskException)45 Setting (org.aisen.android.common.setting.Setting)11 Params (org.aisen.android.network.http.Params)10 File (java.io.File)9 HttpConfig (org.aisen.android.network.http.HttpConfig)8 WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)8 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)7 DialogAction (com.afollestad.materialdialogs.DialogAction)6 JSONArray (com.alibaba.fastjson.JSONArray)6 JSONObject (com.alibaba.fastjson.JSONObject)6 ParseException (java.text.ParseException)6 Bitmap (android.graphics.Bitmap)5 ImageView (android.widget.ImageView)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)4 View (android.view.View)3 Request (com.squareup.okhttp.Request)3 Response (com.squareup.okhttp.Response)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3