diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java index ff5bc780910d1bf741ff785b8125050e36857d6f..7ef663ac05323bb3961c3ced95163d798bad55d6 100644 --- a/src/com/android/settings/accounts/AccountPreferenceController.java +++ b/src/com/android/settings/accounts/AccountPreferenceController.java @@ -498,6 +498,8 @@ public class AccountPreferenceController extends AbstractPreferenceController final ArrayList accountTypePreferences = new ArrayList<>(accountTypes.length); + final ArrayList murenaAccountPreferences = new ArrayList<>(); + for (int i = 0; i < accountTypes.length; i++) { final String accountType = accountTypes[i]; // Skip showing any account that does not have any of the requested authorities @@ -521,6 +523,11 @@ public class AccountPreferenceController extends AbstractPreferenceController final AccountTypePreference preference = preferenceToRemove.remove(AccountTypePreference.buildKey(account)); if (preference != null) { + if (MurenaAccountHelper.isMurenaAccount(accountType)) { + murenaAccountPreferences.add(preference); + continue; + } + accountTypePreferences.add(preference); continue; } @@ -541,23 +548,38 @@ public class AccountPreferenceController extends AbstractPreferenceController fragmentArguments.putInt(AccountDetailDashboardFragment.KEY_ACCOUNT_TITLE_RES, titleResId); fragmentArguments.putParcelable(EXTRA_USER, userHandle); - accountTypePreferences.add(new AccountTypePreference( + AccountTypePreference accountTypePreference = new AccountTypePreference( prefContext, mMetricsFeatureProvider.getMetricsCategory(mFragment), account, titleResPackageName, titleResId, label, - AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon)); + AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon); + + if (MurenaAccountHelper.isMurenaAccount(accountType)) { + murenaAccountPreferences.add(accountTypePreference); + continue; + } + + accountTypePreferences.add(accountTypePreference); } helper.preloadDrawableForType(mContext, accountType); } // Sort by label - Collections.sort(accountTypePreferences, new Comparator() { + Collections.sort(accountTypePreferences, getAccountTypePreferenceComparator()); + Collections.sort(murenaAccountPreferences, getAccountTypePreferenceComparator()); + + accountTypePreferences.addAll(0, murenaAccountPreferences); + + return accountTypePreferences; + } + + private Comparator getAccountTypePreferenceComparator() { + return new Comparator() { @Override public int compare(AccountTypePreference t1, AccountTypePreference t2) { int result = t1.getSummary().toString().compareTo(t2.getSummary().toString()); return result != 0 ? result : t1.getTitle().toString().compareTo(t2.getTitle().toString()); } - }); - return accountTypePreferences; + }; } private boolean accountTypeHasAnyRequestedAuthorities(AuthenticatorHelper helper, diff --git a/src/com/android/settings/accounts/MurenaAccountHelper.java b/src/com/android/settings/accounts/MurenaAccountHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..df449d2b0b4873c265bed9454c67bf0a41f09df2 --- /dev/null +++ b/src/com/android/settings/accounts/MurenaAccountHelper.java @@ -0,0 +1,27 @@ +/* + * Copyright MURENA SAS 2022 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.android.settings.accounts; + +public class MurenaAccountHelper { + + public static final String MURENA_ACCOUNT_TYPE = "e.foundation.webdav.eelo"; + public static final String MURENA_ADDRESS_BOOK_ACCOUNT_TYPE = "foundation.e.accountmanager.eelo.address_book"; + + public static boolean isMurenaAccount(String accountType) { + return accountType.equals(MURENA_ACCOUNT_TYPE) || accountType.equals(MURENA_ADDRESS_BOOK_ACCOUNT_TYPE); + } +} diff --git a/src/com/android/settings/accounts/ProviderEntry.java b/src/com/android/settings/accounts/ProviderEntry.java index cf55e1423fc5fbc0025bbbe830fbc15aa2e310af..bbf09ab43acebc0a22436c21cb557930678b4fbc 100644 --- a/src/com/android/settings/accounts/ProviderEntry.java +++ b/src/com/android/settings/accounts/ProviderEntry.java @@ -34,6 +34,21 @@ public class ProviderEntry implements Comparable { if (another.name == null) { return +1; } + + // both are murena accounts, compare them normally + if (MurenaAccountHelper.isMurenaAccount(type) && MurenaAccountHelper.isMurenaAccount(another.type)) { + return CharSequences.compareToIgnoreCase(name, another.name); + } + + // if any one is Murena account, put it on top + if (MurenaAccountHelper.isMurenaAccount(type)) { + return -1; + } + + if (MurenaAccountHelper.isMurenaAccount(another.type)) { + return 1; + } + return CharSequences.compareToIgnoreCase(name, another.name); }