blob: 0801bee43a66450323e7a50beb2ce5958fc78166 [file] [log] [blame]
Vikram Aggarwala55b36c2012-01-13 11:45:02 -08001/*******************************************************************************
2 * Copyright (C) 2012 Google Inc.
3 * Licensed to The Android Open Source Project.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17
18package com.android.mail.ui;
19
Martin Hibdon371a71c2014-02-19 13:55:28 -080020import android.app.Activity;
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080021import android.app.Fragment;
Andy Huang632721e2012-04-11 16:57:26 -070022import android.app.FragmentManager;
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080023import android.app.FragmentTransaction;
Martin Hibdon371a71c2014-02-19 13:55:28 -080024import android.content.Intent;
Mindy Pereira559c3b32012-03-01 13:17:47 -080025import android.net.Uri;
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -080026import android.os.Bundle;
Rohan Shah8e65c6d2013-03-07 16:47:25 -080027import android.support.v4.widget.DrawerLayout;
Scott Kennedyfeb5b1e2013-05-29 11:28:41 -070028import android.widget.ListView;
Rohan Shah8e65c6d2013-03-07 16:47:25 -080029
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080030import com.android.mail.ConversationListContext;
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -080031import com.android.mail.R;
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -080032import com.android.mail.providers.Account;
Mindy Pereira9b875682012-02-15 18:10:54 -080033import com.android.mail.providers.Conversation;
Mindy Pereira3982e232012-02-29 15:00:34 -080034import com.android.mail.providers.Folder;
Mindy Pereirafbe40192012-03-20 10:40:45 -070035import com.android.mail.providers.UIProvider;
Scott Kennedy259df5b2013-07-11 13:24:01 -070036import com.android.mail.utils.FolderUri;
mindypc59dd822012-11-13 10:56:21 -080037import com.android.mail.utils.Utils;
Mindy Pereirafbe40192012-03-20 10:40:45 -070038
Vikram Aggarwala55b36c2012-01-13 11:45:02 -080039/**
40 * Controller for one-pane Mail activity. One Pane is used for phones, where screen real estate is
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080041 * limited. This controller also does the layout, since the layout is simpler in the one pane case.
Vikram Aggarwala55b36c2012-01-13 11:45:02 -080042 */
43
Mindy Pereiraa76e5ae2012-03-29 08:23:48 -070044public final class OnePaneController extends AbstractActivityController {
Vikram Aggarwal2bfb5c02012-09-05 13:21:14 -070045 /** Key used to store {@link #mLastConversationListTransactionId} */
Mindy Pereira3982e232012-02-29 15:00:34 -080046 private static final String CONVERSATION_LIST_TRANSACTION_KEY = "conversation-list-transaction";
Vikram Aggarwal2bfb5c02012-09-05 13:21:14 -070047 /** Key used to store {@link #mLastConversationTransactionId}. */
Mindy Pereira3982e232012-02-29 15:00:34 -080048 private static final String CONVERSATION_TRANSACTION_KEY = "conversation-transaction";
Vikram Aggarwal2bfb5c02012-09-05 13:21:14 -070049 /** Key used to store {@link #mConversationListVisible}. */
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -070050 private static final String CONVERSATION_LIST_VISIBLE_KEY = "conversation-list-visible";
Vikram Aggarwal2bfb5c02012-09-05 13:21:14 -070051 /** Key used to store {@link #mConversationListNeverShown}. */
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -070052 private static final String CONVERSATION_LIST_NEVER_SHOWN_KEY = "conversation-list-never-shown";
Paul Westbrook2d50bcd2012-04-10 11:53:47 -070053
Mindy Pereira3982e232012-02-29 15:00:34 -080054 private static final int INVALID_ID = -1;
Vikram Aggarwal2175d0a2012-02-17 16:04:23 -080055 private boolean mConversationListVisible = false;
Mindy Pereira3982e232012-02-29 15:00:34 -080056 private int mLastConversationListTransactionId = INVALID_ID;
57 private int mLastConversationTransactionId = INVALID_ID;
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -080058 /** Whether a conversation list for this account has ever been shown.*/
59 private boolean mConversationListNeverShown = true;
Rohan Shah713156d2013-04-04 14:11:01 -070060
Vikram Aggarwala55b36c2012-01-13 11:45:02 -080061 public OnePaneController(MailActivity activity, ViewMode viewMode) {
62 super(activity, viewMode);
Vikram Aggarwala55b36c2012-01-13 11:45:02 -080063 }
64
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -080065 @Override
Andy Huang632721e2012-04-11 16:57:26 -070066 public void onRestoreInstanceState(Bundle inState) {
67 super.onRestoreInstanceState(inState);
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -070068 if (inState == null) {
69 return;
Mindy Pereira3982e232012-02-29 15:00:34 -080070 }
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -070071 mLastConversationListTransactionId =
72 inState.getInt(CONVERSATION_LIST_TRANSACTION_KEY, INVALID_ID);
73 mLastConversationTransactionId = inState.getInt(CONVERSATION_TRANSACTION_KEY, INVALID_ID);
74 mConversationListVisible = inState.getBoolean(CONVERSATION_LIST_VISIBLE_KEY);
75 mConversationListNeverShown = inState.getBoolean(CONVERSATION_LIST_NEVER_SHOWN_KEY);
Mindy Pereira3982e232012-02-29 15:00:34 -080076 }
77
78 @Override
79 public void onSaveInstanceState(Bundle outState) {
80 super.onSaveInstanceState(outState);
Mindy Pereira3982e232012-02-29 15:00:34 -080081 outState.putInt(CONVERSATION_LIST_TRANSACTION_KEY, mLastConversationListTransactionId);
82 outState.putInt(CONVERSATION_TRANSACTION_KEY, mLastConversationTransactionId);
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -070083 outState.putBoolean(CONVERSATION_LIST_VISIBLE_KEY, mConversationListVisible);
84 outState.putBoolean(CONVERSATION_LIST_NEVER_SHOWN_KEY, mConversationListNeverShown);
Mindy Pereira3982e232012-02-29 15:00:34 -080085 }
86
87 @Override
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080088 public void resetActionBarIcon() {
Rohan Shah1dd054f2013-04-01 11:23:44 -070089 // Calling resetActionBarIcon should never remove the up affordance
90 // even when waiting for sync (Folder list should still show with one
91 // account. Currently this method is blank to avoid any changes.
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -080092 }
93
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -070094 /**
Vikram Aggarwal7c7043b2012-10-29 17:15:39 -070095 * Returns true if the candidate URI is the URI for the default inbox for the given account.
Vikram Aggarwal3e068ba2013-03-05 17:21:21 -080096 * @param candidate the URI to check
97 * @param account the account whose default Inbox the candidate might be
98 * @return true if the candidate is indeed the default inbox for the given account.
Vikram Aggarwal7c7043b2012-10-29 17:15:39 -070099 */
Scott Kennedy259df5b2013-07-11 13:24:01 -0700100 private static boolean isDefaultInbox(FolderUri candidate, Account account) {
Vikram Aggarwal3e068ba2013-03-05 17:21:21 -0800101 return (candidate != null && account != null)
102 && candidate.equals(account.settings.defaultInbox);
Vikram Aggarwal7c7043b2012-10-29 17:15:39 -0700103 }
104
105 /**
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700106 * Returns true if the user is currently in the conversation list view, viewing the default
107 * inbox.
Vikram Aggarwal3e068ba2013-03-05 17:21:21 -0800108 * @return true if user is in conversation list mode, viewing the default inbox.
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700109 */
Vikram Aggarwal2074a052012-05-30 11:11:25 -0700110 private static boolean inInbox(final Account account, final ConversationListContext context) {
111 // If we don't have valid state, then we are not in the inbox.
Vikram Aggarwal3e068ba2013-03-05 17:21:21 -0800112 return !(account == null || context == null || context.folder == null
113 || account.settings == null) && !ConversationListContext.isSearchResult(context)
Scott Kennedy259df5b2013-07-11 13:24:01 -0700114 && isDefaultInbox(context.folder.folderUri, account);
Mindy Pereira3982e232012-02-29 15:00:34 -0800115 }
116
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800117 /**
118 * On account change, carry out super implementation, load FolderListFragment
119 * into drawer (to avoid repetitive calls to replaceFragment).
120 */
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800121 @Override
Vikram Aggarwal5fd8afd2013-03-13 15:28:47 -0700122 public void changeAccount(Account account) {
123 super.changeAccount(account);
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -0800124 mConversationListNeverShown = true;
Vikram Aggarwal23b528f2013-03-29 13:55:23 -0700125 closeDrawerIfOpen();
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -0800126 }
127
128 @Override
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800129 public boolean onCreate(Bundle savedInstanceState) {
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -0800130 mActivity.setContentView(R.layout.one_pane_activity);
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800131 mDrawerContainer = (DrawerLayout) mActivity.findViewById(R.id.drawer_container);
James Lemieux10fcd642014-03-03 13:01:04 -0800132 final String drawerPulloutTag = mActivity.getString(R.string.drawer_pullout_tag);
133 mDrawerPullout = mDrawerContainer.findViewWithTag(drawerPulloutTag);
Andy Huang1aced4c2013-04-29 11:38:40 -0700134 mDrawerPullout.setBackgroundResource(R.color.list_background_color);
Paul Westbrook57246a42013-04-21 09:40:22 -0700135
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800136 // The parent class sets the correct viewmode and starts the application off.
137 return super.onCreate(savedInstanceState);
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -0800138 }
139
Paul Westbrook57246a42013-04-21 09:40:22 -0700140 @Override
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -0800141 protected boolean isConversationListVisible() {
Vikram Aggarwal2175d0a2012-02-17 16:04:23 -0800142 return mConversationListVisible;
Vikram Aggarwal1ddcf0f2012-01-13 11:45:02 -0800143 }
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800144
145 @Override
146 public void onViewModeChanged(int newMode) {
147 super.onViewModeChanged(newMode);
Rohan Shaheb89afe2013-03-14 14:07:33 -0700148
Andy Huang632721e2012-04-11 16:57:26 -0700149 // When entering conversation list mode, hide and clean up any currently visible
150 // conversation.
Vikram Aggarwal49e0e992012-09-21 13:53:15 -0700151 if (ViewMode.isListMode(newMode)) {
Andy Huanga3ed8342012-08-31 17:29:39 -0700152 mPagerController.hide(true /* changeVisibility */);
Andy Huang632721e2012-04-11 16:57:26 -0700153 }
Vikram Aggarwal49e0e992012-09-21 13:53:15 -0700154 // When we step away from the conversation mode, we don't have a current conversation
155 // anymore. Let's blank it out so clients calling getCurrentConversation are not misled.
156 if (!ViewMode.isConversationMode(newMode)) {
157 setCurrentConversation(null);
158 }
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800159 }
160
161 @Override
Andy Huang6214ee42013-04-02 19:02:11 -0700162 public String toString() {
163 final StringBuilder sb = new StringBuilder(super.toString());
Andy Huang6214ee42013-04-02 19:02:11 -0700164 sb.append(" lastConvListTransId=");
165 sb.append(mLastConversationListTransactionId);
166 sb.append("}");
167 return sb.toString();
168 }
169
170 @Override
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800171 public void showConversationList(ConversationListContext listContext) {
Vikram Aggarwale128fc22012-04-04 12:33:34 -0700172 super.showConversationList(listContext);
173 enableCabMode();
Andy Huang12b3ee42013-04-24 22:49:43 -0700174 mConversationListVisible = true;
Vikram Aggarwalae4ea992012-08-07 09:56:02 -0700175 if (ConversationListContext.isSearchResult(listContext)) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800176 mViewMode.enterSearchResultsListMode();
177 } else {
178 mViewMode.enterConversationListMode();
179 }
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -0800180 final int transition = mConversationListNeverShown
181 ? FragmentTransaction.TRANSIT_FRAGMENT_FADE
Mindy Pereira9b875682012-02-15 18:10:54 -0800182 : FragmentTransaction.TRANSIT_FRAGMENT_OPEN;
Vikram Aggarwal37a20ca2013-06-06 11:19:49 -0700183 final Fragment conversationListFragment =
184 ConversationListFragment.newInstance(listContext);
Paul Westbrookbf232c32012-04-18 03:17:41 -0700185
Andy Huang6214ee42013-04-02 19:02:11 -0700186 if (!inInbox(mAccount, listContext)) {
Mindy Pereira3982e232012-02-29 15:00:34 -0800187 // Maintain fragment transaction history so we can get back to the
188 // fragment used to launch this list.
Alice Yangebeef1b2013-09-04 06:41:10 +0000189 mLastConversationListTransactionId = replaceFragment(conversationListFragment,
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800190 transition, TAG_CONVERSATION_LIST, R.id.content_pane);
Mindy Pereira3982e232012-02-29 15:00:34 -0800191 } else {
192 // If going to the inbox, clear the folder list transaction history.
193 mInbox = listContext.folder;
Alice Yangebeef1b2013-09-04 06:41:10 +0000194 replaceFragment(conversationListFragment, transition, TAG_CONVERSATION_LIST,
195 R.id.content_pane);
Andy Huang6214ee42013-04-02 19:02:11 -0700196
Paul Westbrook0e3fd9d2012-04-20 02:02:23 -0700197 // If we ever to to the inbox, we want to unset the transation id for any other
198 // non-inbox folder.
199 mLastConversationListTransactionId = INVALID_ID;
Mindy Pereira3982e232012-02-29 15:00:34 -0800200 }
Andy Huang08b0a0d2013-03-29 16:55:25 -0700201
202 mActivity.getFragmentManager().executePendingTransactions();
203
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700204 onConversationVisibilityChanged(false);
Paul Westbrook9f119c72012-04-24 16:10:59 -0700205 onConversationListVisibilityChanged(true);
Vikram Aggarwalcd09f5e2012-03-09 16:48:56 -0800206 mConversationListNeverShown = false;
Vikram Aggarwald7a12cd2012-02-03 09:36:20 -0800207 }
208
Mindy Pereira9b875682012-02-15 18:10:54 -0800209 @Override
Jin Cao30c881a2014-04-08 14:28:36 -0700210 protected void showConversation(Conversation conversation) {
211 super.showConversation(conversation);
Andy Huang12b3ee42013-04-24 22:49:43 -0700212 mConversationListVisible = false;
Vikram Aggarwal3d7ca9d2012-05-11 14:40:36 -0700213 if (conversation == null) {
Alice Yangebeef1b2013-09-04 06:41:10 +0000214 transitionBackToConversationListMode();
Vikram Aggarwal3d7ca9d2012-05-11 14:40:36 -0700215 return;
216 }
Vikram Aggarwale128fc22012-04-04 12:33:34 -0700217 disableCabMode();
Vikram Aggarwalae4ea992012-08-07 09:56:02 -0700218 if (ConversationListContext.isSearchResult(mConvListContext)) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800219 mViewMode.enterSearchResultsConversationMode();
220 } else {
221 mViewMode.enterConversationMode();
222 }
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700223 final FragmentManager fm = mActivity.getFragmentManager();
mindypf4fce122012-09-14 15:55:33 -0700224 final FragmentTransaction ft = fm.beginTransaction();
mindypf4fce122012-09-14 15:55:33 -0700225 // Switching to conversation view is an incongruous transition:
226 // we are not replacing a fragment with another fragment as
227 // usual. Instead, reveal the heretofore inert conversation
228 // ViewPager and just remove the previously visible fragment
229 // e.g. conversation list, or possibly label list?).
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700230 final Fragment f = fm.findFragmentById(R.id.content_pane);
Paul Westbrookdeab1192012-09-27 09:38:57 -0700231 // FragmentManager#findFragmentById can return fragments that are not added to the activity.
232 // We want to make sure that we don't attempt to remove fragments that are not added to the
233 // activity, as when the transaction is popped off, the FragmentManager will attempt to
234 // readd the same fragment twice
235 if (f != null && f.isAdded()) {
Vikram Aggarwal2b703c62012-09-18 13:54:15 -0700236 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
237 ft.remove(f);
238 ft.commitAllowingStateLoss();
Andy Huang6214ee42013-04-02 19:02:11 -0700239 fm.executePendingTransactions();
Andy Huang632721e2012-04-11 16:57:26 -0700240 }
Andy Huanga3ed8342012-08-31 17:29:39 -0700241 mPagerController.show(mAccount, mFolder, conversation, true /* changeVisibility */);
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700242 onConversationVisibilityChanged(true);
Paul Westbrook9f119c72012-04-24 16:10:59 -0700243 onConversationListVisibilityChanged(false);
Mindy Pereira9b875682012-02-15 18:10:54 -0800244 }
245
246 @Override
Paul Westbrook2d50bcd2012-04-10 11:53:47 -0700247 public void showWaitForInitialization() {
248 super.showWaitForInitialization();
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800249 replaceFragment(getWaitFragment(), FragmentTransaction.TRANSIT_FRAGMENT_OPEN, TAG_WAIT,
250 R.id.content_pane);
Paul Westbrook2d50bcd2012-04-10 11:53:47 -0700251 }
252
Vikram Aggarwala3f43d42012-10-25 16:21:30 -0700253 @Override
Vikram Aggarwaldd6a7ce2012-10-22 15:45:57 -0700254 protected void hideWaitForInitialization() {
Paul Westbrook2d50bcd2012-04-10 11:53:47 -0700255 transitionToInbox();
Vikram Aggarwala3f43d42012-10-25 16:21:30 -0700256 super.hideWaitForInitialization();
Paul Westbrook2d50bcd2012-04-10 11:53:47 -0700257 }
258
259 @Override
Scott Kennedy2b9d80e2013-07-30 23:03:45 -0700260 public boolean doesActionChangeConversationListVisibility(final int action) {
261 if (action == R.id.archive
262 || action == R.id.remove_folder
263 || action == R.id.delete
264 || action == R.id.discard_drafts
265 || action == R.id.mark_important
266 || action == R.id.mark_not_important
267 || action == R.id.mute
268 || action == R.id.report_spam
269 || action == R.id.mark_not_spam
270 || action == R.id.report_phishing
271 || action == R.id.refresh
Andrew Sapperstein6c570db2013-08-06 17:21:36 -0700272 || action == R.id.change_folders) {
Scott Kennedy2b9d80e2013-07-30 23:03:45 -0700273 return false;
274 } else {
275 return true;
mindyp17a8e782012-11-29 14:56:17 -0800276 }
277 }
278
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800279 /**
Vikram Aggarwal6902dcf2012-04-11 08:57:42 -0700280 * Replace the content_pane with the fragment specified here. The tag is specified so that
281 * the {@link ActivityController} can look up the fragments through the
Alice Yangebeef1b2013-09-04 06:41:10 +0000282 * {@link android.app.FragmentManager}.
Vikram Aggarwal3e068ba2013-03-05 17:21:21 -0800283 * @param fragment the new fragment to put
284 * @param transition the transition to show
285 * @param tag a tag for the fragment manager.
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800286 * @param anchor ID of view to replace fragment in
Vikram Aggarwal6902dcf2012-04-11 08:57:42 -0700287 * @return transaction ID returned when the transition is committed.
288 */
Alice Yangebeef1b2013-09-04 06:41:10 +0000289 private int replaceFragment(Fragment fragment, int transition, String tag, int anchor) {
Andy Huang6214ee42013-04-02 19:02:11 -0700290 final FragmentManager fm = mActivity.getFragmentManager();
291 FragmentTransaction fragmentTransaction = fm.beginTransaction();
Mindy Pereira9b875682012-02-15 18:10:54 -0800292 fragmentTransaction.setTransition(transition);
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800293 fragmentTransaction.replace(anchor, fragment, tag);
Andy Huang6214ee42013-04-02 19:02:11 -0700294 final int id = fragmentTransaction.commitAllowingStateLoss();
295 fm.executePendingTransactions();
296 return id;
Mindy Pereira9b875682012-02-15 18:10:54 -0800297 }
Mindy Pereira01668eb2012-02-15 19:19:05 -0800298
Mindy Pereira3982e232012-02-29 15:00:34 -0800299 /**
300 * Back works as follows:
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800301 * 1) If the drawer is pulled out (Or mid-drag), close it - handled.
302 * 2) If the user is in the folder list view, go back
Mindy Pereira3982e232012-02-29 15:00:34 -0800303 * to the account default inbox.
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800304 * 3) If the user is in a conversation list
Mindy Pereira3982e232012-02-29 15:00:34 -0800305 * that is not the inbox AND:
306 * a) they got there by going through the folder
307 * list view, go back to the folder list view.
308 * b) they got there by using some other means (account dropdown), go back to the inbox.
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800309 * 4) If the user is in a conversation, go back to the conversation list they were last in.
310 * 5) If the user is in the conversation list for the default account inbox,
Mindy Pereira3982e232012-02-29 15:00:34 -0800311 * back exits the app.
312 */
Mindy Pereira01668eb2012-02-15 19:19:05 -0800313 @Override
Andy Huangc1fb9a92013-02-11 13:09:12 -0800314 public boolean handleBackPress() {
Vikram Aggarwal2074a052012-05-30 11:11:25 -0700315 final int mode = mViewMode.getMode();
Rohan Shah8e65c6d2013-03-07 16:47:25 -0800316
Scott Kennedyaded5782013-07-16 14:21:53 -0700317 if (mode == ViewMode.SEARCH_RESULTS_LIST) {
Mindy Pereira68f2e222012-03-07 10:36:54 -0800318 mActivity.finish();
Mindy Pereirab466bcf2012-06-14 15:52:26 -0700319 } else if (mViewMode.isListMode() && !inInbox(mAccount, mConvListContext)) {
Alice Yangebeef1b2013-09-04 06:41:10 +0000320 navigateUpFolderHierarchy();
Andrew Sapperstein6c570db2013-08-06 17:21:36 -0700321 } else if (mViewMode.isConversationMode() || mViewMode.isAdMode()) {
Alice Yangebeef1b2013-09-04 06:41:10 +0000322 transitionBackToConversationListMode();
Mindy Pereira3982e232012-02-29 15:00:34 -0800323 } else {
324 mActivity.finish();
Mindy Pereira01668eb2012-02-15 19:19:05 -0800325 }
Andrew Sappersteinf8ccdcf2013-08-08 19:30:38 -0700326 mToastBar.hide(false, false /* actionClicked */);
Mindy Pereira3982e232012-02-29 15:00:34 -0800327 return true;
Mindy Pereira01668eb2012-02-15 19:19:05 -0800328 }
Mindy Pereiraf5acda42012-02-15 20:13:59 -0800329
Vikram Aggarwal649b9ea2012-08-27 12:15:20 -0700330 /**
331 * Switch to the Inbox by creating a new conversation list context that loads the inbox.
332 */
Mindy Pereira3982e232012-02-29 15:00:34 -0800333 private void transitionToInbox() {
Vikram Aggarwal7c7043b2012-10-29 17:15:39 -0700334 // The inbox could have changed, in which case we should load it again.
Scott Kennedy259df5b2013-07-11 13:24:01 -0700335 if (mInbox == null || !isDefaultInbox(mInbox.folderUri, mAccount)) {
Mindy Pereiraab486362012-03-21 18:18:53 -0700336 loadAccountInbox();
Mindy Pereira3982e232012-02-29 15:00:34 -0800337 } else {
Alice Yangebeef1b2013-09-04 06:41:10 +0000338 onFolderChanged(mInbox, false /* force */);
Mindy Pereira3982e232012-02-29 15:00:34 -0800339 }
340 }
341
Mindy Pereira118b3f62012-03-21 10:13:20 -0700342 @Override
Mindy Pereira505df5f2012-06-19 17:57:17 -0700343 public void onFolderSelected(Folder folder) {
Andy Huange764cfd2014-02-26 11:55:03 -0800344 if (mViewMode.isSearchMode()) {
Martin Hibdon371a71c2014-02-19 13:55:28 -0800345 // We are in an activity on top of the main navigation activity.
346 // We need to return to it with a result code that indicates it should navigate to
347 // a different folder.
348 final Intent intent = new Intent();
349 intent.putExtra(AbstractActivityController.EXTRA_FOLDER, folder);
350 mActivity.setResult(Activity.RESULT_OK, intent);
351 mActivity.finish();
352 return;
353 }
Vikram Aggarwalfcde31a2013-06-07 16:32:03 -0700354 setHierarchyFolder(folder);
355 super.onFolderSelected(folder);
Mindy Pereira118b3f62012-03-21 10:13:20 -0700356 }
357
Mindy Pereira3982e232012-02-29 15:00:34 -0800358 /**
359 * Up works as follows:
360 * 1) If the user is in a conversation list that is not the default account inbox,
361 * a conversation, or the folder list, up follows the rules of back.
362 * 2) If the user is in search results, up exits search
363 * mode and returns the user to whatever view they were in when they began search.
364 * 3) If the user is in the inbox, there is no up.
365 */
Mindy Pereiraf5acda42012-02-15 20:13:59 -0800366 @Override
Andy Huangc1fb9a92013-02-11 13:09:12 -0800367 public boolean handleUpPress() {
Vikram Aggarwal9da85df2012-05-09 15:34:23 -0700368 final int mode = mViewMode.getMode();
Mindy Pereira68f2e222012-03-07 10:36:54 -0800369 if (mode == ViewMode.SEARCH_RESULTS_LIST) {
370 mActivity.finish();
Vikram Aggarwal7f657182013-03-20 12:59:56 -0700371 // Not needed, the activity is going away anyway.
Tony Mantlerd9eaca82013-08-05 11:42:29 -0700372 } else if (mode == ViewMode.CONVERSATION_LIST
Rohan Shah1dd054f2013-04-01 11:23:44 -0700373 || mode == ViewMode.WAITING_FOR_ACCOUNT_INITIALIZATION) {
Scott Kennedy0eaef6f2013-07-10 17:33:57 -0700374 final boolean isTopLevel = (mFolder == null) || (mFolder.parent == Uri.EMPTY);
375
376 if (isTopLevel) {
377 // Show the drawer.
Tony Mantlerd9eaca82013-08-05 11:42:29 -0700378 toggleDrawerState();
Scott Kennedy0eaef6f2013-07-10 17:33:57 -0700379 } else {
Alice Yangebeef1b2013-09-04 06:41:10 +0000380 navigateUpFolderHierarchy();
Scott Kennedy0eaef6f2013-07-10 17:33:57 -0700381 }
Andrew Sapperstein6c570db2013-08-06 17:21:36 -0700382 } else if (mode == ViewMode.CONVERSATION || mode == ViewMode.SEARCH_RESULTS_CONVERSATION
383 || mode == ViewMode.AD) {
Mindy Pereiraf5acda42012-02-15 20:13:59 -0800384 // Same as go back.
Andy Huangc1fb9a92013-02-11 13:09:12 -0800385 handleBackPress();
Mindy Pereiraf5acda42012-02-15 20:13:59 -0800386 }
387 return true;
388 }
389
Alice Yangebeef1b2013-09-04 06:41:10 +0000390 private void transitionBackToConversationListMode() {
Vikram Aggarwal9da85df2012-05-09 15:34:23 -0700391 final int mode = mViewMode.getMode();
Vikram Aggarwal90d89e22012-04-27 10:38:25 -0700392 enableCabMode();
Andy Huang12b3ee42013-04-24 22:49:43 -0700393 mConversationListVisible = true;
Mindy Pereira68f2e222012-03-07 10:36:54 -0800394 if (mode == ViewMode.SEARCH_RESULTS_CONVERSATION) {
395 mViewMode.enterSearchResultsListMode();
396 } else {
397 mViewMode.enterConversationListMode();
398 }
Alice Yangebeef1b2013-09-04 06:41:10 +0000399
400 final Folder folder = mFolder != null ? mFolder : mInbox;
401 onFolderChanged(folder, true /* force */);
402
Vikram Aggarwal7dd054e2012-05-21 14:43:10 -0700403 onConversationVisibilityChanged(false);
Paul Westbrook9f119c72012-04-24 16:10:59 -0700404 onConversationListVisibilityChanged(true);
Mindy Pereiraf5acda42012-02-15 20:13:59 -0800405 }
Mindy Pereirab849dfb2012-03-07 18:13:15 -0800406
407 @Override
408 public boolean shouldShowFirstConversation() {
409 return false;
410 }
Mindy Pereirafbe40192012-03-20 10:40:45 -0700411
412 @Override
Mindy Pereirad33674992012-06-25 16:26:30 -0700413 public void onUndoAvailable(ToastBarOperation op) {
Mindy Pereira0963ef82012-04-10 11:43:01 -0700414 if (op != null && mAccount.supportsCapability(UIProvider.AccountCapabilities.UNDO)) {
Vikram Aggarwal7f602f72012-04-30 16:04:06 -0700415 final int mode = mViewMode.getMode();
Mindy Pereiradbab8fa2012-06-29 11:14:29 -0700416 final ConversationListFragment convList = getConversationListFragment();
Mindy Pereira0963ef82012-04-10 11:43:01 -0700417 switch (mode) {
Mindy Pereirab466bcf2012-06-14 15:52:26 -0700418 case ViewMode.SEARCH_RESULTS_CONVERSATION:
Mindy Pereira0963ef82012-04-10 11:43:01 -0700419 case ViewMode.CONVERSATION:
Andrew Sappersteinf8ccdcf2013-08-08 19:30:38 -0700420 mToastBar.show(getUndoClickedListener(
421 convList != null ? convList.getAnimatedAdapter() : null),
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700422 0,
mindypc59dd822012-11-13 10:56:21 -0800423 Utils.convertHtmlToPlainText
Scott Kennedy6a3d5ce2013-03-15 17:33:14 -0700424 (op.getDescription(mActivity.getActivityContext())),
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700425 true, /* showActionIcon */
426 R.string.undo,
Mindy Pereirad33674992012-06-25 16:26:30 -0700427 true, /* replaceVisibleToast */
428 op);
Mindy Pereira0963ef82012-04-10 11:43:01 -0700429 break;
Mindy Pereirab466bcf2012-06-14 15:52:26 -0700430 case ViewMode.SEARCH_RESULTS_LIST:
Mindy Pereira0963ef82012-04-10 11:43:01 -0700431 case ViewMode.CONVERSATION_LIST:
Vikram Aggarwal6902dcf2012-04-11 08:57:42 -0700432 if (convList != null) {
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700433 mToastBar.show(
434 getUndoClickedListener(convList.getAnimatedAdapter()),
435 0,
mindypc59dd822012-11-13 10:56:21 -0800436 Utils.convertHtmlToPlainText
Scott Kennedy6a3d5ce2013-03-15 17:33:14 -0700437 (op.getDescription(mActivity.getActivityContext())),
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700438 true, /* showActionIcon */
439 R.string.undo,
Mindy Pereirad33674992012-06-25 16:26:30 -0700440 true, /* replaceVisibleToast */
441 op);
Mindy Pereira4765c5c2012-07-19 11:58:22 -0700442 } else {
443 mActivity.setPendingToastOperation(op);
Vikram Aggarwal6902dcf2012-04-11 08:57:42 -0700444 }
Mindy Pereira0963ef82012-04-10 11:43:01 -0700445 break;
446 }
447 }
448 }
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700449
450 @Override
Mark Weid243d452012-10-31 16:24:08 -0700451 protected void hideOrRepositionToastBar(boolean animated) {
Andrew Sappersteinf8ccdcf2013-08-08 19:30:38 -0700452 mToastBar.hide(animated, false /* actionClicked */);
Mark Weid243d452012-10-31 16:24:08 -0700453 }
454
455 @Override
Andrew Sapperstein9d7519d2012-07-16 14:03:53 -0700456 public void onError(final Folder folder, boolean replaceVisibleToast) {
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700457 final int mode = mViewMode.getMode();
458 switch (mode) {
459 case ViewMode.SEARCH_RESULTS_LIST:
460 case ViewMode.CONVERSATION_LIST:
Andrew Sapperstein9d7519d2012-07-16 14:03:53 -0700461 showErrorToast(folder, replaceVisibleToast);
Andrew Sappersteinc2c9dc12012-07-02 18:17:32 -0700462 break;
463 default:
464 break;
465 }
466 }
Paul Westbrook30745b62012-08-19 14:10:32 -0700467
Paul Westbrook8c887ef2013-04-24 00:29:28 -0700468 @Override
469 public boolean isDrawerEnabled() {
470 // The drawer is enabled for one pane mode
471 return true;
472 }
Scott Kennedyfeb5b1e2013-05-29 11:28:41 -0700473
474 @Override
475 public int getFolderListViewChoiceMode() {
476 // By default, we do not want to allow any item to be selected in the folder list
477 return ListView.CHOICE_MODE_NONE;
478 }
Scott Kennedy103319a2013-07-26 13:35:35 -0700479
480 @Override
Scott Kennedye0d01fb2013-08-19 19:07:54 -0700481 public void launchFragment(final Fragment fragment, final int selectPosition) {
Alice Yangebeef1b2013-09-04 06:41:10 +0000482 replaceFragment(fragment, FragmentTransaction.TRANSIT_FRAGMENT_OPEN,
Scott Kennedy103319a2013-07-26 13:35:35 -0700483 TAG_CUSTOM_FRAGMENT, R.id.content_pane);
484 }
Vikram Aggarwala55b36c2012-01-13 11:45:02 -0800485}