use of app.philm.in.model.PhilmAccount in project philm by chrisbanes.
the class AndroidAccountManager method removeAccount.
@Override
public void removeAccount(PhilmAccount philmAccount) {
Account account = new Account(philmAccount.getAccountName(), Constants.TRAKT_ACCOUNT_TYPE);
mAccountManager.removeAccount(account, null, null);
}
use of app.philm.in.model.PhilmAccount in project philm by chrisbanes.
the class AndroidAccountManager method getAccounts.
@Override
public List<PhilmAccount> getAccounts() {
final Account[] accounts = mAccountManager.getAccountsByType(Constants.TRAKT_ACCOUNT_TYPE);
ArrayList<PhilmAccount> philmAccounts = new ArrayList<>(accounts.length);
for (int i = 0; i < accounts.length; i++) {
final Account account = accounts[i];
String password = mAccountManager.getPassword(account);
philmAccounts.add(new PhilmAccount(account.name, password));
}
return philmAccounts;
}
use of app.philm.in.model.PhilmAccount in project philm by chrisbanes.
the class AndroidAccountManager method addAccount.
@Override
public void addAccount(PhilmAccount philmAccount) {
Account account = new Account(philmAccount.getAccountName(), Constants.TRAKT_ACCOUNT_TYPE);
mAccountManager.addAccountExplicitly(account, philmAccount.getPassword(), null);
mAccountManager.setAuthToken(account, philmAccount.getAuthToken(), philmAccount.getAuthTokenType());
}
use of app.philm.in.model.PhilmAccount in project philm by chrisbanes.
the class UserController method onInited.
@Override
protected void onInited() {
super.onInited();
mUserState.registerForEvents(this);
PhilmAccount account = mUserState.getCurrentAccount();
List<PhilmAccount> accounts = mPhilmAccountManager.getAccounts();
if (account == null) {
if (!PhilmCollections.isEmpty(accounts)) {
mUserState.setCurrentAccount(accounts.get(0));
}
} else {
// Try and find account in account list, if removed, remove our reference
boolean found = false;
for (int i = 0, z = accounts.size(); i < z; i++) {
if (Objects.equal(accounts.get(i).getAccountName(), account.getAccountName())) {
found = true;
break;
}
}
if (!found) {
mUserState.setCurrentAccount(null);
}
}
}
use of app.philm.in.model.PhilmAccount in project philm by chrisbanes.
the class UserController method onAccountChanged.
@Subscribe
public void onAccountChanged(UserState.AccountChangedEvent event) {
PhilmAccount currentAccount = mUserState.getCurrentAccount();
if (currentAccount != null) {
final String username = currentAccount.getAccountName();
mUserState.setUsername(username);
mTraktClient.setAuthentication(username, currentAccount.getPassword());
mDbHelper.getUserProfile(username, new UserProfileDbLoadCallback());
} else {
mUserState.setUsername(null);
mTraktClient.setAuthentication(null, null);
final PhilmUserProfile currentUserProfile = mUserState.getUserProfile();
if (currentUserProfile != null) {
mUserState.setUserProfile(null);
mDbHelper.delete(currentUserProfile);
}
// TODO: Also nuke rest of state
}
mLogger.d(LOG_TAG, "onAccountChanged: " + mUserState.getUsername());
}
Aggregations