diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt index cfaf74ce24..64b3e180aa 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/SsoIdentityProvider.kt @@ -48,7 +48,7 @@ data class SsoIdentityProvider( */ @Json(name = "brand") val brand: String? -) : Parcelable { +) : Parcelable, Comparable { companion object { const val BRAND_GOOGLE = "org.matrix.google" @@ -58,4 +58,25 @@ data class SsoIdentityProvider( const val BRAND_TWITTER = "org.matrix.twitter" const val BRAND_GITLAB = "org.matrix.gitlab" } + + override fun compareTo(other: SsoIdentityProvider): Int { + return other.toPriority().compareTo(toPriority()) + } + + private fun toPriority(): Int { + return when (brand) { + // We are on Android, so user is more likely to have a Google account + BRAND_GOOGLE -> 5 + // Facebook is also an important SSO provider + BRAND_FACEBOOK -> 4 + // Twitter is more for professionals + BRAND_TWITTER -> 3 + // Here it's very for techie people + BRAND_GITHUB, + BRAND_GITLAB -> 2 + // And finally, if the account has been created with an iPhone... + BRAND_APPLE -> 1 + else -> 0 + } + } } diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginFragment2SignupUsername.kt b/vector/src/main/java/im/vector/app/features/login2/LoginFragment2SignupUsername.kt index ce9add677d..92bd041da9 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginFragment2SignupUsername.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginFragment2SignupUsername.kt @@ -94,7 +94,7 @@ class LoginFragment2SignupUsername @Inject constructor() : AbstractSSOLoginFragm if (state.loginMode is LoginMode.SsoAndPassword) { views.loginSocialLoginContainer.isVisible = true - views.loginSocialLoginButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders + views.loginSocialLoginButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders?.sorted() views.loginSocialLoginButtons.listener = object : SocialLoginButtonsView.InteractionListener { override fun onProviderSelected(id: String?) { loginViewModel.getSsoUrl( diff --git a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt index 252ae0482a..479902a803 100644 --- a/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt +++ b/vector/src/main/java/im/vector/app/features/login2/LoginFragmentToAny2.kt @@ -125,7 +125,7 @@ class LoginFragmentToAny2 @Inject constructor() : AbstractSSOLoginFragment2