Search in sources :

Example 1 with ImportAccount

use of com.nextcloud.talk.models.ImportAccount in project talk-android by nextcloud.

the class AccountUtils method getInformationFromAccount.

public static ImportAccount getInformationFromAccount(Account account) {
    int lastAtPos = account.name.lastIndexOf("@");
    String urlString = account.name.substring(lastAtPos + 1);
    String username = account.name.substring(0, lastAtPos);
    Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext();
    final AccountManager accMgr = AccountManager.get(context);
    String password = accMgr.getPassword(account);
    if (urlString.endsWith("/")) {
        urlString = urlString.substring(0, urlString.length() - 1);
    }
    return new ImportAccount(username, password, urlString);
}
Also used : Context(android.content.Context) AccountManager(android.accounts.AccountManager) ImportAccount(com.nextcloud.talk.models.ImportAccount)

Example 2 with ImportAccount

use of com.nextcloud.talk.models.ImportAccount in project talk-android by nextcloud.

the class SwitchAccountController method onViewBound.

@Override
protected void onViewBound(@NonNull View view) {
    super.onViewBound(view);
    NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
    swipeRefreshLayout.setEnabled(false);
    if (adapter == null) {
        adapter = new FlexibleAdapter<>(userItems, getActivity(), false);
        UserEntity userEntity;
        Participant participant;
        if (!isAccountImport) {
            for (Object userEntityObject : userUtils.getUsers()) {
                userEntity = (UserEntity) userEntityObject;
                if (!userEntity.getCurrent()) {
                    participant = new Participant();
                    participant.setName(userEntity.getDisplayName());
                    String userId;
                    if (userEntity.getUserId() != null) {
                        userId = userEntity.getUserId();
                    } else {
                        userId = userEntity.getUsername();
                    }
                    participant.setUserId(userId);
                    userItems.add(new AdvancedUserItem(participant, userEntity, null));
                }
            }
            adapter.addListener(onSwitchItemClickListener);
            adapter.updateDataSet(userItems, false);
        } else {
            if (getActionBar() != null) {
                getActionBar().show();
            }
            Account account;
            ImportAccount importAccount;
            for (Object accountObject : AccountUtils.findAccounts(userUtils.getUsers())) {
                account = (Account) accountObject;
                importAccount = AccountUtils.getInformationFromAccount(account);
                participant = new Participant();
                participant.setName(importAccount.getUsername());
                participant.setUserId(importAccount.getUsername());
                userEntity = new UserEntity();
                userEntity.setBaseUrl(importAccount.getBaseUrl());
                userItems.add(new AdvancedUserItem(participant, userEntity, account));
            }
            adapter.addListener(onImportItemClickListener);
            adapter.updateDataSet(userItems, false);
        }
    }
    prepareViews();
}
Also used : ImportAccount(com.nextcloud.talk.models.ImportAccount) Account(android.accounts.Account) Participant(com.nextcloud.talk.models.json.participants.Participant) ImportAccount(com.nextcloud.talk.models.ImportAccount) AdvancedUserItem(com.nextcloud.talk.adapters.items.AdvancedUserItem) UserEntity(com.nextcloud.talk.models.database.UserEntity)

Example 3 with ImportAccount

use of com.nextcloud.talk.models.ImportAccount in project talk-android by nextcloud.

the class SwitchAccountController method verifyAccount.

private void verifyAccount(Account account) {
    ImportAccount importAccount = AccountUtils.getInformationFromAccount(account);
    Bundle bundle = new Bundle();
    bundle.putString(BundleKeys.KEY_USERNAME, importAccount.getUsername());
    bundle.putString(BundleKeys.KEY_TOKEN, importAccount.getToken());
    bundle.putString(BundleKeys.KEY_BASE_URL, importAccount.getBaseUrl());
    bundle.putBoolean(BundleKeys.KEY_IS_ACCOUNT_IMPORT, true);
    getRouter().pushController(RouterTransaction.with(new AccountVerificationController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
}
Also used : Bundle(android.os.Bundle) ImportAccount(com.nextcloud.talk.models.ImportAccount) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)

Example 4 with ImportAccount

use of com.nextcloud.talk.models.ImportAccount in project talk-android by nextcloud.

the class AccountUtils method findAccounts.

public static List<Account> findAccounts(List<UserEntity> userEntitiesList) {
    Context context = NextcloudTalkApplication.getSharedApplication().getApplicationContext();
    final AccountManager accMgr = AccountManager.get(context);
    final Account[] accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type));
    List<Account> accountsAvailable = new ArrayList<>();
    ImportAccount importAccount;
    UserEntity internalUserEntity;
    boolean accountFound;
    for (Account account : accounts) {
        accountFound = false;
        for (int i = 0; i < userEntitiesList.size(); i++) {
            internalUserEntity = userEntitiesList.get(i);
            importAccount = getInformationFromAccount(account);
            if (importAccount.getBaseUrl().startsWith("http://") || importAccount.getBaseUrl().startsWith("https://")) {
                if (internalUserEntity.getUsername().equals(importAccount.getUsername()) && internalUserEntity.getBaseUrl().equals(importAccount.getBaseUrl())) {
                    accountFound = true;
                    break;
                }
            } else {
                if (internalUserEntity.getUsername().equals(importAccount.getUsername()) && (internalUserEntity.getBaseUrl().equals("http://" + importAccount.getBaseUrl()) || internalUserEntity.getBaseUrl().equals("https://" + importAccount.getBaseUrl()))) {
                    accountFound = true;
                    break;
                }
            }
        }
        if (!accountFound) {
            accountsAvailable.add(account);
        }
    }
    return accountsAvailable;
}
Also used : Context(android.content.Context) Account(android.accounts.Account) ImportAccount(com.nextcloud.talk.models.ImportAccount) ArrayList(java.util.ArrayList) AccountManager(android.accounts.AccountManager) ImportAccount(com.nextcloud.talk.models.ImportAccount) UserEntity(com.nextcloud.talk.models.database.UserEntity)

Aggregations

ImportAccount (com.nextcloud.talk.models.ImportAccount)4 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 UserEntity (com.nextcloud.talk.models.database.UserEntity)2 Bundle (android.os.Bundle)1 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)1 AdvancedUserItem (com.nextcloud.talk.adapters.items.AdvancedUserItem)1 Participant (com.nextcloud.talk.models.json.participants.Participant)1 ArrayList (java.util.ArrayList)1