Loading app/ui/src/main/java/com/fsck/k9/activity/Accounts.java +11 −0 Original line number Diff line number Diff line Loading @@ -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<Account> disabledAccounts = new ArrayList<>(); disabledAccounts.add(account); Loading app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +1 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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<List<Folder>>() { @Override public void onChanged(@Nullable List<Folder> folders) { drawer.setUserFolders(folders); } }); drawer.updateUserAccountsAndFolders(account); } findFragments(); Loading app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +94 −22 Original line number Diff line number Diff line 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; Loading @@ -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; Loading @@ -48,9 +63,11 @@ public class K9Drawer { private int iconFolderResId; private final List<Long> userFolderDrawerIds = new ArrayList<>(); private final List<Long> 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; Loading @@ -64,24 +81,65 @@ public class K9Drawer { .withOnDrawerItemClickListener(createItemClickListener()) .withOnDrawerListener(parent.createOnDrawerListener()) .withSavedInstance(savedInstanceState) .withAccountHeader(buildAccountHeader()) .build(); addHeaderItems(); addFooterItems(); initializeFolderIcons(); } private void addHeaderItems() { private AccountHeader buildAccountHeader() { AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder() .withActivity(parent) //.withTextColorRes(R.color.primary_text_secondary_when_activated_material) .withTranslucentStatusBar(false); if (!K9.isHideSpecialAccounts()) { drawer.addItems(new PrimaryDrawerItem() headerBuilder.addProfiles(new ProfileDrawerItem() .withNameShown(true) .withName(R.string.integrated_inbox_title) .withIcon(getResId(R.attr.iconUnifiedInbox)) .withIdentifier(DRAWER_ID_UNIFIED_INBOX), new DividerDrawerItem()); .withSetSelected(unifiedInboxSelected) .withIdentifier(DRAWER_ID_UNIFIED_INBOX) ); } headerItemCount += 2; List <Account> 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() { Loading Loading @@ -130,23 +188,36 @@ 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<List<Folder>>() { @Override public void onChanged(@Nullable List<Folder> 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; } } }; } Loading Loading @@ -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() { Loading app/ui/src/main/res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,6 @@ <color name="status_ok_checkmark">#7bad45</color> <color name="drawer_background">#666666</color> <color name="material_drawer_header_selection_text">@color/material_drawer_primary_text</color> </resources> app/ui/src/main/res/values/themes.xml +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ <item name="material_drawer_divider">@color/material_drawer_dark_divider</item> <item name="material_drawer_selected">@color/material_drawer_dark_selected</item> <item name="material_drawer_selected_text">@color/material_drawer_dark_selected_text</item> <item name="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item> <item name="material_drawer_header_selection_text">@color/material_drawer_dark_header_selection_text</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> <item name="iconUnifiedInbox">@drawable/ic_inbox_multiple_dark</item> Loading Loading
app/ui/src/main/java/com/fsck/k9/activity/Accounts.java +11 −0 Original line number Diff line number Diff line Loading @@ -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<Account> disabledAccounts = new ArrayList<>(); disabledAccounts.add(account); Loading
app/ui/src/main/java/com/fsck/k9/activity/MessageList.java +1 −9 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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<List<Folder>>() { @Override public void onChanged(@Nullable List<Folder> folders) { drawer.setUserFolders(folders); } }); drawer.updateUserAccountsAndFolders(account); } findFragments(); Loading
app/ui/src/main/java/com/fsck/k9/ui/K9Drawer.java +94 −22 Original line number Diff line number Diff line 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; Loading @@ -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; Loading @@ -48,9 +63,11 @@ public class K9Drawer { private int iconFolderResId; private final List<Long> userFolderDrawerIds = new ArrayList<>(); private final List<Long> 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; Loading @@ -64,24 +81,65 @@ public class K9Drawer { .withOnDrawerItemClickListener(createItemClickListener()) .withOnDrawerListener(parent.createOnDrawerListener()) .withSavedInstance(savedInstanceState) .withAccountHeader(buildAccountHeader()) .build(); addHeaderItems(); addFooterItems(); initializeFolderIcons(); } private void addHeaderItems() { private AccountHeader buildAccountHeader() { AccountHeaderBuilder headerBuilder = new AccountHeaderBuilder() .withActivity(parent) //.withTextColorRes(R.color.primary_text_secondary_when_activated_material) .withTranslucentStatusBar(false); if (!K9.isHideSpecialAccounts()) { drawer.addItems(new PrimaryDrawerItem() headerBuilder.addProfiles(new ProfileDrawerItem() .withNameShown(true) .withName(R.string.integrated_inbox_title) .withIcon(getResId(R.attr.iconUnifiedInbox)) .withIdentifier(DRAWER_ID_UNIFIED_INBOX), new DividerDrawerItem()); .withSetSelected(unifiedInboxSelected) .withIdentifier(DRAWER_ID_UNIFIED_INBOX) ); } headerItemCount += 2; List <Account> 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() { Loading Loading @@ -130,23 +188,36 @@ 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<List<Folder>>() { @Override public void onChanged(@Nullable List<Folder> 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; } } }; } Loading Loading @@ -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() { Loading
app/ui/src/main/res/values/colors.xml +2 −0 Original line number Diff line number Diff line Loading @@ -9,4 +9,6 @@ <color name="status_ok_checkmark">#7bad45</color> <color name="drawer_background">#666666</color> <color name="material_drawer_header_selection_text">@color/material_drawer_primary_text</color> </resources>
app/ui/src/main/res/values/themes.xml +1 −1 Original line number Diff line number Diff line Loading @@ -116,7 +116,7 @@ <item name="material_drawer_divider">@color/material_drawer_dark_divider</item> <item name="material_drawer_selected">@color/material_drawer_dark_selected</item> <item name="material_drawer_selected_text">@color/material_drawer_dark_selected_text</item> <item name="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item> <item name="material_drawer_header_selection_text">@color/material_drawer_dark_header_selection_text</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> <item name="iconUnifiedInbox">@drawable/ic_inbox_multiple_dark</item> Loading