mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-28 09:38:14 +03:00
split account matcher code for better readability
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
8385def3ed
commit
7568ccdbb1
1 changed files with 30 additions and 27 deletions
|
@ -45,42 +45,18 @@ object AccountUtils {
|
|||
return findAccountsForUsers(LegacyUserEntityMapper.toModel(userEntitiesList))
|
||||
}
|
||||
|
||||
fun findAccountsForUsers(userEntitiesList: List<User>): List<Account> {
|
||||
fun findAccountsForUsers(users: List<User>): List<Account> {
|
||||
val context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
||||
val accMgr = AccountManager.get(context)
|
||||
val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
|
||||
|
||||
val accountsAvailable = ArrayList<Account>()
|
||||
var importAccount: ImportAccount
|
||||
var internalUserEntity: User
|
||||
var accountFound: Boolean
|
||||
for (account in accounts) {
|
||||
accountFound = false
|
||||
|
||||
for (i in userEntitiesList.indices) {
|
||||
internalUserEntity = userEntitiesList[i]
|
||||
importAccount = getInformationFromAccount(account)
|
||||
if (importAccount.token != null) {
|
||||
if (UriUtils.hasHttpProtocollPrefixed(importAccount.baseUrl)) {
|
||||
if (
|
||||
internalUserEntity.username == importAccount.username &&
|
||||
internalUserEntity.baseUrl == importAccount.baseUrl
|
||||
) {
|
||||
accountFound = true
|
||||
break
|
||||
}
|
||||
} else {
|
||||
if (internalUserEntity.username == importAccount.username &&
|
||||
(
|
||||
internalUserEntity.baseUrl == "http://" + importAccount.baseUrl ||
|
||||
internalUserEntity.baseUrl == "https://" + importAccount.baseUrl
|
||||
)
|
||||
) {
|
||||
accountFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (user in users) {
|
||||
if (matchAccounts(getInformationFromAccount(account), user)) {
|
||||
accountFound = true
|
||||
break
|
||||
}
|
||||
|
@ -94,6 +70,33 @@ object AccountUtils {
|
|||
return accountsAvailable
|
||||
}
|
||||
|
||||
private fun matchAccounts(importAccount: ImportAccount, user: User): Boolean {
|
||||
var accountFound = false
|
||||
if (importAccount.token != null) {
|
||||
if (UriUtils.hasHttpProtocollPrefixed(importAccount.baseUrl)) {
|
||||
if (
|
||||
user.username == importAccount.username &&
|
||||
user.baseUrl == importAccount.baseUrl
|
||||
) {
|
||||
accountFound = true
|
||||
}
|
||||
} else {
|
||||
if (user.username == importAccount.username &&
|
||||
(
|
||||
user.baseUrl == "http://" + importAccount.baseUrl ||
|
||||
user.baseUrl == "https://" + importAccount.baseUrl
|
||||
)
|
||||
) {
|
||||
accountFound = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
accountFound = true
|
||||
}
|
||||
|
||||
return accountFound
|
||||
}
|
||||
|
||||
fun getAppNameBasedOnPackage(packageName: String): String {
|
||||
val context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
||||
val packageManager = context.packageManager
|
||||
|
|
Loading…
Reference in a new issue