Search in sources :

Example 1 with PhilmAccount

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);
}
Also used : Account(android.accounts.Account) PhilmAccount(app.philm.in.model.PhilmAccount)

Example 2 with PhilmAccount

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;
}
Also used : Account(android.accounts.Account) PhilmAccount(app.philm.in.model.PhilmAccount) ArrayList(java.util.ArrayList) PhilmAccount(app.philm.in.model.PhilmAccount)

Example 3 with PhilmAccount

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());
}
Also used : Account(android.accounts.Account) PhilmAccount(app.philm.in.model.PhilmAccount)

Example 4 with PhilmAccount

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);
        }
    }
}
Also used : PhilmAccount(app.philm.in.model.PhilmAccount)

Example 5 with PhilmAccount

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());
}
Also used : PhilmUserProfile(app.philm.in.model.PhilmUserProfile) PhilmAccount(app.philm.in.model.PhilmAccount) Subscribe(com.squareup.otto.Subscribe)

Aggregations

PhilmAccount (app.philm.in.model.PhilmAccount)5 Account (android.accounts.Account)3 PhilmUserProfile (app.philm.in.model.PhilmUserProfile)1 Subscribe (com.squareup.otto.Subscribe)1 ArrayList (java.util.ArrayList)1