mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 02:05:06 +08:00
Sort social logins buttons
This commit is contained in:
parent
7117427686
commit
4486181669
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user