Search in sources :

Example 1 with AccessTokenManager

use of com.codez.collar.auth.AccessTokenManager in project Collar by CodeZsx.

the class LoginActivity method handleRedirectedUrl.

private void handleRedirectedUrl(String url) {
    if (!url.contains("error")) {
        int accessTokenIndex = url.indexOf("access_token=");
        int expiresInIndex = url.indexOf("expires_in=");
        int refreshTokenIndex = url.indexOf("refresh_token=");
        int uidIndex = url.indexOf("uid=");
        String accessToken = url.substring(accessTokenIndex + 13, url.indexOf("&", accessTokenIndex));
        String expiresIn = url.substring(expiresInIndex + 11, url.indexOf("&", expiresInIndex));
        String refreshToken = url.substring(refreshTokenIndex + 14, url.indexOf("&", refreshTokenIndex));
        String uid = new String();
        if (url.contains("scope=")) {
            uid = url.substring(uidIndex + 4, url.indexOf("&", uidIndex));
        } else {
            uid = url.substring(uidIndex + 4);
        }
        AccessTokenManager accessTokenManager = new AccessTokenManager();
        accessTokenManager.addToken(this, accessToken, expiresIn, refreshToken, uid);
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        // intent.putExtra("fisrtstart", true);
        if (isComeFromAccountAty) {
            intent.putExtra("comeFromAccoutActivity", true);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
        startActivity(intent);
        finish();
    }
}
Also used : AccessTokenManager(com.codez.collar.auth.AccessTokenManager) Intent(android.content.Intent)

Example 2 with AccessTokenManager

use of com.codez.collar.auth.AccessTokenManager in project Collar by CodeZsx.

the class AccountActivity method loadData.

private void loadData() {
    if (!AccessTokenKeeper.getInstance().readAccessToken().isSessionsValid()) {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }
    AccessTokenManager manager = new AccessTokenManager();
    TokenList tokenList = manager.getTokenList(this);
    final List<Token> lists = tokenList.getTokenList();
    for (Token token : lists) {
        HttpUtils.getInstance().getUserService().getUserInfo(token.getUid(), null).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<UserBean>() {

            @Override
            public void onCompleted() {
                L.e("onCompleted");
            }

            @Override
            public void onError(Throwable e) {
                L.e("onError");
            }

            @Override
            public void onNext(UserBean userBean) {
                mAdapter.add(userBean);
                mAdapter.notifyDataSetChanged();
            }
        });
    }
}
Also used : AccessTokenManager(com.codez.collar.auth.AccessTokenManager) UserBean(com.codez.collar.bean.UserBean) Intent(android.content.Intent) TokenList(com.codez.collar.bean.TokenList) Token(com.codez.collar.bean.Token)

Aggregations

Intent (android.content.Intent)2 AccessTokenManager (com.codez.collar.auth.AccessTokenManager)2 Token (com.codez.collar.bean.Token)1 TokenList (com.codez.collar.bean.TokenList)1 UserBean (com.codez.collar.bean.UserBean)1