From 60b322673ed8cafe8159eaeb29e492b22fd52809 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Wed, 19 Oct 2022 12:46:09 +0600 Subject: [PATCH 1/3] Put murena account on top of add account list issue: https://gitlab.e.foundation/e/os/backlog/-/issues/697 We want to show murena account types (normal & addressbook) on top of add account list. To ensure that we need to update the ProviderEntry compare method. --- .../accounts/MurenaAccountHelper.java | 27 +++++++++++++++++++ .../settings/accounts/ProviderEntry.java | 15 +++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/com/android/settings/accounts/MurenaAccountHelper.java diff --git a/src/com/android/settings/accounts/MurenaAccountHelper.java b/src/com/android/settings/accounts/MurenaAccountHelper.java new file mode 100644 index 00000000000..df449d2b0b4 --- /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 cf55e1423fc..2d37873d452 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); } -- GitLab From 6ac9b607b41bde9ba690002a338a0a0a21a99dc4 Mon Sep 17 00:00:00 2001 From: Fahim Salam Chowdhury Date: Mon, 24 Oct 2022 18:54:34 +0600 Subject: [PATCH 2/3] Put murena account on top of already added account list issue: https://gitlab.e.foundation/e/os/backlog/-/issues/697 We want to show murena account types (normal & addressbook) on top of account list. To ensure that we need to update the accountTypePreference compare method. --- .../accounts/AccountPreferenceController.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java index ff5bc780910..7ef663ac053 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, -- GitLab From 09200f8a78eb77621d3cb2281ab403fed58cd1a7 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 25 Oct 2022 06:11:35 +0000 Subject: [PATCH 3/3] Apply 1 suggestion(s) to 1 file(s) --- src/com/android/settings/accounts/ProviderEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/settings/accounts/ProviderEntry.java b/src/com/android/settings/accounts/ProviderEntry.java index 2d37873d452..bbf09ab43ac 100644 --- a/src/com/android/settings/accounts/ProviderEntry.java +++ b/src/com/android/settings/accounts/ProviderEntry.java @@ -41,7 +41,7 @@ public class ProviderEntry implements Comparable { } // if any one is Murena account, put it on top - if(MurenaAccountHelper.isMurenaAccount(type)) { + if (MurenaAccountHelper.isMurenaAccount(type)) { return -1; } -- GitLab