Search in sources :

Example 1 with AccountBean

use of org.aisen.weibo.sina.support.bean.AccountBean in project AisenWeiBo by wangdan.

the class WeiboClientActivity method fillAccount.

private void fillAccount() {
    final String url = "http://passport.weibo.cn/signin/login?";
    new WorkTask<Void, Void, String>() {

        @Override
        protected void onPrepare() {
            super.onPrepare();
            ViewUtils.createProgressDialog(WeiboClientActivity.this, getString(R.string.account_fillaccount_loading), ThemeUtils.getThemeColor()).show();
        }

        @Override
        public String workInBackground(Void... p) throws TaskException {
            try {
                AccountBean accountBean = AccountUtils.getLogedinAccount();
                if (TextUtils.isEmpty(accountBean.getAccount()) || TextUtils.isEmpty(accountBean.getPassword()))
                    throw new TaskException("", getString(R.string.account_fillaccount_faild));
                String js = FileUtils.readAssetsFile("mobile.js", GlobalContext.getInstance());
                js = js.replace("%username%", accountBean.getAccount());
                js = js.replace("%password%", accountBean.getPassword());
                Document dom = Jsoup.connect(url).get();
                String html = dom.toString();
                html = html.replace("</head>", js + "</head>");
                return html;
            } catch (Exception e) {
                e.printStackTrace();
            }
            throw new TaskException("", getString(R.string.account_fillaccount_faild));
        }

        @Override
        protected void onSuccess(String s) {
            super.onSuccess(s);
            Logger.e(s);
            mWebView.loadDataWithBaseURL("http://passport.weibo.cn", s, "text/html", "UTF-8", "");
            GlobalContext.getInstance().getHandler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mWebView.loadUrl("javascript:fillAccount()");
                    ViewUtils.dismissProgressDialog();
                }
            }, 1500);
        }

        @Override
        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            showMessage(exception.getMessage());
            ViewUtils.dismissProgressDialog();
        }
    }.execute();
}
Also used : TaskException(org.aisen.android.network.task.TaskException) AccountBean(org.aisen.weibo.sina.support.bean.AccountBean) Document(org.jsoup.nodes.Document) TaskException(org.aisen.android.network.task.TaskException)

Example 2 with AccountBean

use of org.aisen.weibo.sina.support.bean.AccountBean in project AisenWeiBo by wangdan.

the class BizFragment method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        // 请求授权
        if (requestCode == REQUEST_CODE_AD_AUTH) {
            AccountBean accountBean = (AccountBean) data.getSerializableExtra("account");
            AppContext.getAccount().setAdvancedToken(accountBean.getAccessToken());
            AccountUtils.newAccount(AppContext.getAccount());
            AccountUtils.setLogedinAccount(AppContext.getAccount());
            if (checkAdTokenAction != null) {
                checkAdTokenAction.run();
            }
        } else // 处理点赞
        if (123123 == requestCode) {
            if (requestWebLoginAction != null) {
                requestWebLoginAction.run();
            }
        }
    }
    checkAdTokenAction = null;
    requestWebLoginAction = null;
}
Also used : AccountBean(org.aisen.weibo.sina.support.bean.AccountBean)

Example 3 with AccountBean

use of org.aisen.weibo.sina.support.bean.AccountBean in project AisenWeiBo by wangdan.

the class MenuHeaderView method setAccountViews.

private void setAccountViews(final List<AccountBean> accounts, final View view, final int index) {
    ImageView image = (ImageView) view.findViewById(R.id.imgAccount);
    ImageView cover = (ImageView) view.findViewById(R.id.imgCover);
    ColorDrawable grayDrawable = new ColorDrawable(Color.parseColor("#29000000"));
    cover.setImageDrawable(grayDrawable);
    view.setVisibility(accounts.size() >= index + 1 ? View.VISIBLE : View.GONE);
    if (view.getVisibility() == View.VISIBLE) {
        BitmapLoader.getInstance().display(menuFragment, accounts.get(index).getUser().getAvatar_large(), image, ImageConfigUtils.getLargePhotoConfig());
        view.setTag(accounts.get(index));
        view.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                UMengUtil.onEvent(menuFragment.getActivity(), "menuheader_account_change");
                AccountBean account = (AccountBean) v.getTag();
                changeAccount(account, v);
            }
        });
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ImageView(android.widget.ImageView) AccountBean(org.aisen.weibo.sina.support.bean.AccountBean) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 4 with AccountBean

use of org.aisen.weibo.sina.support.bean.AccountBean in project AisenWeiBo by wangdan.

the class MainActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_AUTH) {
        if (resultCode == Activity.RESULT_OK) {
            AccountBean accountBean = (AccountBean) data.getSerializableExtra("account");
            AppContext.getAccount().setAccessToken(accountBean.getAccessToken());
            if (accountBean.getUser() != null) {
                AppContext.getAccount().setUser(accountBean.getUser());
            }
            if (accountBean.getGroups() != null) {
                AppContext.getAccount().setGroups(accountBean.getGroups());
            }
            AccountUtils.newAccount(AppContext.getAccount());
            AccountUtils.setLogedinAccount(AppContext.getAccount());
            login();
        }
    }
}
Also used : AccountBean(org.aisen.weibo.sina.support.bean.AccountBean)

Example 5 with AccountBean

use of org.aisen.weibo.sina.support.bean.AccountBean in project AisenWeiBo by wangdan.

the class AccountFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
    final AccountBean account = getAdapterItems().get(position);
    // 重新授权Aisen
    if (account.getAccessToken() == null || account.getAccessToken().isExpired()) {
        new MaterialDialog.Builder(getActivity()).title(R.string.remind).content(R.string.account_expired).positiveText(R.string.confirm).onPositive(new MaterialDialog.SingleButtonCallback() {

            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                WebLoginFragment.launch(AccountFragment.this, WebLoginFragment.Client.aisen, account.getAccount(), account.getPassword(), BizFragment.REQUEST_CODE_AUTH);
            }
        }).show();
        return;
    }
    login(getActivity(), account, true);
    getActivity().finish();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) AccountBean(org.aisen.weibo.sina.support.bean.AccountBean)

Aggregations

AccountBean (org.aisen.weibo.sina.support.bean.AccountBean)5 ColorDrawable (android.graphics.drawable.ColorDrawable)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 TaskException (org.aisen.android.network.task.TaskException)1 Document (org.jsoup.nodes.Document)1