From 689f69ca49033439a5493c07a220d9927b489fe6 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Tue, 27 Nov 2012 11:50:41 -0500 Subject: [PATCH] Provide progress indicator for searches. Searches can be slow, so users need an indicator. The indicator is also used when opening a message list or when refreshing it, or when loading more messages. This also removes some unused code. --- res/layout-land/actionbar_custom.xml | 8 ++++++ res/layout/actionbar_custom.xml | 19 ++++++------- src/com/fsck/k9/activity/MessageList.java | 28 +++++++++++++++++++ .../fsck/k9/fragment/MessageListFragment.java | 16 ++--------- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/res/layout-land/actionbar_custom.xml b/res/layout-land/actionbar_custom.xml index ee40b173b..70d16a495 100644 --- a/res/layout-land/actionbar_custom.xml +++ b/res/layout-land/actionbar_custom.xml @@ -30,6 +30,14 @@ android:textSize="12sp" /> + + + + - - \ No newline at end of file diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 31eda7daf..7fc818ca3 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -11,8 +11,10 @@ import android.support.v4.app.FragmentManager.OnBackStackChangedListener; import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -114,6 +116,9 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme private LocalSearch mSearch; private boolean mSingleFolderMode; private boolean mSingleAccountMode; + private ProgressBar mActionBarProgress; + private MenuItem mMenuButtonCheckMail; + private View mActionButtonIndeterminateProgress; /** * {@code true} if the message list should be displayed as flat list (i.e. no threading) @@ -246,6 +251,9 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme mActionBarTitle = (TextView) customView.findViewById(R.id.actionbar_title_first); mActionBarSubTitle = (TextView) customView.findViewById(R.id.actionbar_title_sub); mActionBarUnread = (TextView) customView.findViewById(R.id.actionbar_unread_count); + mActionBarProgress = (ProgressBar) customView.findViewById(R.id.actionbar_progress); + mActionButtonIndeterminateProgress = + getLayoutInflater().inflate(R.layout.actionbar_indeterminate_progress_actionview, null); mActionBar.setDisplayHomeAsUpEnabled(true); } @@ -472,6 +480,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme public boolean onCreateOptionsMenu(Menu menu) { getSupportMenuInflater().inflate(R.menu.message_list_option, menu); mMenu = menu; + mMenuButtonCheckMail= menu.findItem(R.id.check_mail); return true; } @@ -731,4 +740,23 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme // Remove action button for remote search configureMenu(mMenu); } + public void enableActionBarProgress(boolean enable) { + if (mMenuButtonCheckMail != null && mMenuButtonCheckMail.isVisible()) { + mActionBarProgress.setVisibility(ProgressBar.GONE); + if (enable) { + mMenuButtonCheckMail + .setActionView(mActionButtonIndeterminateProgress); + } else { + mMenuButtonCheckMail.setActionView(null); + } + } else { + if (mMenuButtonCheckMail != null) + mMenuButtonCheckMail.setActionView(null); + if (enable) { + mActionBarProgress.setVisibility(ProgressBar.VISIBLE); + } else { + mActionBarProgress.setVisibility(ProgressBar.GONE); + } + } + } } diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java index 578eb75c4..115ecc327 100644 --- a/src/com/fsck/k9/fragment/MessageListFragment.java +++ b/src/com/fsck/k9/fragment/MessageListFragment.java @@ -378,9 +378,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick private FontSizes mFontSizes = K9.getFontSizes(); - private MenuItem mRefreshMenuItem; private ActionMode mActionMode; - private View mActionBarProgressView; private Boolean mHasConnectivity; @@ -608,16 +606,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick } private void progress(final boolean progress) { - // Make sure we don't try this before the menu is initialized - // this could happen while the activity is initialized. - if (mRefreshMenuItem != null) { - if (progress) { - mRefreshMenuItem.setActionView(mActionBarProgressView); - } else { - mRefreshMenuItem.setActionView(null); - } - } - + mFragmentListener.enableActionBarProgress(progress); if (mPullToRefreshView != null && !progress) { mPullToRefreshView.onRefreshComplete(); } @@ -712,8 +701,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick View view = inflater.inflate(R.layout.message_list_fragment, container, false); - mActionBarProgressView = inflater.inflate(R.layout.actionbar_indeterminate_progress_actionview, null); - initializePullToRefresh(inflater, view); initializeLayout(); @@ -2699,6 +2686,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick } public interface MessageListFragmentListener { + void enableActionBarProgress(boolean enable); void setMessageListProgress(int level); void showThread(Account account, String folderName, long rootId); void showMoreFromSameSender(String senderAddress);