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