Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 037b19d7 authored by Vincent Breitmoser's avatar Vincent Breitmoser Committed by GitHub
Browse files

Merge pull request #3807 from k9mail/message_list_title

Remove custom view in MessageList toolbar
parents 4160a1b4 2f80530b
Loading
Loading
Loading
Loading
+56 −43
Original line number Diff line number Diff line
package com.fsck.k9.activity;

import android.content.Context;

import com.fsck.k9.Account;
import com.fsck.k9.ui.R;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.DI;
import com.fsck.k9.mailstore.Folder;
import com.fsck.k9.mailstore.FolderType;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.ui.folders.FolderNameFormatter;


public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
    private final FolderNameFormatter folderNameFormatter = DI.get(FolderNameFormatter.class);

    public String serverId;
    public String displayName;
    public long lastChecked;
@@ -17,7 +20,7 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
    public boolean loading;
    public String status;
    public boolean lastCheckFailed;
    public Folder folder;
    public LocalFolder folder;
    public boolean pushActive;
    public boolean moreMessages;

@@ -55,64 +58,74 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
    public FolderInfoHolder() {
    }

    public FolderInfoHolder(Context context, LocalFolder folder, Account account) {
        if (context == null) {
            throw new IllegalArgumentException("null context given");
        }
        populate(context, folder, account);
    public FolderInfoHolder(LocalFolder folder, Account account) {
        populate(folder, account);
    }

    public FolderInfoHolder(Context context, LocalFolder folder, Account account, int unreadCount) {
        populate(context, folder, account, unreadCount);
    public FolderInfoHolder(LocalFolder folder, Account account, int unreadCount) {
        populate(folder, account, unreadCount);
    }

    public void populate(Context context, LocalFolder folder, Account account, int unreadCount) {
        populate(context, folder, account);
    public void populate(LocalFolder folder, Account account, int unreadCount) {
        populate(folder, account);
        this.unreadMessageCount = unreadCount;
        folder.close();

    }

    public void populate(LocalFolder localFolder, Account account) {
        this.folder = localFolder;
        this.serverId = localFolder.getServerId();
        this.lastChecked = localFolder.getLastUpdate();

    public void populate(Context context, LocalFolder folder, Account account) {
        this.folder = folder;
        this.serverId = folder.getServerId();
        this.lastChecked = folder.getLastUpdate();
        this.status = truncateStatus(localFolder.getStatus());

        this.displayName = getDisplayName(account, localFolder);
        setMoreMessagesFromFolder(localFolder);
    }

        this.status = truncateStatus(folder.getStatus());
    private String getDisplayName(Account account, LocalFolder localFolder) {
        String serverId = localFolder.getServerId();
        Folder folder = new Folder(
                localFolder.getDatabaseId(),
                serverId,
                localFolder.getName(),
                getFolderType(account, serverId));

        this.displayName = getDisplayName(context, account, serverId, folder.getName());
        setMoreMessagesFromFolder(folder);
        return folderNameFormatter.displayName(folder);
    }

    /**
     * Returns the display name for a folder.
     *
     * <p>
     * This will return localized strings for special folders like the Inbox or the Trash folder.
     * </p>
     */
    public static String getDisplayName(Context context, Account account, String serverId, String name) {
        final String displayName;
        if (serverId.equals(account.getSpamFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_spam_fmt, serverId);
    private static FolderType getFolderType(Account account, String serverId) {
        if (serverId.equals(account.getInboxFolder())) {
            return FolderType.INBOX;
        } else if (serverId.equals(account.getOutboxFolder())) {
            return FolderType.OUTBOX;
        } else if (serverId.equals(account.getArchiveFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_archive_fmt, serverId);
            return FolderType.ARCHIVE;
        } else if (serverId.equals(account.getDraftsFolder())) {
            return FolderType.DRAFTS;
        } else if (serverId.equals(account.getSentFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_sent_fmt, serverId);
            return FolderType.SENT;
        } else if (serverId.equals(account.getSpamFolder())) {
            return FolderType.SPAM;
        } else if (serverId.equals(account.getTrashFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_trash_fmt, serverId);
        } else if (serverId.equals(account.getDraftsFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_drafts_fmt, serverId);
        } else if (serverId.equals(account.getOutboxFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_outbox);
        } else if (serverId.equals(account.getInboxFolder())) {
            displayName = context.getString(R.string.special_mailbox_name_inbox);
            return FolderType.TRASH;
        } else {
            displayName = name;
            return FolderType.REGULAR;
        }
    }

    /**
     * Returns the display name for a folder.
     *
     * Deprecated. Use {@link FolderNameFormatter} instead.
     */
    @Deprecated
    public static String getDisplayName(Account account, String serverId, String name) {
        FolderNameFormatter folderNameFormatter = DI.get(FolderNameFormatter.class);
        FolderType folderType = getFolderType(account, serverId);
        Folder folder = new Folder(-1, serverId, name, folderType);

        return displayName;
        return folderNameFormatter.displayName(folder);
    }

    public void setMoreMessagesFromFolder(LocalFolder folder) {
+3 −3
Original line number Diff line number Diff line
@@ -693,9 +693,9 @@ public class FolderList extends K9ListActivity {
                        }

                        if (holder == null) {
                            holder = new FolderInfoHolder(context, folder, FolderList.this.account, -1);
                            holder = new FolderInfoHolder(folder, FolderList.this.account, -1);
                        } else {
                            holder.populate(context, folder, FolderList.this.account, -1);
                            holder.populate(folder, FolderList.this.account, -1);

                        }
                        if (folder.isInTopGroup()) {
@@ -748,7 +748,7 @@ public class FolderList extends K9ListActivity {
                        localFolder = DI.get(LocalStoreProvider.class).getInstance(account).getFolder(folderServerId);
                        FolderInfoHolder folderHolder = getFolder(folderServerId);
                        if (folderHolder != null) {
                            folderHolder.populate(context, localFolder, FolderList.this.account, -1);
                            folderHolder.populate(localFolder, FolderList.this.account, -1);
                            folderHolder.flaggedMessageCount = -1;

                            handler.dataChanged();
+13 −50
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.fsck.k9.Account;
@@ -163,9 +161,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
    private ActionBarDrawerToggle drawerToggle;
    private K9Drawer drawer;
    private FragmentTransaction openFolderTransaction;
    private View actionBarMessageList;
    private TextView actionBarTitle;
    private TextView actionBarSubTitle;
    private Menu menu;

    private ViewGroup messageViewContainer;
@@ -179,7 +174,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
    private LocalSearch search;
    private boolean singleFolderMode;

    private ProgressBar actionBarProgress;
    private MenuItem menuButtonCheckMail;
    private View actionButtonIndeterminateProgress;
    private int lastDirection = (K9.messageViewShowNext()) ? NEXT : PREVIOUS;
@@ -551,19 +545,9 @@ public class MessageList extends K9Activity implements MessageListFragmentListen

    private void initializeActionBar() {
        actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(R.layout.actionbar_custom);

        View customView = actionBar.getCustomView();
        actionBarMessageList = customView.findViewById(R.id.actionbar_message_list);
        actionBarTitle = customView.findViewById(R.id.actionbar_title_first);
        actionBarSubTitle = customView.findViewById(R.id.actionbar_title_sub);
        actionBarProgress = customView.findViewById(R.id.actionbar_progress);
        actionButtonIndeterminateProgress = getActionButtonIndeterminateProgress();

        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    private void initializeDrawer(Bundle savedInstanceState) {
@@ -1213,21 +1197,14 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
    }

    public void setActionBarTitle(String title) {
        actionBarTitle.setText(title);
    }

    public void setActionBarSubTitle(String subTitle) {
        actionBarSubTitle.setText(subTitle);
        actionBar.setTitle(title);
    }

    @Override
    public void setMessageListTitle(String title) {
        if (displayMode != DisplayMode.MESSAGE_VIEW) {
            setActionBarTitle(title);
        }

    @Override
    public void setMessageListSubTitle(String subTitle) {
        setActionBarSubTitle(subTitle);
    }

    @Override
@@ -1479,22 +1456,14 @@ public class MessageList extends K9Activity implements MessageListFragmentListen

    @Override
    public void enableActionBarProgress(boolean enable) {
        if (menuButtonCheckMail != null && menuButtonCheckMail.isVisible()) {
            actionBarProgress.setVisibility(ProgressBar.GONE);
            if (enable) {
                menuButtonCheckMail
                        .setActionView(actionButtonIndeterminateProgress);
            } else {
                menuButtonCheckMail.setActionView(null);
        if (menuButtonCheckMail == null) {
            return;
        }

        if (menuButtonCheckMail.isVisible()) {
            menuButtonCheckMail.setActionView(enable ? actionButtonIndeterminateProgress : null);
        } else {
            if (menuButtonCheckMail != null)
            menuButtonCheckMail.setActionView(null);
            if (enable) {
                actionBarProgress.setVisibility(ProgressBar.VISIBLE);
            } else {
                actionBarProgress.setVisibility(ProgressBar.GONE);
            }
        }
    }

@@ -1621,15 +1590,13 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
    }

    private void showDefaultTitleView() {
        actionBarMessageList.setVisibility(View.VISIBLE);

        if (messageListFragment != null) {
            messageListFragment.updateTitle();
        }
    }

    private void showMessageTitleView() {
        actionBarMessageList.setVisibility(View.GONE);
        setActionBarTitle("");
    }

    @Override
@@ -1691,10 +1658,6 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
        }

        configureDrawer();

        // now we know if we are in single account mode and need a subtitle
        actionBarSubTitle.setVisibility((!singleFolderMode) ? View.GONE : View.VISIBLE);

    }

    private void configureDrawer() {
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class FolderSettings extends K9PreferenceActivity {
        addPreferencesFromResource(R.xml.folder_settings_preferences);

        String folderName = mFolder.getName();
        String displayName = FolderInfoHolder.getDisplayName(this, mAccount, folderServerId, folderName);
        String displayName = FolderInfoHolder.getDisplayName(mAccount, folderServerId, folderName);
        Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
        category.setTitle(displayName);

+2 −17
Original line number Diff line number Diff line
@@ -182,7 +182,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
     * Stores the server ID of the folder that we want to open as soon as possible after load.
     */
    private String folderServerId;
    private String folderName;

    private boolean remoteSearchPerformed = false;
    private Future<?> remoteSearchFuture = null;
@@ -318,17 +317,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
    private void setWindowTitle() {
        // regular folder content display
        if (!isManualSearch() && singleFolderMode) {
            Activity activity = getActivity();
            String displayName = FolderInfoHolder.getDisplayName(activity, account, folderServerId, folderName);

            fragmentListener.setMessageListTitle(displayName);

            String operation = activityListener.getOperation(activity);
            if (operation.length() < 1) {
                fragmentListener.setMessageListSubTitle(account.getEmail());
            } else {
                fragmentListener.setMessageListSubTitle(operation);
            }
            fragmentListener.setMessageListTitle(currentFolder.displayName);
        } else {
            // query result display.  This may be for a search folder as opposed to a user-initiated search.
            if (title != null) {
@@ -338,8 +327,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
                // This is a search result; set it to the default search result line.
                fragmentListener.setMessageListTitle(getString(R.string.search_results));
            }

            fragmentListener.setMessageListSubTitle(null);
        }
    }

@@ -582,7 +569,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
            singleFolderMode = true;
            folderServerId = search.getFolderServerIds().get(0);
            currentFolder = getFolderInfoHolder(folderServerId, account);
            folderName = currentFolder.displayName;
        }

        allAccounts = false;
@@ -641,7 +627,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
    private FolderInfoHolder getFolderInfoHolder(String folderServerId, Account account) {
        try {
            LocalFolder localFolder = MlfUtils.getOpenFolder(folderServerId, account);
            return new FolderInfoHolder(context, localFolder, account);
            return new FolderInfoHolder(localFolder, account);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
@@ -2288,7 +2274,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
        void onReplyAll(MessageReference message);
        void openMessage(MessageReference messageReference);
        void setMessageListTitle(String title);
        void setMessageListSubTitle(String subTitle);
        void onCompose(Account account);
        boolean startSearch(Account account, String folderServerId);
        void remoteSearchStarted();
Loading