Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package com.android.mail.ui; |
| 19 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
| 21 | import android.app.ListFragment; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 23 | import android.content.res.Resources; |
Mindy Pereira | 6d8e7fe | 2012-07-26 16:02:49 -0700 | [diff] [blame] | 24 | import android.database.DataSetObserver; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Parcelable; |
| 28 | import android.view.LayoutInflater; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.view.ViewGroup; |
| 31 | import android.view.ViewGroup.MarginLayoutParams; |
| 32 | import android.widget.AdapterView; |
| 33 | import android.widget.AdapterView.OnItemLongClickListener; |
| 34 | import android.widget.ListView; |
| 35 | import android.widget.TextView; |
| 36 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 37 | import com.android.mail.ConversationListContext; |
Marc Blank | f362695 | 2012-02-28 17:06:05 -0800 | [diff] [blame] | 38 | import com.android.mail.R; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 39 | import com.android.mail.browse.ConversationCursor; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 40 | import com.android.mail.browse.ConversationItemView; |
Mindy Pereira | 12fe37a | 2012-08-15 10:02:57 -0700 | [diff] [blame^] | 41 | import com.android.mail.browse.ConversationItemViewModel; |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 42 | import com.android.mail.browse.ConversationListFooterView; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 43 | import com.android.mail.providers.Account; |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 44 | import com.android.mail.providers.AccountObserver; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 45 | import com.android.mail.providers.Conversation; |
Mindy Pereira | 4f166de | 2012-02-14 13:40:58 -0800 | [diff] [blame] | 46 | import com.android.mail.providers.Folder; |
Vikram Aggarwal | 7d81600 | 2012-04-17 17:06:41 -0700 | [diff] [blame] | 47 | import com.android.mail.providers.Settings; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 48 | import com.android.mail.providers.UIProvider; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 49 | import com.android.mail.providers.UIProvider.AccountCapabilities; |
| 50 | import com.android.mail.providers.UIProvider.FolderCapabilities; |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 51 | import com.android.mail.providers.UIProvider.Swipe; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 52 | import com.android.mail.ui.SwipeableListView.SwipeCompleteListener; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 53 | import com.android.mail.ui.ViewMode.ModeChangeListener; |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 54 | import com.android.mail.utils.LogTag; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 55 | import com.android.mail.utils.LogUtils; |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 56 | import com.android.mail.utils.Utils; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 57 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 58 | import java.util.Collection; |
Mindy Pereira | fe06bea | 2012-02-16 08:15:14 -0800 | [diff] [blame] | 59 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 60 | /** |
| 61 | * The conversation list UI component. |
| 62 | */ |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 63 | public final class ConversationListFragment extends ListFragment implements |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 64 | OnItemLongClickListener, ModeChangeListener, SwipeCompleteListener { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 65 | // Keys used to pass data to {@link ConversationListFragment}. |
| 66 | private static final String CONVERSATION_LIST_KEY = "conversation-list"; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 67 | // Key used to keep track of the scroll state of the list. |
| 68 | private static final String LIST_STATE_KEY = "list-state"; |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 69 | private static final String LOG_TAG = LogTag.getLogTag(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 70 | |
Vikram Aggarwal | d7a12cd | 2012-02-03 09:36:20 -0800 | [diff] [blame] | 71 | // True if we are on a tablet device |
| 72 | private static boolean mTabletDevice; |
| 73 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 74 | /** |
| 75 | * Frequency of update of timestamps. Initialized in {@link #onCreate(Bundle)} and final |
| 76 | * afterwards. |
| 77 | */ |
| 78 | private static int TIMESTAMP_UPDATE_INTERVAL = 0; |
| 79 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 80 | private ControllableActivity mActivity; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 81 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 82 | // Control state. |
| 83 | private ConversationListCallbacks mCallbacks; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 84 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 85 | private final Handler mHandler = new Handler(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 86 | // List save state. |
| 87 | private Parcelable mListSavedState; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 88 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 89 | // The internal view objects. |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 90 | private SwipeableListView mListView; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 91 | |
| 92 | private TextView mSearchResultCountTextView; |
| 93 | private TextView mSearchStatusTextView; |
| 94 | |
| 95 | private View mSearchStatusView; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 96 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 97 | /** |
| 98 | * Current Account being viewed |
| 99 | */ |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 100 | private Account mAccount; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 101 | /** |
Mindy Pereira | 30fd47b | 2012-03-09 09:24:00 -0800 | [diff] [blame] | 102 | * Current folder being viewed. |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 103 | */ |
Mindy Pereira | 4f166de | 2012-02-14 13:40:58 -0800 | [diff] [blame] | 104 | private Folder mFolder; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 105 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 106 | /** |
| 107 | * A simple method to update the timestamps of conversations periodically. |
| 108 | */ |
| 109 | private Runnable mUpdateTimestampsRunnable = null; |
| 110 | |
| 111 | private ConversationListContext mViewContext; |
| 112 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 113 | private AnimatedAdapter mListAdapter; |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 114 | |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 115 | private ConversationListFooterView mFooterView; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 116 | private int mSwipeAction; |
Andrew Sapperstein | c2c9dc1 | 2012-07-02 18:17:32 -0700 | [diff] [blame] | 117 | private ErrorListener mErrorListener; |
Mindy Pereira | e3c7b0b | 2012-07-26 16:28:34 -0700 | [diff] [blame] | 118 | private DataSetObserver mFolderObserver; |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 119 | private DataSetObserver mConversationListStatusObserver; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 120 | |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 121 | private ConversationSelectionSet mSelectedSet; |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 122 | private final AccountObserver mAccountObserver = new AccountObserver() { |
| 123 | @Override |
| 124 | public void onChanged(Account newAccount) { |
| 125 | mAccount = newAccount; |
| 126 | setSwipeAction(); |
| 127 | } |
| 128 | }; |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 129 | |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Constructor needs to be public to handle orientation changes and activity lifecycle events. |
| 132 | */ |
Paul Westbrook | efc9f12 | 2012-02-21 11:14:49 -0800 | [diff] [blame] | 133 | public ConversationListFragment() { |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 134 | super(); |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Mindy Pereira | 6d8e7fe | 2012-07-26 16:02:49 -0700 | [diff] [blame] | 137 | // update the pager title strip as the Folder's conversation count changes |
| 138 | private class FolderObserver extends DataSetObserver { |
| 139 | @Override |
| 140 | public void onChanged() { |
Andy Huang | 7591d2f | 2012-07-26 16:48:06 -0700 | [diff] [blame] | 141 | onFolderUpdated(mActivity.getFolderController().getFolder()); |
Mindy Pereira | 6d8e7fe | 2012-07-26 16:02:49 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 145 | private class ConversationListStatusObserver extends DataSetObserver { |
| 146 | @Override |
| 147 | public void onChanged() { |
| 148 | // update footer |
| 149 | onConversationListStatusUpdated(); |
| 150 | } |
| 151 | } |
| 152 | |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 153 | /** |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 154 | * Creates a new instance of {@link ConversationListFragment}, initialized to display |
| 155 | * conversation list context. |
| 156 | */ |
| 157 | public static ConversationListFragment newInstance(ConversationListContext viewContext) { |
| 158 | ConversationListFragment fragment = new ConversationListFragment(); |
| 159 | Bundle args = new Bundle(); |
| 160 | args.putBundle(CONVERSATION_LIST_KEY, viewContext.toBundle()); |
| 161 | fragment.setArguments(args); |
| 162 | return fragment; |
| 163 | } |
| 164 | |
| 165 | /** |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 166 | * Show the header if the current conversation list is showing search results. |
| 167 | */ |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 168 | void configureSearchResultHeader() { |
Mindy Pereira | 755fd6e | 2012-03-21 15:15:44 -0700 | [diff] [blame] | 169 | if (mActivity == null) { |
| 170 | return; |
| 171 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 172 | // Only show the header if the context is for a search result |
| 173 | final Resources res = getResources(); |
Vikram Aggarwal | ae4ea99 | 2012-08-07 09:56:02 -0700 | [diff] [blame] | 174 | final boolean showHeader = ConversationListContext.isSearchResult(mViewContext); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 175 | // TODO(viki): This code contains intimate understanding of the view. Much of this logic |
| 176 | // needs to reside in a separate class that handles the text view in isolation. Then, |
| 177 | // that logic can be reused in other fragments. |
| 178 | if (showHeader) { |
| 179 | mSearchStatusTextView.setText(res.getString(R.string.search_results_searching_header)); |
| 180 | // Initially reset the count |
| 181 | mSearchResultCountTextView.setText(""); |
| 182 | } |
| 183 | mSearchStatusView.setVisibility(showHeader ? View.VISIBLE : View.GONE); |
| 184 | int marginTop = showHeader ? (int) res.getDimension(R.dimen.notification_view_height) : 0; |
| 185 | MarginLayoutParams layoutParams = (MarginLayoutParams) mListView.getLayoutParams(); |
| 186 | layoutParams.topMargin = marginTop; |
| 187 | mListView.setLayoutParams(layoutParams); |
| 188 | } |
| 189 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 190 | /** |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 191 | * Show the header if the current conversation list is showing search results. |
| 192 | */ |
| 193 | private void updateSearchResultHeader(int count) { |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 194 | if (mActivity == null) { |
| 195 | return; |
| 196 | } |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 197 | // Only show the header if the context is for a search result |
| 198 | final Resources res = getResources(); |
Vikram Aggarwal | ae4ea99 | 2012-08-07 09:56:02 -0700 | [diff] [blame] | 199 | final boolean showHeader = ConversationListContext.isSearchResult(mViewContext); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 200 | if (showHeader) { |
| 201 | mSearchStatusTextView.setText(res.getString(R.string.search_results_header)); |
| 202 | mSearchResultCountTextView |
| 203 | .setText(res.getString(R.string.search_results_loaded, count)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | /** |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 208 | * Initializes all internal state for a rendering. |
| 209 | */ |
| 210 | private void initializeUiForFirstDisplay() { |
| 211 | // TODO(mindyp): find some way to make the notification container more re-usable. |
| 212 | // TODO(viki): refactor according to comment in configureSearchResultHandler() |
| 213 | mSearchStatusView = mActivity.findViewById(R.id.search_status_view); |
| 214 | mSearchStatusTextView = (TextView) mActivity.findViewById(R.id.search_status_text_view); |
| 215 | mSearchResultCountTextView = (TextView) mActivity.findViewById( |
| 216 | R.id.search_result_count_view); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 219 | @Override |
| 220 | public void onActivityCreated(Bundle savedInstanceState) { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 221 | super.onActivityCreated(savedInstanceState); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 222 | // Strictly speaking, we get back an android.app.Activity from getActivity. However, the |
| 223 | // only activity creating a ConversationListContext is a MailActivity which is of type |
| 224 | // ControllableActivity, so this cast should be safe. If this cast fails, some other |
| 225 | // activity is creating ConversationListFragments. This activity must be of type |
| 226 | // ControllableActivity. |
| 227 | final Activity activity = getActivity(); |
Andy Huang | 5ff6374 | 2012-03-16 20:30:23 -0700 | [diff] [blame] | 228 | if (! (activity instanceof ControllableActivity)) { |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 229 | LogUtils.e(LOG_TAG, "ConversationListFragment expects only a ControllableActivity to" + |
| 230 | "create it. Cannot proceed."); |
| 231 | } |
| 232 | mActivity = (ControllableActivity) activity; |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 233 | // Since we now have a controllable activity, load the account from it, and register for |
| 234 | // future account changes. |
| 235 | mAccount = mAccountObserver.initialize(mActivity.getAccountController()); |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 236 | mCallbacks = mActivity.getListHandler(); |
Andrew Sapperstein | c2c9dc1 | 2012-07-02 18:17:32 -0700 | [diff] [blame] | 237 | mErrorListener = mActivity.getErrorListener(); |
Mindy Pereira | 278fd22 | 2012-07-26 15:23:10 -0700 | [diff] [blame] | 238 | // Start off with the current state of the folder being viewed. |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 239 | mFooterView = (ConversationListFooterView) LayoutInflater.from( |
| 240 | mActivity.getActivityContext()).inflate(R.layout.conversation_list_footer_view, |
| 241 | null); |
Andrew Sapperstein | 00179f1 | 2012-08-09 15:15:40 -0700 | [diff] [blame] | 242 | mFooterView.setFragmentManager(getFragmentManager()); |
Mindy Pereira | 6d8e7fe | 2012-07-26 16:02:49 -0700 | [diff] [blame] | 243 | mListAdapter = new AnimatedAdapter(mActivity.getApplicationContext(), -1, |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 244 | getConversationListCursor(), mActivity.getSelectedSet(), mActivity, mListView); |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 245 | mListAdapter.addFooter(mFooterView); |
Mindy Pereira | 6f4a6af | 2012-02-29 11:48:52 -0800 | [diff] [blame] | 246 | mListView.setAdapter(mListAdapter); |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 247 | mSelectedSet = mActivity.getSelectedSet(); |
| 248 | mListView.setSelectionSet(mSelectedSet); |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 249 | mListAdapter.hideFooter(); |
Mindy Pereira | e3c7b0b | 2012-07-26 16:28:34 -0700 | [diff] [blame] | 250 | mFolderObserver = new FolderObserver(); |
Andy Huang | 7591d2f | 2012-07-26 16:48:06 -0700 | [diff] [blame] | 251 | mActivity.getFolderController().registerFolderObserver(mFolderObserver); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 252 | mConversationListStatusObserver = new ConversationListStatusObserver(); |
| 253 | mActivity.getConversationUpdater().registerConversationListObserver( |
| 254 | mConversationListStatusObserver); |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 255 | mTabletDevice = Utils.useTabletUI(mActivity.getApplicationContext()); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 256 | initializeUiForFirstDisplay(); |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 257 | configureSearchResultHeader(); |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 258 | // The onViewModeChanged callback doesn't get called when the mode object is created, so |
| 259 | // force setting the mode manually this time around. |
Mindy Pereira | f96ec32 | 2012-03-02 14:06:33 -0800 | [diff] [blame] | 260 | onViewModeChanged(mActivity.getViewMode().getMode()); |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 261 | mActivity.getViewMode().addListener(this); |
Paul Westbrook | 0e3fd9d | 2012-04-20 02:02:23 -0700 | [diff] [blame] | 262 | // Restore the list state |
| 263 | if (mListSavedState != null) { |
| 264 | mListView.onRestoreInstanceState(mListSavedState); |
| 265 | |
| 266 | // TODO: find a better way to unset the selected item when restoring |
| 267 | mListView.clearChoices(); |
| 268 | } |
| 269 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 270 | if (mActivity.isFinishing()) { |
| 271 | // Activity is finishing, just bail. |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | // Show list and start loading list. |
| 276 | showList(); |
Mindy Pereira | 4765c5c | 2012-07-19 11:58:22 -0700 | [diff] [blame] | 277 | ToastBarOperation pendingOp = mActivity.getPendingToastOperation(); |
| 278 | if (pendingOp != null) { |
| 279 | // Clear the pending operation |
| 280 | mActivity.setPendingToastOperation(null); |
| 281 | mActivity.onUndoAvailable(pendingOp); |
| 282 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 285 | public AnimatedAdapter getAnimatedAdapter() { |
| 286 | return mListAdapter; |
| 287 | } |
| 288 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 289 | @Override |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 290 | public void onCreate(Bundle savedState) { |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 291 | super.onCreate(savedState); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 292 | |
| 293 | // Initialize fragment constants from resources |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 294 | final Resources res = getResources(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 295 | TIMESTAMP_UPDATE_INTERVAL = res.getInteger(R.integer.timestamp_update_interval); |
| 296 | mUpdateTimestampsRunnable = new Runnable(){ |
| 297 | @Override |
| 298 | public void run() { |
| 299 | mListView.invalidateViews(); |
| 300 | mHandler.postDelayed(mUpdateTimestampsRunnable, TIMESTAMP_UPDATE_INTERVAL); |
| 301 | } |
| 302 | }; |
| 303 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 304 | // Get the context from the arguments |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 305 | final Bundle args = getArguments(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 306 | mViewContext = ConversationListContext.forBundle(args.getBundle(CONVERSATION_LIST_KEY)); |
Mindy Pereira | 3982e23 | 2012-02-29 15:00:34 -0800 | [diff] [blame] | 307 | mAccount = mViewContext.account; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 308 | // TODO(mindyp): do we want this as a setting? |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 309 | mSwipeAction = mAccount.supportsCapability(AccountCapabilities.ARCHIVE) ? |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 310 | R.id.archive : R.id.delete; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 311 | if (savedState != null) { |
| 312 | mListSavedState = savedState.getParcelable(LIST_STATE_KEY); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 313 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 314 | setRetainInstance(true); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public View onCreateView(LayoutInflater inflater, |
| 319 | ViewGroup container, Bundle savedInstanceState) { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 320 | View rootView = inflater.inflate(R.layout.conversation_list, null); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 321 | mListView = (SwipeableListView) rootView.findViewById(android.R.id.list); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 322 | mListView.setHeaderDividersEnabled(false); |
Mindy Pereira | 14f64ec | 2012-08-14 17:14:02 -0700 | [diff] [blame] | 323 | mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 324 | mListView.setOnItemLongClickListener(this); |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 325 | mListView.enableSwipe(mAccount.supportsCapability(AccountCapabilities.UNDO)); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 326 | // Note - we manually save/restore the listview state. |
| 327 | mListView.setSaveEnabled(false); |
Marc Blank | 2af0cf3 | 2012-03-01 19:24:13 -0800 | [diff] [blame] | 328 | |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 329 | ConversationCursor conversationListCursor = getConversationListCursor(); |
Marc Blank | 2af0cf3 | 2012-03-01 19:24:13 -0800 | [diff] [blame] | 330 | // Belt and suspenders here; make sure we do any necessary sync of the ConversationCursor |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 331 | if (conversationListCursor != null && conversationListCursor.isRefreshReady()) { |
| 332 | conversationListCursor.sync(); |
Marc Blank | 2af0cf3 | 2012-03-01 19:24:13 -0800 | [diff] [blame] | 333 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 334 | return rootView; |
| 335 | } |
| 336 | |
| 337 | @Override |
| 338 | public void onDestroyView() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 339 | mListSavedState = mListView.onSaveInstanceState(); |
| 340 | |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 341 | // Clear the list's adapter |
| 342 | mListAdapter.destroy(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 343 | mListView.setAdapter(null); |
| 344 | |
Vikram Aggarwal | d7a12cd | 2012-02-03 09:36:20 -0800 | [diff] [blame] | 345 | mActivity.unsetViewModeListener(this); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 346 | if (!mActivity.isChangingConfigurations()) { |
| 347 | mActivity.getLoaderManager().destroyLoader(mViewContext.hashCode()); |
| 348 | } |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 349 | if (mFolderObserver != null) { |
Andy Huang | 7591d2f | 2012-07-26 16:48:06 -0700 | [diff] [blame] | 350 | mActivity.getFolderController().unregisterFolderObserver(mFolderObserver); |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 351 | mFolderObserver = null; |
| 352 | } |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 353 | if (mConversationListStatusObserver != null) { |
| 354 | mActivity.getConversationUpdater().unregisterConversationListObserver( |
| 355 | mConversationListStatusObserver); |
| 356 | mConversationListStatusObserver = null; |
| 357 | } |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 358 | mAccountObserver.unregisterAndDestroy(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 359 | super.onDestroyView(); |
| 360 | } |
| 361 | |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 362 | /** |
| 363 | * There are three binary variables, which determine what we do with a message. |
| 364 | * checkbEnabled: Whether check boxes are enabled or not (forced true on tablet) |
| 365 | * cabModeOn: Whether CAB mode is currently on or not. |
| 366 | * pressType: long or short tap |
| 367 | * (There is a third possibility: phone or tablet, but they have <em>identical</em> behavior) |
| 368 | * The matrix of possibilities is: |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 369 | * <p>Long tap: |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 370 | * Always toggle selection of conversation. If CAB mode is not started, then start it. |
| 371 | * <pre> |
| 372 | * | Checkboxes | No Checkboxes |
| 373 | * ----------+------------+--------------- |
| 374 | * CAB mode | Select | Select |
| 375 | * List mode | Select | Select |
| 376 | * |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 377 | * </pre> |
| 378 | * Reference: http://b/issue?id=6392199 |
| 379 | * <p> |
| 380 | * {@inheritDoc} |
| 381 | */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 382 | @Override |
| 383 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 384 | // Ignore anything that is not a conversation item. Could be a footer. |
| 385 | if (!(view instanceof ConversationItemView)) { |
| 386 | return true; |
| 387 | } |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 388 | ((ConversationItemView) view).toggleCheckMark(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 389 | return true; |
| 390 | } |
| 391 | |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 392 | /** |
| 393 | * See the comment for {@link #onItemLongClick(AdapterView, View, int, long)}. |
| 394 | * <p>Short tap behavior: |
| 395 | * <pre> |
| 396 | * | Checkboxes | No Checkboxes |
| 397 | * ----------+------------+--------------- |
| 398 | * CAB mode | Peek | Select |
| 399 | * List mode | Peek | Peek |
| 400 | * </pre> |
| 401 | * Reference: http://b/issue?id=6392199 |
| 402 | * <p> |
| 403 | * {@inheritDoc} |
| 404 | */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 405 | @Override |
Vikram Aggarwal | 54452ae | 2012-03-13 15:29:00 -0700 | [diff] [blame] | 406 | public void onListItemClick(ListView l, View view, int position, long id) { |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 407 | // Ignore anything that is not a conversation item. Could be a footer. |
| 408 | if (!(view instanceof ConversationItemView)) { |
| 409 | return; |
| 410 | } |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 411 | if (mAccount.settings.hideCheckboxes && !mSelectedSet.isEmpty()) { |
| 412 | ((ConversationItemView) view).toggleCheckMark(); |
| 413 | } else { |
| 414 | viewConversation(position); |
| 415 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | @Override |
| 419 | public void onPause() { |
| 420 | super.onPause(); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void onSaveInstanceState(Bundle outState) { |
| 425 | super.onSaveInstanceState(outState); |
| 426 | if (mListView != null) { |
| 427 | outState.putParcelable(LIST_STATE_KEY, mListView.onSaveInstanceState()); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | @Override |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 432 | public void onStart() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 433 | super.onStart(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 434 | mHandler.postDelayed(mUpdateTimestampsRunnable, TIMESTAMP_UPDATE_INTERVAL); |
| 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public void onStop() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 439 | super.onStop(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 440 | mHandler.removeCallbacks(mUpdateTimestampsRunnable); |
| 441 | } |
| 442 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 443 | @Override |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 444 | public void onViewModeChanged(int newMode) { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 445 | // Change the divider based on view mode. |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 446 | if (mTabletDevice) { |
| 447 | if (newMode == ViewMode.CONVERSATION) { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 448 | mListView.setBackgroundResource(R.drawable.panel_conversation_leftstroke); |
Mindy Pereira | de1c859 | 2012-08-10 14:54:31 -0700 | [diff] [blame] | 449 | } else if (newMode == ViewMode.CONVERSATION_LIST |
| 450 | || newMode == ViewMode.SEARCH_RESULTS_LIST) { |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 451 | // There are no selected conversations when in conversation |
| 452 | // list mode. |
Mindy Pereira | 62c5af8 | 2012-03-05 10:08:38 -0800 | [diff] [blame] | 453 | mListView.clearChoices(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 454 | mListView.setBackgroundDrawable(null); |
| 455 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 456 | } else { |
| 457 | mListView.setBackgroundDrawable(null); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 458 | } |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 459 | if (mFooterView != null) { |
| 460 | mFooterView.onViewModeChanged(newMode); |
| 461 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 462 | } |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 463 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 464 | /** |
| 465 | * Handles a request to show a new conversation list, either from a search query or for viewing |
Mindy Pereira | 30fd47b | 2012-03-09 09:24:00 -0800 | [diff] [blame] | 466 | * a folder. This will initiate a data load, and hence must be called on the UI thread. |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 467 | */ |
| 468 | private void showList() { |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 469 | mListView.setEmptyView(null); |
Andy Huang | 7591d2f | 2012-07-26 16:48:06 -0700 | [diff] [blame] | 470 | onFolderUpdated(mActivity.getFolderController().getFolder()); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 473 | /** |
| 474 | * View the message at the given position. |
| 475 | * @param position |
| 476 | */ |
Mindy Pereira | fbe4019 | 2012-03-20 10:40:45 -0700 | [diff] [blame] | 477 | protected void viewConversation(int position) { |
Vikram Aggarwal | c769422 | 2012-04-23 13:37:01 -0700 | [diff] [blame] | 478 | LogUtils.d(LOG_TAG, "ConversationListFragment.viewConversation(%d)", position); |
Vikram Aggarwal | 3d7ca9d | 2012-05-11 14:40:36 -0700 | [diff] [blame] | 479 | setSelected(position); |
| 480 | final ConversationCursor cursor = getConversationListCursor(); |
| 481 | if (cursor != null && cursor.moveToPosition(position)) { |
| 482 | final Conversation conv = new Conversation(cursor); |
| 483 | conv.position = position; |
| 484 | mCallbacks.onConversationSelected(conv); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Sets the selected position (the highlighted conversation) to the position provided here. |
| 490 | * @param position |
| 491 | */ |
| 492 | protected final void setSelected(int position) { |
Andy Huang | 864e758 | 2012-06-29 16:42:34 -0700 | [diff] [blame] | 493 | mListView.smoothScrollToPosition(position); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 494 | } |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 495 | |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 496 | private ConversationCursor getConversationListCursor() { |
| 497 | return mCallbacks != null ? mCallbacks.getConversationListCursor() : null; |
Mindy Pereira | fe06bea | 2012-02-16 08:15:14 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /** |
Vikram Aggarwal | 54452ae | 2012-03-13 15:29:00 -0700 | [diff] [blame] | 501 | * Request a refresh of the list. No sync is carried out and none is promised. |
| 502 | */ |
| 503 | public void requestListRefresh() { |
| 504 | mListAdapter.notifyDataSetChanged(); |
| 505 | } |
| 506 | |
Vikram Aggarwal | 75daee5 | 2012-04-30 11:13:09 -0700 | [diff] [blame] | 507 | /** |
Vikram Aggarwal | 7f602f7 | 2012-04-30 16:04:06 -0700 | [diff] [blame] | 508 | * Change the UI to delete the conversations provided and then call the |
| 509 | * {@link DestructiveAction} provided here <b>after</b> the UI has been updated. |
| 510 | * @param conversations |
Vikram Aggarwal | 75daee5 | 2012-04-30 11:13:09 -0700 | [diff] [blame] | 511 | * @param action |
| 512 | */ |
Vikram Aggarwal | 7f602f7 | 2012-04-30 16:04:06 -0700 | [diff] [blame] | 513 | public void requestDelete(Collection<Conversation> conversations, DestructiveAction action) { |
Mindy Pereira | acf6039 | 2012-04-06 09:11:00 -0700 | [diff] [blame] | 514 | for (Conversation conv : conversations) { |
| 515 | conv.localDeleteOnUpdate = true; |
| 516 | } |
| 517 | // Delete the local delete items (all for now) and when done, |
| 518 | // update... |
Vikram Aggarwal | 75daee5 | 2012-04-30 11:13:09 -0700 | [diff] [blame] | 519 | mListAdapter.delete(conversations, action); |
Mindy Pereira | acf6039 | 2012-04-06 09:11:00 -0700 | [diff] [blame] | 520 | } |
Mindy Pereira | a3911aa | 2012-03-09 13:26:26 -0800 | [diff] [blame] | 521 | |
Mindy Pereira | 11dd5ef | 2012-03-10 15:10:18 -0800 | [diff] [blame] | 522 | public void onFolderUpdated(Folder folder) { |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 523 | mFolder = folder; |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 524 | setSwipeAction(); |
Mindy Pereira | 82cea48 | 2012-03-27 16:45:00 -0700 | [diff] [blame] | 525 | if (mFolder == null) { |
| 526 | return; |
| 527 | } |
Mindy Pereira | 4584a0d | 2012-03-13 14:42:14 -0700 | [diff] [blame] | 528 | mListAdapter.setFolder(mFolder); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 529 | mFooterView.setFolder(mFolder); |
| 530 | if (mFolder.lastSyncResult != UIProvider.LastSyncResult.SUCCESS) { |
| 531 | mErrorListener.onError(mFolder, false); |
| 532 | } |
Mindy Pereira | 12fe37a | 2012-08-15 10:02:57 -0700 | [diff] [blame^] | 533 | // Blow away conversation items cache. |
| 534 | ConversationItemViewModel.onFolderUpdated(mFolder); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | public void onConversationListStatusUpdated() { |
| 538 | ConversationCursor cursor = getConversationListCursor(); |
Paul Westbrook | 573b9e6 | 2012-08-02 14:56:17 -0700 | [diff] [blame] | 539 | final boolean showFooter = mFooterView.updateStatus(cursor); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 540 | Bundle extras = cursor.getExtras(); |
| 541 | int error = extras.containsKey(UIProvider.CursorExtraKeys.EXTRA_ERROR) ? |
| 542 | extras.getInt(UIProvider.CursorExtraKeys.EXTRA_ERROR) |
| 543 | : UIProvider.LastSyncResult.SUCCESS; |
| 544 | if (error != UIProvider.LastSyncResult.SUCCESS) { |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 545 | // Check the status of the folder to see if we are done loading. |
Mindy Pereira | a3911aa | 2012-03-09 13:26:26 -0800 | [diff] [blame] | 546 | updateSearchResultHeader(mFolder != null ? mFolder.totalCount : 0); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 547 | } |
Paul Westbrook | 573b9e6 | 2012-08-02 14:56:17 -0700 | [diff] [blame] | 548 | mListAdapter.setFooterVisibility(showFooter); |
Mindy Pereira | a3911aa | 2012-03-09 13:26:26 -0800 | [diff] [blame] | 549 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 550 | |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 551 | private void setSwipeAction() { |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 552 | int swipeSetting = Settings.getSwipeSetting(mAccount.settings); |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 553 | if (swipeSetting == Swipe.DISABLED |
Mindy Pereira | b807337 | 2012-08-09 14:00:10 -0700 | [diff] [blame] | 554 | || !mAccount.supportsCapability(AccountCapabilities.UNDO) |
| 555 | || (mFolder != null && mFolder.isTrash())) { |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 556 | mListView.enableSwipe(false); |
| 557 | } else { |
| 558 | int action; |
Vikram Aggarwal | ae4ea99 | 2012-08-07 09:56:02 -0700 | [diff] [blame] | 559 | if (ConversationListContext.isSearchResult(mViewContext)) { |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 560 | action = R.id.delete; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 561 | } else if (mFolder == null) { |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame] | 562 | action = R.id.remove_folder; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 563 | } else { |
| 564 | // We have enough information to respect user settings. |
| 565 | switch (swipeSetting) { |
| 566 | case Swipe.ARCHIVE: |
| 567 | if (mAccount.supportsCapability(AccountCapabilities.ARCHIVE)) { |
| 568 | if (mFolder.supportsCapability(FolderCapabilities.ARCHIVE)) { |
| 569 | action = R.id.archive; |
| 570 | break; |
| 571 | } else if (mFolder.supportsCapability |
| 572 | (FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES)) { |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame] | 573 | action = R.id.remove_folder; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | } |
| 577 | case Swipe.DELETE: |
| 578 | default: |
| 579 | action = R.id.delete; |
| 580 | break; |
| 581 | } |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 582 | } |
| 583 | mListView.setSwipeAction(action); |
| 584 | } |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 585 | mListView.setCurrentFolder(mFolder); |
| 586 | } |
| 587 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 588 | @Override |
| 589 | public void onSwipeComplete(Collection<Conversation> conversations) { |
| 590 | Context context = getActivity().getApplicationContext(); |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 591 | ConversationCursor cc = getConversationListCursor(); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 592 | switch (mSwipeAction) { |
| 593 | case R.id.archive: |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 594 | cc.archive(context, conversations); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 595 | break; |
| 596 | case R.id.delete: |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 597 | cc.delete(context, conversations); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 598 | break; |
| 599 | } |
Mindy Pereira | 175cd3d | 2012-03-16 11:09:18 -0700 | [diff] [blame] | 600 | mListAdapter.notifyDataSetChanged(); |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 601 | if (!mActivity.getSelectedSet().isEmpty()) { |
| 602 | mActivity.getSelectedSet().clear(); |
| 603 | } |
Mindy Pereira | d3367499 | 2012-06-25 16:26:30 -0700 | [diff] [blame] | 604 | mActivity.onUndoAvailable(new ToastBarOperation(conversations.size(), mSwipeAction, |
| 605 | ToastBarOperation.UNDO)); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 606 | } |
Mindy Pereira | 21ab490 | 2012-03-19 18:48:03 -0700 | [diff] [blame] | 607 | |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 608 | public void onCursorUpdated() { |
| 609 | if (mListAdapter != null) { |
| 610 | mListAdapter.swapCursor(mCallbacks.getConversationListCursor()); |
| 611 | } |
| 612 | onFolderUpdated(mFolder); |
Mindy Pereira | 21ab490 | 2012-03-19 18:48:03 -0700 | [diff] [blame] | 613 | } |
Mindy Pereira | 1e2573b | 2012-04-17 14:34:36 -0700 | [diff] [blame] | 614 | |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 615 | public void commitDestructiveActions() { |
| 616 | if (mListView != null) { |
| 617 | mListView.commitDestructiveActions(); |
Vikram Aggarwal | 7d81600 | 2012-04-17 17:06:41 -0700 | [diff] [blame] | 618 | |
| 619 | } |
| 620 | } |
| 621 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 622 | } |