Merge pull request #3807 from k9mail/message_list_title

Remove custom view in MessageList toolbar
This commit is contained in:
Vincent Breitmoser 2018-12-10 19:11:49 +01:00 committed by GitHub
commit 037b19d7ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 77 additions and 223 deletions

View file

@ -1,14 +1,17 @@
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.status = truncateStatus(folder.getStatus());
this.displayName = getDisplayName(account, localFolder);
setMoreMessagesFromFolder(localFolder);
}
this.displayName = getDisplayName(context, account, serverId, folder.getName());
setMoreMessagesFromFolder(folder);
private String getDisplayName(Account account, LocalFolder localFolder) {
String serverId = localFolder.getServerId();
Folder folder = new Folder(
localFolder.getDatabaseId(),
serverId,
localFolder.getName(),
getFolderType(account, serverId));
return folderNameFormatter.displayName(folder);
}
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())) {
return FolderType.ARCHIVE;
} else if (serverId.equals(account.getDraftsFolder())) {
return FolderType.DRAFTS;
} else if (serverId.equals(account.getSentFolder())) {
return FolderType.SENT;
} else if (serverId.equals(account.getSpamFolder())) {
return FolderType.SPAM;
} else if (serverId.equals(account.getTrashFolder())) {
return FolderType.TRASH;
} else {
return FolderType.REGULAR;
}
}
/**
* Returns the display name for a folder.
*
* <p>
* This will return localized strings for special folders like the Inbox or the Trash folder.
* </p>
* Deprecated. Use {@link FolderNameFormatter} instead.
*/
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);
} else if (serverId.equals(account.getArchiveFolder())) {
displayName = context.getString(R.string.special_mailbox_name_archive_fmt, serverId);
} else if (serverId.equals(account.getSentFolder())) {
displayName = context.getString(R.string.special_mailbox_name_sent_fmt, serverId);
} 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);
} else {
displayName = name;
}
@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) {

View file

@ -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();

View file

@ -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.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);
actionButtonIndeterminateProgress = getActionButtonIndeterminateProgress();
}
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) {
setActionBarTitle(title);
}
@Override
public void setMessageListSubTitle(String subTitle) {
setActionBarSubTitle(subTitle);
if (displayMode != DisplayMode.MESSAGE_VIEW) {
setActionBarTitle(title);
}
}
@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);
}
menuButtonCheckMail.setActionView(null);
}
}
@ -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() {

View file

@ -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);

View file

@ -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();

View file

@ -1,56 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/actionbar_message_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/title_layout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/actionbar_title_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:singleLine="true"
android:textSize="14sp" />
<TextView
android:id="@+id/actionbar_title_sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp" />
</LinearLayout>
<ProgressBar
android:id="@+id/actionbar_progress"
style="?android:attr/indeterminateProgressStyle"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:visibility="gone" />
<TextView
android:id="@+id/actionbar_unread_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dip"
android:paddingRight="12dip"
android:textColor="?android:attr/textColorTertiary"
android:textSize="32sp" />
</LinearLayout>
</FrameLayout>

View file

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/actionbar_message_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/title_layout"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="@+id/actionbar_title_first"
tools:text="Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/actionbar_title_sub"
tools:text="Subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary" />
</LinearLayout>
<ProgressBar
android:id="@+id/actionbar_progress"
style="?android:attr/indeterminateProgressStyle"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:visibility="gone" />
</LinearLayout>
</FrameLayout>