/** * Uses the current state to update the current folder {@link #mFolder} and the current account * {@link #mAccount} shown in the actionbar. Also updates the actionbar subtitle to momentarily * display the unread count if it has changed. * * @param folderChanged true if folder changed in terms of URI */ private void setFolderAndAccount(final boolean folderChanged) { // Very little can be done if the actionbar or activity is null. if (mActionBar == null || mActivity == null) { return; } if (ViewMode.isWaitingForSync(mMode)) { // Account is not synced: clear title and update the subtitle. setTitle(""); removeUnreadCount(true); return; } // Check if we should be changing the actionbar at all, and back off if not. final boolean isShowingFolder = mIsOnTablet || ViewMode.isListMode(mMode); if (!isShowingFolder) { // It isn't necessary to set the title in this case, as the title view will // be hidden return; } if (mFolder == null) { // Clear the action bar title. We don't want the app name to be shown while // waiting for the folder query to finish setTitle(""); return; } setTitle(mFolder.name); final int folderUnreadCount = mFolder.isUnreadCountHidden() ? 0 : mFolder.unreadCount; // The user shouldn't see "999+ unread messages", and then a short while later: "999+ // unread messages". So we set our unread count just past the limit. This way we can // change the subtitle the first time around but not for subsequent changes as far as the // unread count remains over the limit. final int toDisplay = (folderUnreadCount > UNREAD_LIMIT) ? (UNREAD_LIMIT + 1) : folderUnreadCount; if ((mUnreadCount != toDisplay || folderChanged) && toDisplay != 0) { setSubtitle(Utils.getUnreadMessageString(mActivity.getApplicationContext(), toDisplay)); } // Schedule a removal of unread count for the future, if there isn't one already. If the // unread count dropped to zero, remove it and show the account name right away. removeUnreadCount(toDisplay == 0); // Remember the new value for the next run mUnreadCount = toDisplay; }
/** {@inheritDoc} */ @Override public void setStartView(ViewMode mode) { setStartView(mode.name()); }