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();
}
}
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();
}
});
}
}
Aggregations