use of com.winsonchiu.reader.data.reddit.User in project Reader by TheKeeperOfPie.
the class ActivityLogin method loadAccountInfo.
private void loadAccountInfo(final String tokenAuth, final String tokenRefresh, final long timeExpire) {
Request request = new Request.Builder().url(Reddit.OAUTH_URL + "/api/v1/me").header(Reddit.USER_AGENT, Reddit.CUSTOM_USER_AGENT).header(Reddit.AUTHORIZATION, Reddit.BEARER + tokenAuth).header(Reddit.CONTENT_TYPE, Reddit.CONTENT_TYPE_APP_JSON).get().build();
reddit.load(request).flatMap(UtilsRx.flatMapWrapError(response -> User.fromJson(ComponentStatic.getObjectMapper().readValue(response, JsonNode.class)))).subscribe(new FinalizingSubscriber<User>() {
@Override
public void next(User user) {
Account account = new Account(user.getName(), Reddit.ACCOUNT_TYPE);
Intent result = new Intent();
result.putExtra(AccountManager.KEY_ACCOUNT_NAME, user.getName());
result.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Reddit.ACCOUNT_TYPE);
result.putExtra(AccountManager.KEY_AUTHTOKEN, tokenAuth);
if (getIntent().getBooleanExtra(KEY_IS_NEW_ACCOUNT, false)) {
Bundle extras = new Bundle();
extras.putString(KEY_TIME_EXPIRATION, String.valueOf(timeExpire));
accountManager.addAccountExplicitly(account, tokenRefresh, extras);
accountManager.setAuthToken(account, Reddit.AUTH_TOKEN_FULL_ACCESS, tokenAuth);
}
destroyWebView();
setAccountAuthenticatorResult(result.getExtras());
setResult(RESULT_OK, result);
ActivityLogin.this.finish();
}
});
}
use of com.winsonchiu.reader.data.reddit.User in project Reader by TheKeeperOfPie.
the class ControllerUser method setAccount.
public void setAccount(Account accountUser) {
boolean accountFound = false;
Account[] accounts = accountManager.getAccountsByType(Reddit.ACCOUNT_TYPE);
for (Account account : accounts) {
if (account.name.equals(accountUser.name)) {
this.account = account;
accountFound = true;
reloadUser();
break;
}
}
user = new User();
if (!accountFound) {
account = null;
} else {
user.setName(account.name);
}
}
use of com.winsonchiu.reader.data.reddit.User in project Reader by TheKeeperOfPie.
the class ControllerUser method clearAccount.
public void clearAccount() {
account = null;
user = new User();
for (Listener listener : listeners) {
listener.onUserLoaded(null);
}
}