From 1e4c7510a678c2a19653a0003b52aa86955e1481 Mon Sep 17 00:00:00 2001 From: Marc K Date: Wed, 21 Nov 2018 18:30:08 +0100 Subject: [PATCH 01/13] Add accounts header to the drawer --- .../java/com/fsck/k9/activity/Accounts.java | 11 ++ .../com/fsck/k9/activity/MessageList.java | 10 +- .../main/java/com/fsck/k9/ui/K9Drawer.java | 118 ++++++++++++++---- app/ui/src/main/res/values/colors.xml | 2 + app/ui/src/main/res/values/themes.xml | 2 +- 5 files changed, 110 insertions(+), 33 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java b/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java index 2f338d3ee..9ce3f34aa 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java @@ -666,6 +666,17 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { return true; } + public static void openRealAccount(Account realAccount, Context context) { + if (realAccount.getAutoExpandFolder() == null) { + FolderList.actionHandleAccount(context, realAccount); + } else { + LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolder()); + search.addAllowedFolder(realAccount.getAutoExpandFolder()); + search.addAccountUuid(realAccount.getUuid()); + MessageList.actionDisplaySearch(context, search, false, true); + } + } + private void onActivateAccount(Account account) { List disabledAccounts = new ArrayList<>(); disabledAccounts.add(account); diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index 37ca3b70c..3e4f36db4 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -3,7 +3,6 @@ package com.fsck.k9.activity; import android.annotation.SuppressLint; import android.app.SearchManager; -import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProvider; import android.arch.lifecycle.ViewModelProviders; import android.content.Context; @@ -15,7 +14,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; -import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager.OnBackStackChangedListener; import android.support.v4.app.FragmentTransaction; @@ -47,7 +45,6 @@ import com.fsck.k9.fragment.MessageListFragment; import com.fsck.k9.fragment.MessageListFragment.MessageListFragmentListener; import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.ParcelableUtil; -import com.fsck.k9.mailstore.Folder; import com.fsck.k9.mailstore.SearchStatusManager; import com.fsck.k9.mailstore.StorageManager; import com.fsck.k9.notification.NotificationChannelManager; @@ -249,12 +246,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen MessageListViewModel viewModel = viewModelProvider.get(MessageListViewModel.class); if (isDrawerEnabled()) { - viewModel.getFolders(account).observe(this, new Observer>() { - @Override - public void onChanged(@Nullable List folders) { - drawer.setUserFolders(folders); - } - }); + drawer.updateUserAccountsAndFolders(account); } findFragments(); diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 76dfe68d5..424853e95 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -1,32 +1,46 @@ package com.fsck.k9.ui; -import java.util.ArrayList; -import java.util.List; - +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProvider; +import android.arch.lifecycle.ViewModelProviders; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.DrawerLayout; import android.util.TypedValue; import android.view.View; - +import com.fsck.k9.Account; import com.fsck.k9.DI; import com.fsck.k9.K9; +import com.fsck.k9.Preferences; +import com.fsck.k9.activity.Accounts; import com.fsck.k9.activity.MessageList; import com.fsck.k9.mailstore.Folder; import com.fsck.k9.ui.folders.FolderNameFormatter; +import com.fsck.k9.ui.messagelist.MessageListViewModel; +import com.fsck.k9.ui.messagelist.MessageListViewModelFactory; import com.fsck.k9.ui.settings.SettingsActivity; +import com.mikepenz.iconics.IconicsDrawable; +import com.mikepenz.materialdrawer.AccountHeader; +import com.mikepenz.materialdrawer.AccountHeaderBuilder; import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.Drawer.OnDrawerItemClickListener; import com.mikepenz.materialdrawer.DrawerBuilder; +import com.mikepenz.materialdrawer.icons.MaterialDrawerFont; import com.mikepenz.materialdrawer.model.DividerDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; +import com.mikepenz.materialdrawer.model.ProfileDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; +import com.mikepenz.materialdrawer.model.interfaces.IProfile; + +import java.util.ArrayList; +import java.util.List; public class K9Drawer { // Bit shift for identifiers of user folders items, to leave space for other items private static final short DRAWER_FOLDER_SHIFT = 2; + private static final short DRAWER_ACCOUNT_SHIFT = 16; private static final long DRAWER_ID_UNIFIED_INBOX = 0; private static final long DRAWER_ID_PREFERENCES = 1; @@ -35,8 +49,9 @@ public class K9Drawer { private final FolderNameFormatter folderNameFormatter = DI.get(FolderNameFormatter.class); private final Drawer drawer; + private AccountHeader accountHeader; private final MessageList parent; - private int headerItemCount = 0; + private int headerItemCount = 1; private int iconFolderInboxResId; private int iconFolderOutboxResId; @@ -48,9 +63,11 @@ public class K9Drawer { private int iconFolderResId; private final List userFolderDrawerIds = new ArrayList<>(); + private final List userAccountDrawerIds = new ArrayList<>(); private boolean unifiedInboxSelected; private String openedFolderServerId; + private final Preferences preferences = DI.get(Preferences.class); public K9Drawer(MessageList parent, Bundle savedInstanceState) { this.parent = parent; @@ -64,24 +81,65 @@ public class K9Drawer { .withOnDrawerItemClickListener(createItemClickListener()) .withOnDrawerListener(parent.createOnDrawerListener()) .withSavedInstance(savedInstanceState) + .withAccountHeader(buildAccountHeader()) .build(); - addHeaderItems(); addFooterItems(); initializeFolderIcons(); } - private void addHeaderItems() { - if (!K9.isHideSpecialAccounts()) { - drawer.addItems(new PrimaryDrawerItem() - .withName(R.string.integrated_inbox_title) - .withIcon(getResId(R.attr.iconUnifiedInbox)) - .withIdentifier(DRAWER_ID_UNIFIED_INBOX), - new DividerDrawerItem()); + private AccountHeader buildAccountHeader() { + AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder() + .withActivity(parent) + //.withTextColorRes(R.color.primary_text_secondary_when_activated_material) + .withTranslucentStatusBar(false); - headerItemCount += 2; + if (!K9.isHideSpecialAccounts()) { + headerBuilder.addProfiles(new ProfileDrawerItem() + .withNameShown(true) + .withName(R.string.integrated_inbox_title) + .withIcon(getResId(R.attr.iconUnifiedInbox)) + .withSetSelected(unifiedInboxSelected) + .withIdentifier(DRAWER_ID_UNIFIED_INBOX) + ); } + + List accounts = preferences.getAccounts(); + for (int i = preferences.getAccounts().size() - 1; i >= 0; i--) { + Account account = accounts.get(i); + long drawerId = (account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT; + + headerBuilder.addProfiles(new ProfileDrawerItem() + .withNameShown(true) + .withName(account.getDescription()) + .withEmail(account.getEmail()) + .withIcon(new IconicsDrawable(parent, MaterialDrawerFont.Icon.mdf_person) + .colorRes(R.color.material_drawer_background).backgroundColor(account.getChipColor()) + .sizeDp(56).paddingDp(16)) + .withIdentifier(drawerId) + .withSetSelected(false) + .withTag(account) + ); + } + + accountHeader = headerBuilder + .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { + @Override + public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { + if (profile.getIdentifier() == DRAWER_ID_UNIFIED_INBOX) { + parent.openUnifiedInbox(); + return false; + } else { + Account account = (Account) ((ProfileDrawerItem) profile).getTag(); + updateUserAccountsAndFolders(account); + Accounts.openRealAccount(account, parent); + return false; + } + } + }) + .build(); + return accountHeader; } private void addFooterItems() { @@ -130,22 +188,35 @@ public class K9Drawer { return folderNameFormatter.displayName(folder); } + public void updateUserAccountsAndFolders(Account account) { + if (account == null) { + selectUnifiedInbox(); + } else { + accountHeader.setActiveProfile((account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT); + ViewModelProvider viewModelProvider = ViewModelProviders.of(parent, new MessageListViewModelFactory()); + MessageListViewModel viewModel = viewModelProvider.get(MessageListViewModel.class); + viewModel.getFolders(account).observe(parent, new Observer>() { + @Override + public void onChanged(@Nullable List folders) { + setUserFolders(folders); + } + }); + } + } + private OnDrawerItemClickListener createItemClickListener() { return new OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { long id = drawerItem.getIdentifier(); - if (id == DRAWER_ID_UNIFIED_INBOX) { - parent.openUnifiedInbox(); - return false; - } else if (id == DRAWER_ID_PREFERENCES) { + if (id == DRAWER_ID_PREFERENCES) { SettingsActivity.launch(parent); return false; + } else { + Folder folder = (Folder) drawerItem.getTag(); + parent.openFolder(folder.getServerId()); + return false; } - - Folder folder = (Folder) drawerItem.getTag(); - parent.openFolder(folder.getServerId()); - return false; } }; } @@ -204,7 +275,8 @@ public class K9Drawer { public void selectUnifiedInbox() { unifiedInboxSelected = true; openedFolderServerId = null; - drawer.setSelection(DRAWER_ID_UNIFIED_INBOX, false); + accountHeader.setActiveProfile(DRAWER_ID_UNIFIED_INBOX); + clearUserFolders(); } public DrawerLayout getLayout() { diff --git a/app/ui/src/main/res/values/colors.xml b/app/ui/src/main/res/values/colors.xml index f176bf856..f2ccc7830 100644 --- a/app/ui/src/main/res/values/colors.xml +++ b/app/ui/src/main/res/values/colors.xml @@ -9,4 +9,6 @@ #7bad45 #666666 + + @color/material_drawer_primary_text diff --git a/app/ui/src/main/res/values/themes.xml b/app/ui/src/main/res/values/themes.xml index 0e0622044..d14562dd8 100644 --- a/app/ui/src/main/res/values/themes.xml +++ b/app/ui/src/main/res/values/themes.xml @@ -116,7 +116,7 @@ @color/material_drawer_dark_divider @color/material_drawer_dark_selected @color/material_drawer_dark_selected_text - @color/material_drawer_header_selection_text + @color/material_drawer_dark_header_selection_text @style/PreferenceThemeOverlay.v14.Material @drawable/ic_inbox_multiple_dark From e8e03b16354f0e39c52e06549cb736b76f842197 Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 12:22:06 +0100 Subject: [PATCH 02/13] Show detailed unified inbox description in accounts drawer header --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 424853e95..0ef049bf4 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -100,6 +100,7 @@ public class K9Drawer { .withNameShown(true) .withName(R.string.integrated_inbox_title) .withIcon(getResId(R.attr.iconUnifiedInbox)) + .withEmail(parent.getString(R.string.integrated_inbox_detail)) .withSetSelected(unifiedInboxSelected) .withIdentifier(DRAWER_ID_UNIFIED_INBOX) ); From ef5cbfb1ecf21218df84c3f14056a003a211f7c4 Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 12:28:34 +0100 Subject: [PATCH 03/13] Use faw-users icon for unified inbox in accounts header --- app/ui/build.gradle | 1 + app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/ui/build.gradle b/app/ui/build.gradle index 9e6743290..171cdbfa1 100644 --- a/app/ui/build.gradle +++ b/app/ui/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation "com.xwray:groupie:2.1.0" implementation "com.xwray:groupie-kotlin-android-extensions:2.1.0" implementation 'com.mikepenz:materialdrawer:6.0.7' + implementation 'com.mikepenz:fontawesome-typeface:5.3.1.1@aar' implementation 'com.github.ByteHamster:SearchPreference:v1.1.4' implementation "commons-io:commons-io:${versions.commonsIo}" diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 0ef049bf4..cb61a82ed 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -4,6 +4,7 @@ package com.fsck.k9.ui; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProvider; import android.arch.lifecycle.ViewModelProviders; +import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.DrawerLayout; @@ -20,6 +21,7 @@ import com.fsck.k9.ui.folders.FolderNameFormatter; import com.fsck.k9.ui.messagelist.MessageListViewModel; import com.fsck.k9.ui.messagelist.MessageListViewModelFactory; import com.fsck.k9.ui.settings.SettingsActivity; +import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.iconics.IconicsDrawable; import com.mikepenz.materialdrawer.AccountHeader; import com.mikepenz.materialdrawer.AccountHeaderBuilder; @@ -99,8 +101,10 @@ public class K9Drawer { headerBuilder.addProfiles(new ProfileDrawerItem() .withNameShown(true) .withName(R.string.integrated_inbox_title) - .withIcon(getResId(R.attr.iconUnifiedInbox)) .withEmail(parent.getString(R.string.integrated_inbox_detail)) + .withIcon(new IconicsDrawable(parent, FontAwesome.Icon.faw_users) + .colorRes(R.color.material_drawer_background).backgroundColor(Color.GRAY) + .sizeDp(56).paddingDp(8)) .withSetSelected(unifiedInboxSelected) .withIdentifier(DRAWER_ID_UNIFIED_INBOX) ); From 830535081a88589cd36ffaca13efd526f542f594 Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 13:57:57 +0100 Subject: [PATCH 04/13] Use font awesome icon also also for normal account --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index cb61a82ed..997edc1c3 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -28,7 +28,6 @@ import com.mikepenz.materialdrawer.AccountHeaderBuilder; import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.Drawer.OnDrawerItemClickListener; import com.mikepenz.materialdrawer.DrawerBuilder; -import com.mikepenz.materialdrawer.icons.MaterialDrawerFont; import com.mikepenz.materialdrawer.model.DividerDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.ProfileDrawerItem; @@ -119,9 +118,9 @@ public class K9Drawer { .withNameShown(true) .withName(account.getDescription()) .withEmail(account.getEmail()) - .withIcon(new IconicsDrawable(parent, MaterialDrawerFont.Icon.mdf_person) + .withIcon(new IconicsDrawable(parent, FontAwesome.Icon.faw_user_alt) .colorRes(R.color.material_drawer_background).backgroundColor(account.getChipColor()) - .sizeDp(56).paddingDp(16)) + .sizeDp(56).paddingDp(14)) .withIdentifier(drawerId) .withSetSelected(false) .withTag(account) From a5196ed2f6c10f9b55120ca77ddebaeaa346a1b9 Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 22:33:18 +0100 Subject: [PATCH 05/13] Clean up leftovers --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 997edc1c3..3cf7d25b4 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -64,7 +64,6 @@ public class K9Drawer { private int iconFolderResId; private final List userFolderDrawerIds = new ArrayList<>(); - private final List userAccountDrawerIds = new ArrayList<>(); private boolean unifiedInboxSelected; private String openedFolderServerId; @@ -93,7 +92,6 @@ public class K9Drawer { private AccountHeader buildAccountHeader() { AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder() .withActivity(parent) - //.withTextColorRes(R.color.primary_text_secondary_when_activated_material) .withTranslucentStatusBar(false); if (!K9.isHideSpecialAccounts()) { @@ -110,7 +108,7 @@ public class K9Drawer { } List accounts = preferences.getAccounts(); - for (int i = preferences.getAccounts().size() - 1; i >= 0; i--) { + for (int i = 0; i < preferences.getAccounts().size(); i++) { Account account = accounts.get(i); long drawerId = (account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT; From f11d0e47ecab204410017e1ff79f02213973d889 Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 23:50:05 +0100 Subject: [PATCH 06/13] Fix account selection and folder list not beeing updated --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 3cf7d25b4..9dbe2107a 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -134,8 +134,8 @@ public class K9Drawer { return false; } else { Account account = (Account) ((ProfileDrawerItem) profile).getTag(); - updateUserAccountsAndFolders(account); Accounts.openRealAccount(account, parent); + updateUserAccountsAndFolders(account); return false; } } @@ -194,6 +194,7 @@ public class K9Drawer { if (account == null) { selectUnifiedInbox(); } else { + unifiedInboxSelected = false; accountHeader.setActiveProfile((account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT); ViewModelProvider viewModelProvider = ViewModelProviders.of(parent, new MessageListViewModelFactory()); MessageListViewModel viewModel = viewModelProvider.get(MessageListViewModel.class); @@ -250,8 +251,6 @@ public class K9Drawer { if (openedFolderDrawerId != -1) { drawer.setSelection(openedFolderDrawerId, false); - } else if (unifiedInboxSelected) { - selectUnifiedInbox(); } } From 98d92d9cf21df488d691045adfb6352d9d712e2e Mon Sep 17 00:00:00 2001 From: morckx Date: Sat, 24 Nov 2018 14:41:16 +0100 Subject: [PATCH 07/13] Use contact photos as account icons --- .../main/java/com/fsck/k9/ui/K9Drawer.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 9dbe2107a..726758b30 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -5,6 +5,7 @@ import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProvider; import android.arch.lifecycle.ViewModelProviders; import android.graphics.Color; +import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.DrawerLayout; @@ -16,6 +17,7 @@ import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.activity.Accounts; import com.fsck.k9.activity.MessageList; +import com.fsck.k9.helper.Contacts; import com.fsck.k9.mailstore.Folder; import com.fsck.k9.ui.folders.FolderNameFormatter; import com.fsck.k9.ui.messagelist.MessageListViewModel; @@ -35,6 +37,7 @@ import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IProfile; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; @@ -107,22 +110,30 @@ public class K9Drawer { ); } + HashSet photoUris = new HashSet(); + List accounts = preferences.getAccounts(); for (int i = 0; i < preferences.getAccounts().size(); i++) { Account account = accounts.get(i); long drawerId = (account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT; - headerBuilder.addProfiles(new ProfileDrawerItem() + ProfileDrawerItem pdi = new ProfileDrawerItem() .withNameShown(true) .withName(account.getDescription()) .withEmail(account.getEmail()) - .withIcon(new IconicsDrawable(parent, FontAwesome.Icon.faw_user_alt) - .colorRes(R.color.material_drawer_background).backgroundColor(account.getChipColor()) - .sizeDp(56).paddingDp(14)) .withIdentifier(drawerId) .withSetSelected(false) - .withTag(account) - ); + .withTag(account); + + Uri photoUri = Contacts.getInstance(parent).getPhotoUri(account.getEmail()); + if (photoUri != null && !photoUris.contains(photoUri)) { + photoUris.add(photoUri); + } else { + pdi.withIcon(new IconicsDrawable(parent, FontAwesome.Icon.faw_user_alt) + .colorRes(R.color.material_drawer_background).backgroundColor(account.getChipColor()) + .sizeDp(56).paddingDp(14)); + } + headerBuilder.addProfiles(pdi); } accountHeader = headerBuilder From e5fbedb5417e429f3088d758a97567e796dbeb49 Mon Sep 17 00:00:00 2001 From: morckx Date: Sun, 25 Nov 2018 00:08:18 +0100 Subject: [PATCH 08/13] Don't forget to set the photo icon --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 726758b30..9b1d23cd3 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -128,6 +128,7 @@ public class K9Drawer { Uri photoUri = Contacts.getInstance(parent).getPhotoUri(account.getEmail()); if (photoUri != null && !photoUris.contains(photoUri)) { photoUris.add(photoUri); + pdi.withIcon(photoUri); } else { pdi.withIcon(new IconicsDrawable(parent, FontAwesome.Icon.faw_user_alt) .colorRes(R.color.material_drawer_background).backgroundColor(account.getChipColor()) From 63154d0602bd00e0e2513e70fbe00c2847761bf9 Mon Sep 17 00:00:00 2001 From: morckx Date: Sun, 25 Nov 2018 10:41:11 +0100 Subject: [PATCH 09/13] Remove more leftovers --- app/ui/src/main/java/com/fsck/k9/activity/MessageList.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index 3e4f36db4..d24093ad7 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -3,8 +3,6 @@ package com.fsck.k9.activity; import android.annotation.SuppressLint; import android.app.SearchManager; -import android.arch.lifecycle.ViewModelProvider; -import android.arch.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; import android.content.IntentSender; @@ -57,8 +55,6 @@ import com.fsck.k9.search.SearchSpecification.SearchCondition; import com.fsck.k9.search.SearchSpecification.SearchField; import com.fsck.k9.ui.K9Drawer; import com.fsck.k9.ui.R; -import com.fsck.k9.ui.messagelist.MessageListViewModel; -import com.fsck.k9.ui.messagelist.MessageListViewModelFactory; import com.fsck.k9.ui.messageview.MessageViewFragment; import com.fsck.k9.ui.messageview.MessageViewFragment.MessageViewFragmentListener; import com.fsck.k9.ui.settings.SettingsActivity; @@ -242,9 +238,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen return; } - ViewModelProvider viewModelProvider = ViewModelProviders.of(this, new MessageListViewModelFactory()); - MessageListViewModel viewModel = viewModelProvider.get(MessageListViewModel.class); - if (isDrawerEnabled()) { drawer.updateUserAccountsAndFolders(account); } From 455b0f2c6ced71b99b84a2fbebfd34db38fbe639 Mon Sep 17 00:00:00 2001 From: morckx Date: Sun, 25 Nov 2018 10:50:07 +0100 Subject: [PATCH 10/13] Make MessageListViewModel.getFolders aware of account switches --- .../java/com/fsck/k9/ui/messagelist/MessageListViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/ui/src/main/java/com/fsck/k9/ui/messagelist/MessageListViewModel.kt b/app/ui/src/main/java/com/fsck/k9/ui/messagelist/MessageListViewModel.kt index c4c02770b..7e55ac351 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/messagelist/MessageListViewModel.kt +++ b/app/ui/src/main/java/com/fsck/k9/ui/messagelist/MessageListViewModel.kt @@ -12,10 +12,12 @@ import org.jetbrains.anko.coroutines.experimental.bg class MessageListViewModel(private val folderRepositoryManager: FolderRepositoryManager) : ViewModel() { private val foldersLiveData = MutableLiveData>() + private var account: Account? = null fun getFolders(account: Account): LiveData> { - if (foldersLiveData.value == null) { + if (foldersLiveData.value == null || this.account != account) { + this.account = account loadFolders(account) } From cced6e34f28c2702075d08a0c1db19a2388e842e Mon Sep 17 00:00:00 2001 From: morckx Date: Mon, 26 Nov 2018 21:18:02 +0100 Subject: [PATCH 11/13] Move openRealAccount from Accounts to MessageList --- .../src/main/java/com/fsck/k9/activity/Accounts.java | 11 ----------- .../main/java/com/fsck/k9/activity/MessageList.java | 11 +++++++++++ app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java b/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java index 9ce3f34aa..2f338d3ee 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/Accounts.java @@ -666,17 +666,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { return true; } - public static void openRealAccount(Account realAccount, Context context) { - if (realAccount.getAutoExpandFolder() == null) { - FolderList.actionHandleAccount(context, realAccount); - } else { - LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolder()); - search.addAllowedFolder(realAccount.getAutoExpandFolder()); - search.addAccountUuid(realAccount.getUuid()); - MessageList.actionDisplaySearch(context, search, false, true); - } - } - private void onActivateAccount(Account account) { List disabledAccounts = new ArrayList<>(); disabledAccounts.add(account); diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index d24093ad7..67f7a7a74 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -607,6 +607,17 @@ public class MessageList extends K9Activity implements MessageListFragmentListen performSearch(SearchAccount.createUnifiedInboxAccount().getRelatedSearch()); } + public void openRealAccount(Account realAccount) { + if (realAccount.getAutoExpandFolder() == null) { + FolderList.actionHandleAccount(this, realAccount); + } else { + LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolder()); + search.addAllowedFolder(realAccount.getAutoExpandFolder()); + search.addAccountUuid(realAccount.getUuid()); + performSearch(search); + } + } + private void performSearch(LocalSearch search) { initializeFromLocalSearch(search); diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index 9b1d23cd3..cf90d1932 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -15,7 +15,6 @@ import com.fsck.k9.Account; import com.fsck.k9.DI; import com.fsck.k9.K9; import com.fsck.k9.Preferences; -import com.fsck.k9.activity.Accounts; import com.fsck.k9.activity.MessageList; import com.fsck.k9.helper.Contacts; import com.fsck.k9.mailstore.Folder; @@ -146,7 +145,7 @@ public class K9Drawer { return false; } else { Account account = (Account) ((ProfileDrawerItem) profile).getTag(); - Accounts.openRealAccount(account, parent); + parent.openRealAccount(account); updateUserAccountsAndFolders(account); return false; } From 269656dbe3b055db97ba2e3752b3d56ee6ce947c Mon Sep 17 00:00:00 2001 From: morckx Date: Mon, 26 Nov 2018 23:41:00 +0100 Subject: [PATCH 12/13] Render message lists in the background after account switch --- app/ui/src/main/java/com/fsck/k9/activity/MessageList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java index 67f7a7a74..9b9ceaee7 100644 --- a/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +++ b/app/ui/src/main/java/com/fsck/k9/activity/MessageList.java @@ -604,7 +604,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen public void openUnifiedInbox() { drawer.selectUnifiedInbox(); - performSearch(SearchAccount.createUnifiedInboxAccount().getRelatedSearch()); + actionDisplaySearch(this, SearchAccount.createUnifiedInboxAccount().getRelatedSearch(), false, false); } public void openRealAccount(Account realAccount) { @@ -614,7 +614,7 @@ public class MessageList extends K9Activity implements MessageListFragmentListen LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolder()); search.addAllowedFolder(realAccount.getAutoExpandFolder()); search.addAccountUuid(realAccount.getUuid()); - performSearch(search); + actionDisplaySearch(this, search, false, false); } } From e9d3c14ff8d5399f80daf45291a440c3183bebd0 Mon Sep 17 00:00:00 2001 From: Marc K Date: Tue, 27 Nov 2018 18:17:24 +0100 Subject: [PATCH 13/13] Add a tinted background image to the drawer account header ... using the configured account color as tint color. Thanks @ByteHamster --- app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java | 4 ++++ .../main/res/drawable/drawer_header_background.xml | 11 +++++++++++ app/ui/src/main/res/values/colors.xml | 2 -- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/ui/src/main/res/drawable/drawer_header_background.xml diff --git a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java index cf90d1932..2c49918ba 100644 --- a/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +++ b/app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java @@ -5,6 +5,7 @@ import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProvider; import android.arch.lifecycle.ViewModelProviders; import android.graphics.Color; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.Bundle; import android.support.annotation.Nullable; @@ -94,6 +95,7 @@ public class K9Drawer { private AccountHeader buildAccountHeader() { AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder() .withActivity(parent) + .withHeaderBackground(R.drawable.drawer_header_background) .withTranslucentStatusBar(false); if (!K9.isHideSpecialAccounts()) { @@ -207,6 +209,7 @@ public class K9Drawer { } else { unifiedInboxSelected = false; accountHeader.setActiveProfile((account.getAccountNumber()+1) << DRAWER_ACCOUNT_SHIFT); + accountHeader.getHeaderBackgroundView().setColorFilter(account.getChipColor(), PorterDuff.Mode.OVERLAY); ViewModelProvider viewModelProvider = ViewModelProviders.of(parent, new MessageListViewModelFactory()); MessageListViewModel viewModel = viewModelProvider.get(MessageListViewModel.class); viewModel.getFolders(account).observe(parent, new Observer>() { @@ -288,6 +291,7 @@ public class K9Drawer { unifiedInboxSelected = true; openedFolderServerId = null; accountHeader.setActiveProfile(DRAWER_ID_UNIFIED_INBOX); + accountHeader.getHeaderBackgroundView().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY); clearUserFolders(); } diff --git a/app/ui/src/main/res/drawable/drawer_header_background.xml b/app/ui/src/main/res/drawable/drawer_header_background.xml new file mode 100644 index 000000000..7f2ca9cc3 --- /dev/null +++ b/app/ui/src/main/res/drawable/drawer_header_background.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/ui/src/main/res/values/colors.xml b/app/ui/src/main/res/values/colors.xml index f2ccc7830..f176bf856 100644 --- a/app/ui/src/main/res/values/colors.xml +++ b/app/ui/src/main/res/values/colors.xml @@ -9,6 +9,4 @@ #7bad45 #666666 - - @color/material_drawer_primary_text