Sort social logins buttons

This commit is contained in:
Benoit Marty 2021-04-15 13:56:15 +02:00
parent 7117427686
commit 4486181669
3 changed files with 24 additions and 3 deletions

View File

@ -48,7 +48,7 @@ data class SsoIdentityProvider(
*/
@Json(name = "brand") val brand: String?
) : Parcelable {
) : Parcelable, Comparable<SsoIdentityProvider> {
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
}
}
}

View File

@ -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(

View File

@ -125,7 +125,7 @@ class LoginFragmentToAny2 @Inject constructor() : AbstractSSOLoginFragment2<Frag
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(