mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01: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
@ -45,42 +45,18 @@ object AccountUtils {
|
|||||||
return findAccountsForUsers(LegacyUserEntityMapper.toModel(userEntitiesList))
|
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 context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
||||||
val accMgr = AccountManager.get(context)
|
val accMgr = AccountManager.get(context)
|
||||||
val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
|
val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
|
||||||
|
|
||||||
val accountsAvailable = ArrayList<Account>()
|
val accountsAvailable = ArrayList<Account>()
|
||||||
var importAccount: ImportAccount
|
|
||||||
var internalUserEntity: User
|
|
||||||
var accountFound: Boolean
|
var accountFound: Boolean
|
||||||
for (account in accounts) {
|
for (account in accounts) {
|
||||||
accountFound = false
|
accountFound = false
|
||||||
|
|
||||||
for (i in userEntitiesList.indices) {
|
for (user in users) {
|
||||||
internalUserEntity = userEntitiesList[i]
|
if (matchAccounts(getInformationFromAccount(account), user)) {
|
||||||
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 {
|
|
||||||
accountFound = true
|
accountFound = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -94,6 +70,33 @@ object AccountUtils {
|
|||||||
return accountsAvailable
|
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 {
|
fun getAppNameBasedOnPackage(packageName: String): String {
|
||||||
val context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
val context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
||||||
val packageManager = context.packageManager
|
val packageManager = context.packageManager
|
||||||
|
Loading…
Reference in New Issue
Block a user