fix(account-name): handling
This commit is contained in:
7 files changed
+99
-79
No files matched your search
@@ -330,8 +330,8 @@ dependencies {
|
||||
implementation("androidx.core:core-ktx:1.19.1")
|
||||
implementation("androidx.sharetarget:sharetarget:1.2.0")
|
||||
implementation("androidx.activity:activity-ktx:1.13.0")
|
||||
implementation("com.github.nextcloud.android-common:ui:0.34.0")
|
||||
implementation("com.github.nextcloud.android-common:core:0.34.0")
|
||||
implementation("com.github.nextcloud.android-common:ui:f6515c1c36")
|
||||
implementation("com.github.nextcloud.android-common:core:f6515c1c36")
|
||||
implementation("com.github.nextcloud-deps:android-talk-webrtc:155.8059.1")
|
||||
implementation("com.github.nextcloud-releases:talk-clients-vodozemac:0.0.2")
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ import com.nextcloud.talk.ui.StatusDrawable
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.users.DefaultAccountProvider
|
||||
import com.nextcloud.talk.users.UserManager
|
||||
import com.nextcloud.talk.utils.AccountUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
@@ -213,11 +214,11 @@ class ChooseAccountDialogCompose {
|
||||
},
|
||||
onEcosystemFilesClick = {
|
||||
shouldDismiss.value = true
|
||||
openEcosystemFiles(currentUser)
|
||||
openEcosystemFiles(activity, currentUser)
|
||||
},
|
||||
onEcosystemNotesClick = {
|
||||
shouldDismiss.value = true
|
||||
openEcosystemNotes(currentUser)
|
||||
openEcosystemNotes(activity, currentUser)
|
||||
},
|
||||
onEcosystemMoreClick = {
|
||||
shouldDismiss.value = true
|
||||
@@ -294,15 +295,16 @@ class ChooseAccountDialogCompose {
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
private fun openEcosystemFiles(currentUser: User) {
|
||||
ecosystemManager.openApp(EcosystemApp.FILES, getAccountHandle(currentUser))
|
||||
private fun openEcosystemFiles(activity: Activity, currentUser: User) {
|
||||
ecosystemManager.openApp(EcosystemApp.FILES, getAccountHandle(activity, currentUser))
|
||||
}
|
||||
|
||||
private fun openEcosystemNotes(currentUser: User) {
|
||||
ecosystemManager.openApp(EcosystemApp.NOTES, getAccountHandle(currentUser))
|
||||
private fun openEcosystemNotes(activity: Activity, currentUser: User) {
|
||||
ecosystemManager.openApp(EcosystemApp.NOTES, getAccountHandle(activity, currentUser))
|
||||
}
|
||||
|
||||
private fun getAccountHandle(user: User): String = user.username + "@" + user.baseUrl?.toUri()?.host
|
||||
private fun getAccountHandle(activity: Activity, user: User): String? =
|
||||
AccountUtils.findFilesAccountName(activity, user) ?: AccountUtils.buildAccountName(user)
|
||||
|
||||
private fun openEcosystemMore(activity: Activity) {
|
||||
LinkHelper.openAppStore("Nextcloud", true, activity)
|
||||
|
||||
@@ -43,6 +43,7 @@ import androidx.work.WorkInfo
|
||||
import androidx.work.WorkManager
|
||||
import autodagger.AutoInjector
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.nextcloud.android.common.core.utils.AccountNameUtils
|
||||
import com.nextcloud.android.common.core.utils.ecosystem.AccountReceiverCallback
|
||||
import com.nextcloud.android.common.core.utils.ecosystem.EcosystemManager
|
||||
import com.nextcloud.talk.R
|
||||
@@ -93,6 +94,7 @@ import com.nextcloud.talk.ui.dialog.FilterConversationFragment
|
||||
import com.nextcloud.talk.ui.dialog.FilterConversationFragment.Companion.ARCHIVE
|
||||
import com.nextcloud.talk.ui.dialog.FilterConversationFragment.Companion.MENTION
|
||||
import com.nextcloud.talk.ui.dialog.FilterConversationFragment.Companion.UNREAD
|
||||
import com.nextcloud.talk.utils.AccountUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.BrandingUtils
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil
|
||||
@@ -436,22 +438,16 @@ class ConversationsListActivity : BaseActivity() {
|
||||
ecosystemManager.receiveAccount(
|
||||
intent,
|
||||
object : AccountReceiverCallback {
|
||||
@SuppressLint("UseKtx")
|
||||
override fun onAccountReceived(accountName: String) {
|
||||
val baseUrl = accountName.substringAfterLast("@")
|
||||
val trimmedAccountName = accountName.substringBeforeLast("@")
|
||||
lifecycleScope.launch {
|
||||
val users = userManager.getUsers()
|
||||
val user = users.firstOrNull { user ->
|
||||
user.username == trimmedAccountName && baseUrl == user.baseUrl?.toUri()?.host
|
||||
}
|
||||
val user = AccountUtils.findUserForFilesAccount(context, accountName, userManager.getUsers())
|
||||
if (user != null && userManager.setUserAsActive(user)) {
|
||||
startActivity(createAccountSwitchIntent(context, user.id!!))
|
||||
} else {
|
||||
showSnackbar(getString(R.string.nc_no_account_found))
|
||||
}
|
||||
}
|
||||
Log.d(TAG, trimmedAccountName)
|
||||
Log.d(TAG, AccountNameUtils.getUserPart(accountName))
|
||||
}
|
||||
|
||||
override fun onAccountError(reason: String) {
|
||||
|
||||
@@ -26,8 +26,9 @@ import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.activities.BaseActivity
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.components.ColoredStatusBar
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.ui.dialog.SaveToStorageDialogFragment
|
||||
import com.nextcloud.talk.utils.AccountUtils.canWeOpenFilesApp
|
||||
import com.nextcloud.talk.utils.AccountUtils.resolveFilesAccountName
|
||||
import com.nextcloud.talk.utils.FileUtils
|
||||
import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX_GENERIC
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACCOUNT
|
||||
@@ -51,8 +52,6 @@ class FullScreenTextViewerActivity : BaseActivity() {
|
||||
val isMarkdown = intent.getBooleanExtra("IS_MARKDOWN", false)
|
||||
val fileId = intent.getStringExtra("FILE_ID").orEmpty()
|
||||
val link = intent.getStringExtra("LINK")
|
||||
val username = user.username.orEmpty()
|
||||
val baseUrl = user.baseUrl.orEmpty()
|
||||
textFile = FileUtils.resolveSharedAttachmentFile(applicationContext.cacheDir, fileName) ?: run {
|
||||
Log.e(TAG, "Invalid text filename: $fileName")
|
||||
finish()
|
||||
@@ -80,7 +79,7 @@ class FullScreenTextViewerActivity : BaseActivity() {
|
||||
onShare = { shareFile() },
|
||||
onSave = { showSaveDialog(fileName) },
|
||||
onOpenInFilesApp = if (fileId.isNotEmpty()) {
|
||||
{ openInFilesApp(link, fileId, username, baseUrl) }
|
||||
{ openInFilesApp(link, fileId, user) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -90,9 +89,9 @@ class FullScreenTextViewerActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun openInFilesApp(link: String?, fileId: String, username: String, baseUrl: String) {
|
||||
val accountString = "$username@${baseUrl.replace("https://", "").replace("http://", "")}"
|
||||
if (canWeOpenFilesApp(this, accountString)) {
|
||||
private fun openInFilesApp(link: String?, fileId: String, user: User) {
|
||||
val accountName = resolveFilesAccountName(this, user)
|
||||
if (accountName != null) {
|
||||
val filesAppIntent = Intent(Intent.ACTION_VIEW, null)
|
||||
val componentName = ComponentName(
|
||||
getString(R.string.nc_import_accounts_from),
|
||||
@@ -101,7 +100,7 @@ class FullScreenTextViewerActivity : BaseActivity() {
|
||||
filesAppIntent.component = componentName
|
||||
filesAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
filesAppIntent.setPackage(getString(R.string.nc_import_accounts_from))
|
||||
filesAppIntent.putExtra(KEY_ACCOUNT, accountString)
|
||||
filesAppIntent.putExtra(KEY_ACCOUNT, accountName)
|
||||
filesAppIntent.putExtra(KEY_FILE_ID, fileId)
|
||||
startActivity(filesAppIntent)
|
||||
} else if (!link.isNullOrEmpty()) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.util.Log
|
||||
import com.nextcloud.android.common.core.utils.AccountNameUtils
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
@@ -26,59 +27,63 @@ object AccountUtils {
|
||||
|
||||
private val TAG = AccountUtils::class.java.simpleName
|
||||
private const val MIN_SUPPORTED_FILES_APP_VERSION = 30060151
|
||||
private const val FILES_KEY_USER_ID = "oc_id"
|
||||
private const val FILES_KEY_BASE_URL = "oc_base_url"
|
||||
|
||||
fun findAvailableAccountsOnDevice(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 accountFound: Boolean
|
||||
for (account in accounts) {
|
||||
accountFound = false
|
||||
|
||||
for (user in users) {
|
||||
if (matchAccounts(getInformationFromAccount(account), user)) {
|
||||
accountFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!accountFound) {
|
||||
accountsAvailable.add(account)
|
||||
}
|
||||
return accounts.filter { account ->
|
||||
val canImport = users.isEmpty() || getInformationFromAccount(account).token != null
|
||||
canImport && users.none { accMgr.isSameAccount(account, it) }
|
||||
}
|
||||
|
||||
return accountsAvailable
|
||||
}
|
||||
|
||||
private fun matchAccounts(importAccount: ImportAccount, user: User): Boolean {
|
||||
var accountFound = false
|
||||
if (importAccount.token != null) {
|
||||
if (UriUtils.hasHttpProtocolPrefixed(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
|
||||
}
|
||||
}
|
||||
fun findFilesAccountName(context: Context, user: User): String? {
|
||||
val accMgr = AccountManager.get(context)
|
||||
return accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
|
||||
.firstOrNull { accMgr.isSameAccount(it, user) }
|
||||
?.name
|
||||
}
|
||||
|
||||
fun findUserForFilesAccount(context: Context, accountName: String, users: List<User>): User? {
|
||||
val accountType = context.getString(R.string.nc_import_account_type)
|
||||
val accMgr = AccountManager.get(context)
|
||||
val account = accMgr.getAccountsByType(accountType).firstOrNull { it.name == accountName }
|
||||
?: Account(accountName, accountType)
|
||||
return users.firstOrNull { accMgr.isSameAccount(account, it) }
|
||||
}
|
||||
|
||||
fun buildAccountName(user: User): String? {
|
||||
val username = user.username
|
||||
val baseUrl = user.baseUrl
|
||||
if (username == null || baseUrl == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return AccountNameUtils.build(username, AccountNameUtils.removeScheme(baseUrl))
|
||||
}
|
||||
|
||||
private fun AccountManager.isSameAccount(account: Account, user: User): Boolean {
|
||||
val userBaseUrl = user.baseUrl ?: return false
|
||||
val filesBaseUrl = getUserDataOrNull(account, FILES_KEY_BASE_URL)
|
||||
?: AccountNameUtils.getServerPart(account.name)
|
||||
val filesUserId = getUserDataOrNull(account, FILES_KEY_USER_ID)
|
||||
val userId = user.userId
|
||||
|
||||
return if (filesUserId != null && userId != null) {
|
||||
AccountNameUtils.isSameAccount(filesBaseUrl, filesUserId, userBaseUrl, userId)
|
||||
} else {
|
||||
accountFound = true
|
||||
AccountNameUtils.isSameServer(filesBaseUrl, userBaseUrl) &&
|
||||
AccountNameUtils.getUserPart(account.name).equals(user.username, ignoreCase = true)
|
||||
}
|
||||
|
||||
return accountFound
|
||||
}
|
||||
|
||||
private fun AccountManager.getUserDataOrNull(account: Account, key: String): String? =
|
||||
runCatching { getUserData(account, key) }.getOrNull()
|
||||
|
||||
fun getAppNameBasedOnPackage(packageName: String): String {
|
||||
val context = NextcloudTalkApplication.sharedApplication!!.applicationContext
|
||||
val packageManager = context.packageManager
|
||||
@@ -97,7 +102,7 @@ object AccountUtils {
|
||||
return appName
|
||||
}
|
||||
|
||||
fun canWeOpenFilesApp(context: Context, accountName: String): Boolean {
|
||||
fun resolveFilesAccountName(context: Context, user: User): String? {
|
||||
val pm = context.packageManager
|
||||
try {
|
||||
val packageInfo = pm.getPackageInfo(context.getString(R.string.nc_import_accounts_from), 0)
|
||||
@@ -109,11 +114,9 @@ object AccountUtils {
|
||||
).signatures
|
||||
|
||||
return if (Arrays.equals(ownSignatures, filesAppSignatures)) {
|
||||
val accMgr = AccountManager.get(context)
|
||||
val accounts = accMgr.getAccountsByType(context.getString(R.string.nc_import_account_type))
|
||||
accounts.any { it.name == accountName }
|
||||
findFilesAccountName(context, user)
|
||||
} else {
|
||||
true
|
||||
buildAccountName(user)
|
||||
}
|
||||
}
|
||||
} catch (appNotFoundException: PackageManager.NameNotFoundException) {
|
||||
@@ -124,7 +127,7 @@ object AccountUtils {
|
||||
)
|
||||
}
|
||||
|
||||
return false
|
||||
return null
|
||||
}
|
||||
|
||||
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.nextcloud.talk.fullscreenfile.FullScreenTextViewerActivity
|
||||
import com.nextcloud.talk.jobs.DownloadFileToCacheWorker
|
||||
import com.nextcloud.talk.mediaviewer.activities.MediaViewerActivity
|
||||
import com.nextcloud.talk.mediaviewer.model.MediaViewerItem
|
||||
import com.nextcloud.talk.utils.AccountUtils.canWeOpenFilesApp
|
||||
import com.nextcloud.talk.utils.AccountUtils.resolveFilesAccountName
|
||||
import com.nextcloud.talk.utils.Mimetype.IMAGE_GIF
|
||||
import com.nextcloud.talk.utils.Mimetype.IMAGE_HEIC
|
||||
import com.nextcloud.talk.utils.Mimetype.IMAGE_JPEG
|
||||
@@ -237,12 +237,8 @@ class FileViewerUtils(private val context: Context, private val user: User) {
|
||||
}
|
||||
|
||||
fun openFileInFilesApp(link: String, keyID: String) {
|
||||
val accountString = user.username + "@" +
|
||||
user.baseUrl
|
||||
?.replace("https://", "")
|
||||
?.replace("http://", "")
|
||||
|
||||
if (canWeOpenFilesApp(context, accountString)) {
|
||||
val accountName = resolveFilesAccountName(context, user)
|
||||
if (accountName != null) {
|
||||
val filesAppIntent = Intent(Intent.ACTION_VIEW, null)
|
||||
val componentName = ComponentName(
|
||||
context.getString(R.string.nc_import_accounts_from),
|
||||
@@ -251,7 +247,7 @@ class FileViewerUtils(private val context: Context, private val user: User) {
|
||||
filesAppIntent.component = componentName
|
||||
filesAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
filesAppIntent.setPackage(context.getString(R.string.nc_import_accounts_from))
|
||||
filesAppIntent.putExtra(KEY_ACCOUNT, accountString)
|
||||
filesAppIntent.putExtra(KEY_ACCOUNT, accountName)
|
||||
filesAppIntent.putExtra(KEY_FILE_ID, keyID)
|
||||
context.startActivity(filesAppIntent)
|
||||
} else {
|
||||
|
||||
@@ -20071,6 +20071,14 @@
|
||||
<sha256 value="2370d56cf5e37eed2f6e99ab08fd587789e6e6a6b37a3e532995b75f5af5ac7e" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.nextcloud.android-common" name="core" version="f6515c1c36">
|
||||
<artifact name="core-f6515c1c36.aar">
|
||||
<sha256 value="4ef33d9ec973b53f73048c914cd8018eb5da9a47eeb637795d0e9b9da5c77dbe" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
<artifact name="core-f6515c1c36.module">
|
||||
<sha256 value="d3108f02040359dd61a176473c71817d0373f19eddeed003162c5c7d7661126a" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.nextcloud.android-common" name="material-color-utilities" version="0.18.0">
|
||||
<artifact name="material-color-utilities-0.18.0.jar">
|
||||
<sha256 value="e04a3f4a3caff6e4b2ce3f14f91f0485ab1f012af652102eba61ab6bcf3d8240" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
@@ -20235,6 +20243,14 @@
|
||||
<sha256 value="b5033fff12118798f6832b30399e8c871be91428066bc9ca87894164c6176961" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.nextcloud.android-common" name="material-color-utilities" version="f6515c1c36">
|
||||
<artifact name="material-color-utilities-f6515c1c36.jar">
|
||||
<sha256 value="b901a9fdcc750cd912686ce7cdcadc03ceec7391ca0cdbddc356de3966672c9a" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
<artifact name="material-color-utilities-f6515c1c36.module">
|
||||
<sha256 value="478bea3c849d5ae8578584b11ebf8cd9b30f4c67c52b80380456fd0413b7b5a3" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.nextcloud.android-common" name="ui" version="0.18.0">
|
||||
<artifact name="ui-0.18.0.aar">
|
||||
<sha256 value="7d900a930d7ad1f7de91177b8b661abef13deef032493cee99fe9842f85bcf16" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
@@ -20395,6 +20411,14 @@
|
||||
<sha256 value="2def8209d0634a0934f2c754d164dfe5fb4f9db3ec6638e7291ba022236faa79" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.nextcloud.android-common" name="ui" version="f6515c1c36">
|
||||
<artifact name="ui-f6515c1c36.aar">
|
||||
<sha256 value="495bf1ba3278c14210e5dfca4e11dbb9ae10bedac67031fc5a006348649dbf46" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
<artifact name="ui-f6515c1c36.module">
|
||||
<sha256 value="bd5e8341b2dd1b2aed46f163d524dd3714533058d2c1d5dd2c1a25a22b0cd74f" origin="Generated by Gradle" reason="Artifact is not signed"/>
|
||||
</artifact>
|
||||
</component>
|
||||
<component group="com.github.spotbugs" name="spotbugs" version="4.10.3">
|
||||
<artifact name="spotbugs-4.10.3.jar">
|
||||
<sha256 value="5b12b471979fd8d664e9772d4c7e7e11b25a55d71dbb0ef2d2dcb749959052e7" origin="Generated by Gradle"/>
|
||||
|
||||
Reference in new issue
Block a user