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 | |
Mark Wei | 2102b2c | 2013-05-02 17:15:30 -0700 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
| 21 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 22 | import android.app.Activity; |
| 23 | import android.app.ListFragment; |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 25 | import android.content.res.Resources; |
Mindy Pereira | 6d8e7fe | 2012-07-26 16:02:49 -0700 | [diff] [blame] | 26 | import android.database.DataSetObserver; |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 27 | import android.graphics.PixelFormat; |
| 28 | import android.graphics.Rect; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 29 | import android.os.Bundle; |
| 30 | import android.os.Handler; |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 31 | import android.text.format.DateUtils; |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 32 | import android.util.TypedValue; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 33 | import android.view.LayoutInflater; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 34 | import android.view.View; |
| 35 | import android.view.ViewGroup; |
| 36 | import android.view.ViewGroup.MarginLayoutParams; |
| 37 | import android.widget.AdapterView; |
| 38 | import android.widget.AdapterView.OnItemLongClickListener; |
| 39 | import android.widget.ListView; |
| 40 | import android.widget.TextView; |
| 41 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 42 | import com.android.mail.ConversationListContext; |
Marc Blank | f362695 | 2012-02-28 17:06:05 -0800 | [diff] [blame] | 43 | import com.android.mail.R; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 44 | import com.android.mail.browse.ConversationCursor; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 45 | import com.android.mail.browse.ConversationItemView; |
Mindy Pereira | 12fe37a | 2012-08-15 10:02:57 -0700 | [diff] [blame] | 46 | import com.android.mail.browse.ConversationItemViewModel; |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 47 | import com.android.mail.browse.ConversationListFooterView; |
Alice Yang | 6427314 | 2013-04-10 18:26:56 -0700 | [diff] [blame] | 48 | import com.android.mail.browse.ToggleableItem; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 49 | import com.android.mail.providers.Account; |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 50 | import com.android.mail.providers.AccountObserver; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 51 | import com.android.mail.providers.Conversation; |
Mindy Pereira | 4f166de | 2012-02-14 13:40:58 -0800 | [diff] [blame] | 52 | import com.android.mail.providers.Folder; |
Vikram Aggarwal | 50ff0e5 | 2013-03-14 13:58:02 -0700 | [diff] [blame] | 53 | import com.android.mail.providers.FolderObserver; |
Vikram Aggarwal | 7d81600 | 2012-04-17 17:06:41 -0700 | [diff] [blame] | 54 | import com.android.mail.providers.Settings; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 55 | import com.android.mail.providers.UIProvider; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 56 | import com.android.mail.providers.UIProvider.AccountCapabilities; |
Alice Yang | 6427314 | 2013-04-10 18:26:56 -0700 | [diff] [blame] | 57 | import com.android.mail.providers.UIProvider.ConversationListIcon; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 58 | import com.android.mail.providers.UIProvider.FolderCapabilities; |
mindyp | 77c3e1b | 2012-09-11 14:05:02 -0700 | [diff] [blame] | 59 | import com.android.mail.providers.UIProvider.FolderType; |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 60 | import com.android.mail.providers.UIProvider.Swipe; |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 61 | import com.android.mail.ui.SwipeableListView.ListItemSwipedListener; |
| 62 | import com.android.mail.ui.SwipeableListView.ListItemsRemovedListener; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 63 | import com.android.mail.ui.ViewMode.ModeChangeListener; |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 64 | import com.android.mail.utils.LogTag; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 65 | import com.android.mail.utils.LogUtils; |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 66 | import com.android.mail.utils.Utils; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 67 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 68 | import java.util.Collection; |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 69 | import java.util.List; |
Mindy Pereira | fe06bea | 2012-02-16 08:15:14 -0800 | [diff] [blame] | 70 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 71 | /** |
| 72 | * The conversation list UI component. |
| 73 | */ |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 74 | public final class ConversationListFragment extends ListFragment implements |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 75 | OnItemLongClickListener, ModeChangeListener, ListItemSwipedListener { |
Vikram Aggarwal | 649b9ea | 2012-08-27 12:15:20 -0700 | [diff] [blame] | 76 | /** Key used to pass data to {@link ConversationListFragment}. */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 77 | private static final String CONVERSATION_LIST_KEY = "conversation-list"; |
Vikram Aggarwal | 649b9ea | 2012-08-27 12:15:20 -0700 | [diff] [blame] | 78 | /** Key used to keep track of the scroll state of the list. */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 79 | private static final String LIST_STATE_KEY = "list-state"; |
Vikram Aggarwal | 649b9ea | 2012-08-27 12:15:20 -0700 | [diff] [blame] | 80 | |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 81 | private static final String LOG_TAG = LogTag.getLogTag(); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 82 | /** Key used to save the ListView choice mode, since ListView doesn't save it automatically! */ |
| 83 | private static final String CHOICE_MODE_KEY = "choice-mode-key"; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 84 | |
Vikram Aggarwal | d7a12cd | 2012-02-03 09:36:20 -0800 | [diff] [blame] | 85 | // True if we are on a tablet device |
| 86 | private static boolean mTabletDevice; |
| 87 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 88 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 89 | * Frequency of update of timestamps. Initialized in |
| 90 | * {@link #onCreate(Bundle)} and final afterwards. |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 91 | */ |
| 92 | private static int TIMESTAMP_UPDATE_INTERVAL = 0; |
| 93 | |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 94 | private static long NO_NEW_MESSAGE_DURATION = 1 * DateUtils.SECOND_IN_MILLIS; |
| 95 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 96 | private ControllableActivity mActivity; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 97 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 98 | // Control state. |
| 99 | private ConversationListCallbacks mCallbacks; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 100 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 101 | private final Handler mHandler = new Handler(); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 102 | |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 103 | private ConversationListView mConversationListView; |
| 104 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 105 | // The internal view objects. |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 106 | private SwipeableListView mListView; |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 107 | |
| 108 | private TextView mSearchResultCountTextView; |
| 109 | private TextView mSearchStatusTextView; |
| 110 | |
| 111 | private View mSearchStatusView; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 112 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 113 | /** |
| 114 | * Current Account being viewed |
| 115 | */ |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 116 | private Account mAccount; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 117 | /** |
Mindy Pereira | 30fd47b | 2012-03-09 09:24:00 -0800 | [diff] [blame] | 118 | * Current folder being viewed. |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 119 | */ |
Mindy Pereira | 4f166de | 2012-02-14 13:40:58 -0800 | [diff] [blame] | 120 | private Folder mFolder; |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 121 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 122 | /** |
| 123 | * A simple method to update the timestamps of conversations periodically. |
| 124 | */ |
| 125 | private Runnable mUpdateTimestampsRunnable = null; |
| 126 | |
| 127 | private ConversationListContext mViewContext; |
| 128 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 129 | private AnimatedAdapter mListAdapter; |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 130 | |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 131 | private ConversationListFooterView mFooterView; |
Mindy Pereira | 6cc9553 | 2012-08-15 16:04:56 -0700 | [diff] [blame] | 132 | private View mEmptyView; |
Andrew Sapperstein | c2c9dc1 | 2012-07-02 18:17:32 -0700 | [diff] [blame] | 133 | private ErrorListener mErrorListener; |
Vikram Aggarwal | 50ff0e5 | 2013-03-14 13:58:02 -0700 | [diff] [blame] | 134 | private FolderObserver mFolderObserver; |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 135 | private DataSetObserver mConversationCursorObserver; |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 136 | |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 137 | private ConversationSelectionSet mSelectedSet; |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 138 | private final AccountObserver mAccountObserver = new AccountObserver() { |
| 139 | @Override |
| 140 | public void onChanged(Account newAccount) { |
| 141 | mAccount = newAccount; |
| 142 | setSwipeAction(); |
| 143 | } |
| 144 | }; |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 145 | private ConversationUpdater mUpdater; |
Vikram Aggarwal | 81a4f08 | 2012-09-28 09:19:04 -0700 | [diff] [blame] | 146 | /** Hash of the Conversation Cursor we last obtained from the controller. */ |
| 147 | private int mConversationCursorHash; |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 148 | |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 149 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 150 | * Constructor needs to be public to handle orientation changes and activity |
| 151 | * lifecycle events. |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 152 | */ |
Paul Westbrook | efc9f12 | 2012-02-21 11:14:49 -0800 | [diff] [blame] | 153 | public ConversationListFragment() { |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 154 | super(); |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 157 | private class ConversationCursorObserver extends DataSetObserver { |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 158 | @Override |
| 159 | public void onChanged() { |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 160 | onConversationListStatusUpdated(); |
| 161 | } |
| 162 | } |
| 163 | |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 164 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 165 | * Creates a new instance of {@link ConversationListFragment}, initialized |
| 166 | * to display conversation list context. |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 167 | */ |
| 168 | public static ConversationListFragment newInstance(ConversationListContext viewContext) { |
| 169 | ConversationListFragment fragment = new ConversationListFragment(); |
| 170 | Bundle args = new Bundle(); |
| 171 | args.putBundle(CONVERSATION_LIST_KEY, viewContext.toBundle()); |
| 172 | fragment.setArguments(args); |
| 173 | return fragment; |
| 174 | } |
| 175 | |
| 176 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 177 | * Show the header if the current conversation list is showing search |
| 178 | * results. |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 179 | */ |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 180 | void configureSearchResultHeader() { |
Mindy Pereira | 755fd6e | 2012-03-21 15:15:44 -0700 | [diff] [blame] | 181 | if (mActivity == null) { |
| 182 | return; |
| 183 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 184 | // Only show the header if the context is for a search result |
| 185 | final Resources res = getResources(); |
Vikram Aggarwal | ae4ea99 | 2012-08-07 09:56:02 -0700 | [diff] [blame] | 186 | final boolean showHeader = ConversationListContext.isSearchResult(mViewContext); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 187 | // TODO(viki): This code contains intimate understanding of the view. |
| 188 | // Much of this logic |
| 189 | // needs to reside in a separate class that handles the text view in |
| 190 | // isolation. Then, |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 191 | // that logic can be reused in other fragments. |
| 192 | if (showHeader) { |
| 193 | mSearchStatusTextView.setText(res.getString(R.string.search_results_searching_header)); |
| 194 | // Initially reset the count |
| 195 | mSearchResultCountTextView.setText(""); |
| 196 | } |
| 197 | mSearchStatusView.setVisibility(showHeader ? View.VISIBLE : View.GONE); |
| 198 | int marginTop = showHeader ? (int) res.getDimension(R.dimen.notification_view_height) : 0; |
| 199 | MarginLayoutParams layoutParams = (MarginLayoutParams) mListView.getLayoutParams(); |
| 200 | layoutParams.topMargin = marginTop; |
| 201 | mListView.setLayoutParams(layoutParams); |
| 202 | } |
| 203 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 204 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 205 | * Show the header if the current conversation list is showing search |
| 206 | * results. |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 207 | */ |
| 208 | private void updateSearchResultHeader(int count) { |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 209 | if (mActivity == null) { |
| 210 | return; |
| 211 | } |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 212 | // Only show the header if the context is for a search result |
| 213 | final Resources res = getResources(); |
Vikram Aggarwal | ae4ea99 | 2012-08-07 09:56:02 -0700 | [diff] [blame] | 214 | final boolean showHeader = ConversationListContext.isSearchResult(mViewContext); |
Mindy Pereira | 68f2e22 | 2012-03-07 10:36:54 -0800 | [diff] [blame] | 215 | if (showHeader) { |
| 216 | mSearchStatusTextView.setText(res.getString(R.string.search_results_header)); |
| 217 | mSearchResultCountTextView |
| 218 | .setText(res.getString(R.string.search_results_loaded, count)); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 223 | * Initializes all internal state for a rendering. |
| 224 | */ |
| 225 | private void initializeUiForFirstDisplay() { |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 226 | // TODO(mindyp): find some way to make the notification container more |
| 227 | // re-usable. |
| 228 | // TODO(viki): refactor according to comment in |
| 229 | // configureSearchResultHandler() |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 230 | mSearchStatusView = mActivity.findViewById(R.id.search_status_view); |
| 231 | mSearchStatusTextView = (TextView) mActivity.findViewById(R.id.search_status_text_view); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 232 | mSearchResultCountTextView = (TextView) mActivity |
| 233 | .findViewById(R.id.search_result_count_view); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 236 | @Override |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 237 | public void onActivityCreated(Bundle savedState) { |
| 238 | super.onActivityCreated(savedState); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 239 | // Strictly speaking, we get back an android.app.Activity from |
| 240 | // getActivity. However, the |
| 241 | // only activity creating a ConversationListContext is a MailActivity |
| 242 | // which is of type |
| 243 | // ControllableActivity, so this cast should be safe. If this cast |
| 244 | // fails, some other |
| 245 | // activity is creating ConversationListFragments. This activity must be |
| 246 | // of type |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 247 | // ControllableActivity. |
| 248 | final Activity activity = getActivity(); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 249 | if (!(activity instanceof ControllableActivity)) { |
| 250 | LogUtils.e(LOG_TAG, "ConversationListFragment expects only a ControllableActivity to" |
| 251 | + "create it. Cannot proceed."); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 252 | } |
| 253 | mActivity = (ControllableActivity) activity; |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 254 | // Since we now have a controllable activity, load the account from it, |
| 255 | // and register for |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 256 | // future account changes. |
| 257 | mAccount = mAccountObserver.initialize(mActivity.getAccountController()); |
Vikram Aggarwal | 7d60288 | 2012-02-07 15:01:20 -0800 | [diff] [blame] | 258 | mCallbacks = mActivity.getListHandler(); |
Andrew Sapperstein | c2c9dc1 | 2012-07-02 18:17:32 -0700 | [diff] [blame] | 259 | mErrorListener = mActivity.getErrorListener(); |
Mindy Pereira | 278fd22 | 2012-07-26 15:23:10 -0700 | [diff] [blame] | 260 | // Start off with the current state of the folder being viewed. |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 261 | Context activityContext = mActivity.getActivityContext(); |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 262 | mFooterView = (ConversationListFooterView) LayoutInflater.from( |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 263 | activityContext).inflate(R.layout.conversation_list_footer_view, |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 264 | null); |
Paul Westbrook | 4969e0c | 2012-08-20 14:38:39 -0700 | [diff] [blame] | 265 | mFooterView.setClickListener(mActivity); |
Alice Yang | c36fa72 | 2013-05-05 01:23:46 -0700 | [diff] [blame] | 266 | mConversationListView.setActivity(mActivity); |
Vikram Aggarwal | 81a4f08 | 2012-09-28 09:19:04 -0700 | [diff] [blame] | 267 | final ConversationCursor conversationCursor = getConversationListCursor(); |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 268 | |
| 269 | final ConversationListHelper helper = mActivity.getConversationListHelper(); |
Mark Wei | 2102b2c | 2013-05-02 17:15:30 -0700 | [diff] [blame] | 270 | final List<ConversationSpecialItemView> specialItemViews = helper != null ? |
| 271 | ImmutableList.copyOf(helper.makeConversationListSpecialViews( |
| 272 | getActivity(), mAccount, mActivity.getFolderListSelectionListener())) |
| 273 | : null; |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 274 | if (specialItemViews != null) { |
| 275 | // Attach to the LoaderManager |
| 276 | for (final ConversationSpecialItemView view : specialItemViews) { |
| 277 | view.bindLoaderManager(getLoaderManager()); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | mListAdapter = new AnimatedAdapter(mActivity.getApplicationContext(), conversationCursor, |
| 282 | mActivity.getSelectedSet(), mActivity, mListView, specialItemViews); |
Mindy Pereira | 6681f6b | 2012-03-09 13:55:54 -0800 | [diff] [blame] | 283 | mListAdapter.addFooter(mFooterView); |
Mindy Pereira | 6f4a6af | 2012-02-29 11:48:52 -0800 | [diff] [blame] | 284 | mListView.setAdapter(mListAdapter); |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 285 | mSelectedSet = mActivity.getSelectedSet(); |
| 286 | mListView.setSelectionSet(mSelectedSet); |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 287 | mListAdapter.hideFooter(); |
Vikram Aggarwal | 50ff0e5 | 2013-03-14 13:58:02 -0700 | [diff] [blame] | 288 | mFolderObserver = new FolderObserver(){ |
| 289 | @Override |
| 290 | public void onChanged(Folder newFolder) { |
| 291 | onFolderUpdated(newFolder); |
| 292 | } |
| 293 | }; |
| 294 | mFolderObserver.initialize(mActivity.getFolderController()); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 295 | mConversationCursorObserver = new ConversationCursorObserver(); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 296 | mUpdater = mActivity.getConversationUpdater(); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 297 | mUpdater.registerConversationListObserver(mConversationCursorObserver); |
Vikram Aggarwal | bcb16b9 | 2013-01-28 18:05:03 -0800 | [diff] [blame] | 298 | mTabletDevice = Utils.useTabletUI(mActivity.getApplicationContext().getResources()); |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 299 | initializeUiForFirstDisplay(); |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 300 | configureSearchResultHeader(); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 301 | // The onViewModeChanged callback doesn't get called when the mode |
| 302 | // object is created, so |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 303 | // force setting the mode manually this time around. |
Mindy Pereira | f96ec32 | 2012-03-02 14:06:33 -0800 | [diff] [blame] | 304 | onViewModeChanged(mActivity.getViewMode().getMode()); |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 305 | mActivity.getViewMode().addListener(this); |
Paul Westbrook | 0e3fd9d | 2012-04-20 02:02:23 -0700 | [diff] [blame] | 306 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 307 | if (mActivity.isFinishing()) { |
| 308 | // Activity is finishing, just bail. |
| 309 | return; |
| 310 | } |
Vikram Aggarwal | 81a4f08 | 2012-09-28 09:19:04 -0700 | [diff] [blame] | 311 | mConversationCursorHash = (conversationCursor == null) ? 0 : conversationCursor.hashCode(); |
| 312 | // Belt and suspenders here; make sure we do any necessary sync of the |
| 313 | // ConversationCursor |
| 314 | if (conversationCursor != null && conversationCursor.isRefreshReady()) { |
| 315 | conversationCursor.sync(); |
| 316 | } |
| 317 | |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 318 | // On a phone we never highlight a conversation, so the default is to select none. |
| 319 | // On a tablet, we highlight a SINGLE conversation in landscape conversation view. |
| 320 | int choice = getDefaultChoiceMode(mTabletDevice); |
| 321 | if (savedState != null) { |
| 322 | // Restore the choice mode if it was set earlier, or NONE if creating a fresh view. |
| 323 | // Choice mode here represents the current conversation only. CAB mode does not rely on |
| 324 | // the platform: checked state is a local variable {@link ConversationItemView#mChecked} |
| 325 | choice = savedState.getInt(CHOICE_MODE_KEY, choice); |
| 326 | if (savedState.containsKey(LIST_STATE_KEY)) { |
| 327 | // TODO: find a better way to unset the selected item when restoring |
| 328 | mListView.clearChoices(); |
| 329 | } |
| 330 | } |
| 331 | setChoiceMode(choice); |
| 332 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 333 | // Show list and start loading list. |
| 334 | showList(); |
Mindy Pereira | 4765c5c | 2012-07-19 11:58:22 -0700 | [diff] [blame] | 335 | ToastBarOperation pendingOp = mActivity.getPendingToastOperation(); |
| 336 | if (pendingOp != null) { |
| 337 | // Clear the pending operation |
| 338 | mActivity.setPendingToastOperation(null); |
| 339 | mActivity.onUndoAvailable(pendingOp); |
| 340 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 343 | /** |
| 344 | * Returns the default choice mode for the list based on whether the list is displayed on tablet |
| 345 | * or not. |
| 346 | * @param isTablet |
| 347 | * @return |
| 348 | */ |
| 349 | private final static int getDefaultChoiceMode(boolean isTablet) { |
| 350 | return isTablet ? ListView.CHOICE_MODE_SINGLE : ListView.CHOICE_MODE_NONE; |
| 351 | } |
| 352 | |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 353 | public AnimatedAdapter getAnimatedAdapter() { |
| 354 | return mListAdapter; |
| 355 | } |
| 356 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 357 | @Override |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 358 | public void onCreate(Bundle savedState) { |
Vikram Aggarwal | d247dc9 | 2012-02-10 15:49:01 -0800 | [diff] [blame] | 359 | super.onCreate(savedState); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 360 | |
| 361 | // Initialize fragment constants from resources |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 362 | final Resources res = getResources(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 363 | TIMESTAMP_UPDATE_INTERVAL = res.getInteger(R.integer.timestamp_update_interval); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 364 | mUpdateTimestampsRunnable = new Runnable() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public void run() { |
| 367 | mListView.invalidateViews(); |
| 368 | mHandler.postDelayed(mUpdateTimestampsRunnable, TIMESTAMP_UPDATE_INTERVAL); |
| 369 | } |
| 370 | }; |
| 371 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 372 | // Get the context from the arguments |
Vikram Aggarwal | 6c51158 | 2012-02-27 10:59:47 -0800 | [diff] [blame] | 373 | final Bundle args = getArguments(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 374 | mViewContext = ConversationListContext.forBundle(args.getBundle(CONVERSATION_LIST_KEY)); |
Mindy Pereira | 3982e23 | 2012-02-29 15:00:34 -0800 | [diff] [blame] | 375 | mAccount = mViewContext.account; |
Paul Westbrook | 80ecd89 | 2012-08-16 13:37:39 -0700 | [diff] [blame] | 376 | |
Vikram Aggarwal | 9a49c9b | 2012-08-31 10:49:33 -0700 | [diff] [blame] | 377 | setRetainInstance(false); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
Andy Huang | 9e4ca79 | 2013-02-28 14:33:43 -0800 | [diff] [blame] | 381 | public String toString() { |
| 382 | final String s = super.toString(); |
| 383 | if (mViewContext == null) { |
| 384 | return s; |
| 385 | } |
Andy Huang | c1922a9 | 2013-05-13 14:33:05 -0700 | [diff] [blame] | 386 | final StringBuilder sb = new StringBuilder(s); |
| 387 | sb.setLength(sb.length() - 1); |
| 388 | sb.append(" mListAdapter="); |
| 389 | sb.append(mListAdapter); |
| 390 | sb.append(" folder="); |
| 391 | sb.append(mViewContext.folder); |
| 392 | sb.append("}"); |
| 393 | return sb.toString(); |
Andy Huang | 9e4ca79 | 2013-02-28 14:33:43 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Override |
Vikram Aggarwal | 9a49c9b | 2012-08-31 10:49:33 -0700 | [diff] [blame] | 397 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 398 | View rootView = inflater.inflate(R.layout.conversation_list, null); |
Mindy Pereira | 6cc9553 | 2012-08-15 16:04:56 -0700 | [diff] [blame] | 399 | mEmptyView = rootView.findViewById(R.id.empty_view); |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 400 | mConversationListView = |
| 401 | (ConversationListView) rootView.findViewById(R.id.conversation_list); |
Alice Yang | 2032316 | 2013-04-17 10:37:41 -0700 | [diff] [blame] | 402 | mConversationListView.setConversationContext(mViewContext); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 403 | mListView = (SwipeableListView) rootView.findViewById(android.R.id.list); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 404 | mListView.setHeaderDividersEnabled(false); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 405 | mListView.setOnItemLongClickListener(this); |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 406 | mListView.enableSwipe(mAccount.supportsCapability(AccountCapabilities.UNDO)); |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 407 | mListView.setSwipedListener(this); |
Marc Blank | 2af0cf3 | 2012-03-01 19:24:13 -0800 | [diff] [blame] | 408 | |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 409 | if (savedState != null && savedState.containsKey(LIST_STATE_KEY)) { |
| 410 | mListView.onRestoreInstanceState(savedState.getParcelable(LIST_STATE_KEY)); |
Vikram Aggarwal | 9a49c9b | 2012-08-31 10:49:33 -0700 | [diff] [blame] | 411 | } |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 412 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 413 | return rootView; |
| 414 | } |
| 415 | |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 416 | /** |
| 417 | * Sets the choice mode of the list view |
| 418 | * @param choiceMode ListView# |
| 419 | */ |
| 420 | private final void setChoiceMode(int choiceMode) { |
| 421 | mListView.setChoiceMode(choiceMode); |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Tell the list to select nothing. |
| 426 | */ |
| 427 | public final void setChoiceNone() { |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 428 | // On a phone, the default choice mode is already none, so nothing to do. |
| 429 | if (!mTabletDevice) { |
| 430 | return; |
| 431 | } |
Andy Huang | b0be3fc | 2013-05-02 15:48:05 -0700 | [diff] [blame] | 432 | clearChoicesAndActivated(); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 433 | setChoiceMode(ListView.CHOICE_MODE_NONE); |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Tell the list to get out of selecting none. |
| 438 | */ |
| 439 | public final void revertChoiceMode() { |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 440 | // On a phone, the default choice mode is always none, so nothing to do. |
| 441 | if (!mTabletDevice) { |
| 442 | return; |
| 443 | } |
| 444 | setChoiceMode(getDefaultChoiceMode(mTabletDevice)); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 447 | @Override |
Andy Huang | 7517e3b | 2012-08-20 12:30:08 -0700 | [diff] [blame] | 448 | public void onDestroy() { |
Andy Huang | 7517e3b | 2012-08-20 12:30:08 -0700 | [diff] [blame] | 449 | super.onDestroy(); |
| 450 | } |
| 451 | |
| 452 | @Override |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 453 | public void onDestroyView() { |
Andy Huang | 7517e3b | 2012-08-20 12:30:08 -0700 | [diff] [blame] | 454 | |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 455 | // Clear the list's adapter |
| 456 | mListAdapter.destroy(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 457 | mListView.setAdapter(null); |
| 458 | |
Vikram Aggarwal | d7a12cd | 2012-02-03 09:36:20 -0800 | [diff] [blame] | 459 | mActivity.unsetViewModeListener(this); |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 460 | if (mFolderObserver != null) { |
Vikram Aggarwal | 50ff0e5 | 2013-03-14 13:58:02 -0700 | [diff] [blame] | 461 | mFolderObserver.unregisterAndDestroy(); |
Mindy Pereira | 71a8f29 | 2012-07-26 16:30:48 -0700 | [diff] [blame] | 462 | mFolderObserver = null; |
| 463 | } |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 464 | if (mConversationCursorObserver != null) { |
| 465 | mUpdater.unregisterConversationListObserver(mConversationCursorObserver); |
| 466 | mConversationCursorObserver = null; |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 467 | } |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 468 | mAccountObserver.unregisterAndDestroy(); |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 469 | getAnimatedAdapter().cleanup(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 470 | super.onDestroyView(); |
| 471 | } |
| 472 | |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 473 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 474 | * There are three binary variables, which determine what we do with a |
| 475 | * message. checkbEnabled: Whether check boxes are enabled or not (forced |
| 476 | * true on tablet) cabModeOn: Whether CAB mode is currently on or not. |
| 477 | * pressType: long or short tap (There is a third possibility: phone or |
| 478 | * tablet, but they have <em>identical</em> behavior) The matrix of |
| 479 | * possibilities is: |
| 480 | * <p> |
| 481 | * Long tap: Always toggle selection of conversation. If CAB mode is not |
| 482 | * started, then start it. |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 483 | * <pre> |
| 484 | * | Checkboxes | No Checkboxes |
| 485 | * ----------+------------+--------------- |
| 486 | * CAB mode | Select | Select |
| 487 | * List mode | Select | Select |
| 488 | * |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 489 | * </pre> |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 490 | * |
Vikram Aggarwal | 9730ea0 | 2012-08-02 12:46:19 -0700 | [diff] [blame] | 491 | * Reference: http://b/issue?id=6392199 |
| 492 | * <p> |
| 493 | * {@inheritDoc} |
| 494 | */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 495 | @Override |
| 496 | public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 497 | // Ignore anything that is not a conversation item. Could be a footer. |
| 498 | if (!(view instanceof ConversationItemView)) { |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 499 | return false; |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 500 | } |
Alice Yang | 4758e98 | 2013-04-24 20:31:34 -0700 | [diff] [blame] | 501 | ((ConversationItemView) view).toggleSelectedStateOrBeginDrag(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 502 | return true; |
| 503 | } |
| 504 | |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 505 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 506 | * See the comment for |
| 507 | * {@link #onItemLongClick(AdapterView, View, int, long)}. |
| 508 | * <p> |
| 509 | * Short tap behavior: |
| 510 | * |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 511 | * <pre> |
| 512 | * | Checkboxes | No Checkboxes |
| 513 | * ----------+------------+--------------- |
| 514 | * CAB mode | Peek | Select |
| 515 | * List mode | Peek | Peek |
| 516 | * </pre> |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 517 | * |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 518 | * Reference: http://b/issue?id=6392199 |
| 519 | * <p> |
| 520 | * {@inheritDoc} |
| 521 | */ |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 522 | @Override |
Vikram Aggarwal | 54452ae | 2012-03-13 15:29:00 -0700 | [diff] [blame] | 523 | public void onListItemClick(ListView l, View view, int position, long id) { |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 524 | // Ignore anything that is not a conversation item. Could be a footer. |
mindyp | 8694fe9 | 2012-09-25 11:07:16 -0700 | [diff] [blame] | 525 | // If we are using a keyboard, the highlighted item is the parent; |
| 526 | // otherwise, this is a direct call from the ConverationItemView |
mindyp | c03b05a | 2012-09-28 14:23:48 -0700 | [diff] [blame] | 527 | if (!(view instanceof ToggleableItem)) { |
Mindy Pereira | 1e231a6 | 2012-03-23 12:42:15 -0700 | [diff] [blame] | 528 | return; |
| 529 | } |
Alice Yang | 4758e98 | 2013-04-24 20:31:34 -0700 | [diff] [blame] | 530 | boolean showSenderImage = (mAccount.settings.convListIcon == |
| 531 | ConversationListIcon.SENDER_IMAGE); |
| 532 | if (!showSenderImage && !mSelectedSet.isEmpty()) { |
mindyp | c03b05a | 2012-09-28 14:23:48 -0700 | [diff] [blame] | 533 | ToggleableItem v = (ToggleableItem) view; |
Mark Wei | 6126d72 | 2013-04-24 21:09:43 -0700 | [diff] [blame] | 534 | v.toggleSelectedState(); |
Vikram Aggarwal | 4f1cc0b | 2012-08-02 15:16:30 -0700 | [diff] [blame] | 535 | } else { |
| 536 | viewConversation(position); |
| 537 | } |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 538 | // When a new list item is clicked, commit any existing leave behind |
mindyp | 8694fe9 | 2012-09-25 11:07:16 -0700 | [diff] [blame] | 539 | // items. Wait until we have opened the desired conversation to cause |
| 540 | // any position changes. |
Vikram Aggarwal | bcb16b9 | 2013-01-28 18:05:03 -0800 | [diff] [blame] | 541 | commitDestructiveActions(Utils.useTabletUI(mActivity.getActivityContext().getResources())); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | @Override |
Scott Kennedy | 08a079c | 2013-02-22 10:13:10 -0800 | [diff] [blame] | 545 | public void onResume() { |
| 546 | super.onResume(); |
| 547 | |
| 548 | final ConversationCursor conversationCursor = getConversationListCursor(); |
| 549 | if (conversationCursor != null) { |
| 550 | conversationCursor.handleNotificationActions(); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | @Override |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 555 | public void onPause() { |
| 556 | super.onPause(); |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public void onSaveInstanceState(Bundle outState) { |
| 561 | super.onSaveInstanceState(outState); |
| 562 | if (mListView != null) { |
| 563 | outState.putParcelable(LIST_STATE_KEY, mListView.onSaveInstanceState()); |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 564 | outState.putInt(CHOICE_MODE_KEY, mListView.getChoiceMode()); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | @Override |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 569 | public void onStart() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 570 | super.onStart(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 571 | mHandler.postDelayed(mUpdateTimestampsRunnable, TIMESTAMP_UPDATE_INTERVAL); |
| 572 | } |
| 573 | |
| 574 | @Override |
| 575 | public void onStop() { |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 576 | super.onStop(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 577 | mHandler.removeCallbacks(mUpdateTimestampsRunnable); |
| 578 | } |
| 579 | |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 580 | @Override |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 581 | public void onViewModeChanged(int newMode) { |
Vikram Aggarwal | fa131a2 | 2012-02-02 13:56:22 -0800 | [diff] [blame] | 582 | if (mTabletDevice) { |
Andy Huang | b0be3fc | 2013-05-02 15:48:05 -0700 | [diff] [blame] | 583 | if (ViewMode.isListMode(newMode)) { |
Vikram Aggarwal | 0509bba | 2013-01-29 17:11:30 -0800 | [diff] [blame] | 584 | // There are no selected conversations when in conversation list mode. |
Andy Huang | b0be3fc | 2013-05-02 15:48:05 -0700 | [diff] [blame] | 585 | clearChoicesAndActivated(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 586 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 587 | } |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 588 | if (mFooterView != null) { |
| 589 | mFooterView.onViewModeChanged(newMode); |
| 590 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 591 | } |
Mindy Pereira | b5901be | 2012-08-09 17:21:53 -0700 | [diff] [blame] | 592 | |
Andy Huang | b0be3fc | 2013-05-02 15:48:05 -0700 | [diff] [blame] | 593 | private void clearChoicesAndActivated() { |
| 594 | final int currentSelected = mListView.getCheckedItemPosition(); |
| 595 | mListView.clearChoices(); |
| 596 | // We use the activated state to show the blue highlight on tablet. Clearing the choices |
| 597 | // removes the checked state, but doesn't do anything to the activated state. We must |
| 598 | // manually clear that. |
| 599 | if (currentSelected != ListView.INVALID_POSITION) { |
| 600 | final View v = mListView.getChildAt(currentSelected); |
| 601 | if (v != null) { |
| 602 | v.setActivated(false); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 607 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 608 | * Handles a request to show a new conversation list, either from a search |
| 609 | * query or for viewing a folder. This will initiate a data load, and hence |
| 610 | * must be called on the UI thread. |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 611 | */ |
| 612 | private void showList() { |
Vikram Aggarwal | 80aeac5 | 2012-02-07 15:27:20 -0800 | [diff] [blame] | 613 | mListView.setEmptyView(null); |
Andy Huang | 7591d2f | 2012-07-26 16:48:06 -0700 | [diff] [blame] | 614 | onFolderUpdated(mActivity.getFolderController().getFolder()); |
mindyp | ca8ca2d | 2012-09-11 17:38:34 -0700 | [diff] [blame] | 615 | onConversationListStatusUpdated(); |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 616 | } |
| 617 | |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 618 | /** |
| 619 | * View the message at the given position. |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 620 | * |
| 621 | * @param position The position of the conversation in the list (as opposed to its position in |
| 622 | * the cursor) |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 623 | */ |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 624 | protected void viewConversation(final int position) { |
Vikram Aggarwal | c769422 | 2012-04-23 13:37:01 -0700 | [diff] [blame] | 625 | LogUtils.d(LOG_TAG, "ConversationListFragment.viewConversation(%d)", position); |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 626 | |
| 627 | final ConversationCursor cursor = |
| 628 | (ConversationCursor) getAnimatedAdapter().getItem(position); |
Andy Huang | 97b1096 | 2013-04-02 13:33:32 -0700 | [diff] [blame] | 629 | |
| 630 | if (cursor == null) { |
| 631 | LogUtils.e(LOG_TAG, |
| 632 | "unable to open conv at cursor pos=%s cursor=%s getPositionOffset=%s", |
| 633 | position, cursor, getAnimatedAdapter().getPositionOffset(position)); |
| 634 | return; |
| 635 | } |
| 636 | |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 637 | final Conversation conv = cursor.getConversation(); |
| 638 | /* |
| 639 | * The cursor position may be different than the position method parameter because of |
| 640 | * special views in the list. |
| 641 | */ |
| 642 | conv.position = cursor.getPosition(); |
| 643 | setSelected(conv.position, true); |
| 644 | mCallbacks.onConversationSelected(conv, false /* inLoaderCallbacks */); |
Vikram Aggarwal | 3d7ca9d | 2012-05-11 14:40:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 647 | /** |
| 648 | * Sets the selected conversation to the position given here. |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 649 | * @param cursorPosition The position of the conversation in the cursor (as opposed to |
| 650 | * in the list) |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 651 | * @param different if the currently selected conversation is different from the one provided |
| 652 | * here. This is a difference in conversations, not a difference in positions. For example, a |
| 653 | * conversation at position 2 can move to position 4 as a result of new mail. |
| 654 | */ |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 655 | public void setSelected(final int cursorPosition, boolean different) { |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 656 | if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE) { |
| 657 | return; |
| 658 | } |
Scott Kennedy | 7c8325d | 2013-02-28 10:46:10 -0800 | [diff] [blame] | 659 | |
| 660 | final int position = |
| 661 | cursorPosition + getAnimatedAdapter().getPositionOffset(cursorPosition); |
| 662 | |
mindyp | e21f886 | 2012-10-01 09:32:03 -0700 | [diff] [blame] | 663 | if (different) { |
| 664 | mListView.smoothScrollToPosition(position); |
| 665 | } |
| 666 | mListView.setItemChecked(position, true); |
| 667 | } |
| 668 | |
Vikram Aggarwal | 3d7ca9d | 2012-05-11 14:40:36 -0700 | [diff] [blame] | 669 | /** |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 670 | * Returns the cursor associated with the conversation list. |
| 671 | * @return |
Vikram Aggarwal | 3d7ca9d | 2012-05-11 14:40:36 -0700 | [diff] [blame] | 672 | */ |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 673 | private ConversationCursor getConversationListCursor() { |
| 674 | return mCallbacks != null ? mCallbacks.getConversationListCursor() : null; |
Mindy Pereira | fe06bea | 2012-02-16 08:15:14 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 678 | * Request a refresh of the list. No sync is carried out and none is |
| 679 | * promised. |
Vikram Aggarwal | 54452ae | 2012-03-13 15:29:00 -0700 | [diff] [blame] | 680 | */ |
| 681 | public void requestListRefresh() { |
| 682 | mListAdapter.notifyDataSetChanged(); |
| 683 | } |
| 684 | |
Vikram Aggarwal | 75daee5 | 2012-04-30 11:13:09 -0700 | [diff] [blame] | 685 | /** |
Vikram Aggarwal | 7f602f7 | 2012-04-30 16:04:06 -0700 | [diff] [blame] | 686 | * Change the UI to delete the conversations provided and then call the |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 687 | * {@link DestructiveAction} provided here <b>after</b> the UI has been |
| 688 | * updated. |
Vikram Aggarwal | 7f602f7 | 2012-04-30 16:04:06 -0700 | [diff] [blame] | 689 | * @param conversations |
Vikram Aggarwal | 75daee5 | 2012-04-30 11:13:09 -0700 | [diff] [blame] | 690 | * @param action |
| 691 | */ |
Vikram Aggarwal | a8e4318 | 2012-09-13 12:55:10 -0700 | [diff] [blame] | 692 | public void requestDelete(int actionId, final Collection<Conversation> conversations, |
Vikram Aggarwal | 669947b | 2013-01-10 17:05:56 -0800 | [diff] [blame] | 693 | final DestructiveAction action) { |
Mindy Pereira | acf6039 | 2012-04-06 09:11:00 -0700 | [diff] [blame] | 694 | for (Conversation conv : conversations) { |
| 695 | conv.localDeleteOnUpdate = true; |
| 696 | } |
Vikram Aggarwal | a8e4318 | 2012-09-13 12:55:10 -0700 | [diff] [blame] | 697 | final ListItemsRemovedListener listener = new ListItemsRemovedListener() { |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 698 | @Override |
| 699 | public void onListItemsRemoved() { |
| 700 | action.performAction(); |
| 701 | } |
Vikram Aggarwal | a8e4318 | 2012-09-13 12:55:10 -0700 | [diff] [blame] | 702 | }; |
| 703 | final SwipeableListView listView = (SwipeableListView) getListView(); |
| 704 | if (listView.getSwipeAction() == actionId) { |
Paul Westbrook | cec3e0b | 2013-02-04 22:50:22 -0800 | [diff] [blame] | 705 | if (!listView.destroyItems(conversations, listener)) { |
| 706 | // The listView failed to destroy the items, perform the action manually |
| 707 | LogUtils.e(LOG_TAG, "ConversationListFragment.requestDelete: " + |
| 708 | "listView failed to destroy items."); |
| 709 | action.performAction(); |
| 710 | } |
Vikram Aggarwal | a8e4318 | 2012-09-13 12:55:10 -0700 | [diff] [blame] | 711 | return; |
| 712 | } |
| 713 | // Delete the local delete items (all for now) and when done, |
| 714 | // update... |
| 715 | mListAdapter.delete(conversations, listener); |
Mindy Pereira | acf6039 | 2012-04-06 09:11:00 -0700 | [diff] [blame] | 716 | } |
Mindy Pereira | a3911aa | 2012-03-09 13:26:26 -0800 | [diff] [blame] | 717 | |
Mindy Pereira | 11dd5ef | 2012-03-10 15:10:18 -0800 | [diff] [blame] | 718 | public void onFolderUpdated(Folder folder) { |
Mindy Pereira | dc8963b | 2012-03-28 17:51:05 -0700 | [diff] [blame] | 719 | mFolder = folder; |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 720 | setSwipeAction(); |
Mindy Pereira | 82cea48 | 2012-03-27 16:45:00 -0700 | [diff] [blame] | 721 | if (mFolder == null) { |
| 722 | return; |
| 723 | } |
Mindy Pereira | 4584a0d | 2012-03-13 14:42:14 -0700 | [diff] [blame] | 724 | mListAdapter.setFolder(mFolder); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 725 | mFooterView.setFolder(mFolder); |
Vikram Aggarwal | 41b9e8f | 2012-09-25 10:15:04 -0700 | [diff] [blame] | 726 | if (!mFolder.wasSyncSuccessful()) { |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 727 | mErrorListener.onError(mFolder, false); |
| 728 | } |
Paul Westbrook | c01f5d9 | 2012-09-25 17:22:25 -0700 | [diff] [blame] | 729 | |
| 730 | // Notify of changes to the Folder. |
| 731 | onFolderStatusUpdated(); |
| 732 | |
Mindy Pereira | 12fe37a | 2012-08-15 10:02:57 -0700 | [diff] [blame] | 733 | // Blow away conversation items cache. |
| 734 | ConversationItemViewModel.onFolderUpdated(mFolder); |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Vikram Aggarwal | 81a4f08 | 2012-09-28 09:19:04 -0700 | [diff] [blame] | 737 | /** |
| 738 | * Updates the footer visibility and updates the conversation cursor |
| 739 | */ |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 740 | public void onConversationListStatusUpdated() { |
Paul Westbrook | 9a70e91 | 2012-08-17 15:53:20 -0700 | [diff] [blame] | 741 | final ConversationCursor cursor = getConversationListCursor(); |
| 742 | final boolean showFooter = cursor != null && mFooterView.updateStatus(cursor); |
Paul Westbrook | c01f5d9 | 2012-09-25 17:22:25 -0700 | [diff] [blame] | 743 | // Update the folder status, in case the cursor could affect it. |
| 744 | onFolderStatusUpdated(); |
| 745 | mListAdapter.setFooterVisibility(showFooter); |
| 746 | |
| 747 | // Also change the cursor here. |
| 748 | onCursorUpdated(); |
| 749 | } |
| 750 | |
| 751 | private void onFolderStatusUpdated() { |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 752 | // Update the sync status bar with sync results if needed |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 753 | checkSyncStatus(); |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 754 | |
Paul Westbrook | c01f5d9 | 2012-09-25 17:22:25 -0700 | [diff] [blame] | 755 | final ConversationCursor cursor = getConversationListCursor(); |
Paul Westbrook | 9a70e91 | 2012-08-17 15:53:20 -0700 | [diff] [blame] | 756 | Bundle extras = cursor != null ? cursor.getExtras() : Bundle.EMPTY; |
Andrew Sapperstein | 427df9d | 2013-05-15 12:05:09 -0700 | [diff] [blame] | 757 | int errorStatus = extras.containsKey(UIProvider.CursorExtraKeys.EXTRA_ERROR) ? |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 758 | extras.getInt(UIProvider.CursorExtraKeys.EXTRA_ERROR) |
| 759 | : UIProvider.LastSyncResult.SUCCESS; |
Andrew Sapperstein | 427df9d | 2013-05-15 12:05:09 -0700 | [diff] [blame] | 760 | int cursorStatus = extras.getInt(UIProvider.CursorExtraKeys.EXTRA_STATUS); |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 761 | // We want to update the UI with this information if either we are loaded or complete, or |
Paul Westbrook | c01f5d9 | 2012-09-25 17:22:25 -0700 | [diff] [blame] | 762 | // we have a folder with a non-0 count. |
| 763 | final int folderCount = mFolder != null ? mFolder.totalCount : 0; |
Andrew Sapperstein | 427df9d | 2013-05-15 12:05:09 -0700 | [diff] [blame] | 764 | if (errorStatus == UIProvider.LastSyncResult.SUCCESS |
| 765 | && (cursorStatus == UIProvider.CursorStatus.LOADED |
| 766 | || cursorStatus == UIProvider.CursorStatus.COMPLETE) || folderCount > 0) { |
Paul Westbrook | c01f5d9 | 2012-09-25 17:22:25 -0700 | [diff] [blame] | 767 | updateSearchResultHeader(folderCount); |
| 768 | if (folderCount == 0) { |
Mindy Pereira | 6cc9553 | 2012-08-15 16:04:56 -0700 | [diff] [blame] | 769 | mListView.setEmptyView(mEmptyView); |
| 770 | } |
Mindy Pereira | 70a70c9 | 2012-08-02 08:39:45 -0700 | [diff] [blame] | 771 | } |
Mindy Pereira | a3911aa | 2012-03-09 13:26:26 -0800 | [diff] [blame] | 772 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 773 | |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 774 | private void setSwipeAction() { |
Vikram Aggarwal | 7c401b7 | 2012-08-13 16:43:47 -0700 | [diff] [blame] | 775 | int swipeSetting = Settings.getSwipeSetting(mAccount.settings); |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 776 | if (swipeSetting == Swipe.DISABLED |
Mindy Pereira | b807337 | 2012-08-09 14:00:10 -0700 | [diff] [blame] | 777 | || !mAccount.supportsCapability(AccountCapabilities.UNDO) |
| 778 | || (mFolder != null && mFolder.isTrash())) { |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 779 | mListView.enableSwipe(false); |
| 780 | } else { |
| 781 | int action; |
Rohan Shah | 7f98d0d | 2013-02-15 13:21:09 -0800 | [diff] [blame] | 782 | mListView.enableSwipe(true); |
mindyp | 77c3e1b | 2012-09-11 14:05:02 -0700 | [diff] [blame] | 783 | if (ConversationListContext.isSearchResult(mViewContext) |
Scott Kennedy | 8c1058e | 2013-03-20 13:40:20 -0700 | [diff] [blame] | 784 | || (mFolder != null && mFolder.isType(FolderType.SPAM))) { |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 785 | action = R.id.delete; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 786 | } else if (mFolder == null) { |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame] | 787 | action = R.id.remove_folder; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 788 | } else { |
| 789 | // We have enough information to respect user settings. |
| 790 | switch (swipeSetting) { |
| 791 | case Swipe.ARCHIVE: |
| 792 | if (mAccount.supportsCapability(AccountCapabilities.ARCHIVE)) { |
| 793 | if (mFolder.supportsCapability(FolderCapabilities.ARCHIVE)) { |
| 794 | action = R.id.archive; |
| 795 | break; |
| 796 | } else if (mFolder.supportsCapability |
| 797 | (FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES)) { |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame] | 798 | action = R.id.remove_folder; |
Mindy Pereira | 4e812f4 | 2012-07-30 16:52:49 -0700 | [diff] [blame] | 799 | break; |
| 800 | } |
| 801 | } |
| 802 | case Swipe.DELETE: |
| 803 | default: |
| 804 | action = R.id.delete; |
| 805 | break; |
| 806 | } |
Mindy Pereira | e58222b | 2012-07-25 14:33:18 -0700 | [diff] [blame] | 807 | } |
| 808 | mListView.setSwipeAction(action); |
| 809 | } |
Mark Wei | 6126d72 | 2013-04-24 21:09:43 -0700 | [diff] [blame] | 810 | mListView.setCurrentAccount(mAccount); |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 811 | mListView.setCurrentFolder(mFolder); |
| 812 | } |
| 813 | |
Vikram Aggarwal | 17f373e | 2012-09-17 15:49:32 -0700 | [diff] [blame] | 814 | /** |
| 815 | * Changes the conversation cursor in the list and sets selected position if none is set. |
| 816 | */ |
| 817 | private void onCursorUpdated() { |
| 818 | if (mCallbacks == null || mListAdapter == null) { |
| 819 | return; |
| 820 | } |
Vikram Aggarwal | 81a4f08 | 2012-09-28 09:19:04 -0700 | [diff] [blame] | 821 | // Check against the previous cursor here and see if they are the same. If they are, then |
| 822 | // do a notifyDataSetChanged. |
| 823 | final ConversationCursor newCursor = mCallbacks.getConversationListCursor(); |
| 824 | mListAdapter.swapCursor(newCursor); |
| 825 | // When the conversation cursor is *updated*, we get back the same instance. In that |
| 826 | // situation, CursorAdapter.swapCursor() silently returns, without forcing a |
| 827 | // notifyDataSetChanged(). So let's force a call to notifyDataSetChanged, since an updated |
| 828 | // cursor means that the dataset has changed. |
| 829 | final int newCursorHash = (newCursor == null) ? 0 : newCursor.hashCode(); |
| 830 | if (mConversationCursorHash == newCursorHash && mConversationCursorHash != 0) { |
| 831 | mListAdapter.notifyDataSetChanged(); |
| 832 | } |
| 833 | mConversationCursorHash = newCursorHash; |
Scott Kennedy | b1e2148 | 2013-03-15 13:40:38 -0700 | [diff] [blame] | 834 | |
Scott Kennedy | 4b9b395 | 2013-03-20 17:20:59 -0700 | [diff] [blame] | 835 | if (newCursor != null && newCursor.getCount() > 0) { |
Scott Kennedy | b1e2148 | 2013-03-15 13:40:38 -0700 | [diff] [blame] | 836 | newCursor.markContentsSeen(); |
| 837 | } |
| 838 | |
Vikram Aggarwal | 17f373e | 2012-09-17 15:49:32 -0700 | [diff] [blame] | 839 | // If a current conversation is available, and none is selected in the list, then ask |
| 840 | // the list to select the current conversation. |
| 841 | final Conversation conv = mCallbacks.getCurrentConversation(); |
| 842 | if (conv == null) { |
| 843 | return; |
| 844 | } |
Vikram Aggarwal | a91d00b | 2013-01-18 12:00:37 -0800 | [diff] [blame] | 845 | if (mListView.getChoiceMode() != ListView.CHOICE_MODE_NONE |
| 846 | && mListView.getCheckedItemPosition() == -1) { |
| 847 | setSelected(conv.position, true); |
Mindy Pereira | 967ede6 | 2012-03-22 09:29:09 -0700 | [diff] [blame] | 848 | } |
Mindy Pereira | 21ab490 | 2012-03-19 18:48:03 -0700 | [diff] [blame] | 849 | } |
Mindy Pereira | 1e2573b | 2012-04-17 14:34:36 -0700 | [diff] [blame] | 850 | |
mindyp | c6adce3 | 2012-08-22 18:46:42 -0700 | [diff] [blame] | 851 | public void commitDestructiveActions(boolean animate) { |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 852 | if (mListView != null) { |
mindyp | c6adce3 | 2012-08-22 18:46:42 -0700 | [diff] [blame] | 853 | mListView.commitDestructiveActions(animate); |
Vikram Aggarwal | 7d81600 | 2012-04-17 17:06:41 -0700 | [diff] [blame] | 854 | |
| 855 | } |
| 856 | } |
| 857 | |
mindyp | 9365a82 | 2012-09-12 09:09:09 -0700 | [diff] [blame] | 858 | @Override |
| 859 | public void onListItemSwiped(Collection<Conversation> conversations) { |
| 860 | mUpdater.showNextConversation(conversations); |
| 861 | } |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 862 | |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 863 | private void checkSyncStatus() { |
Alice Yang | 76d2065 | 2013-04-24 02:32:48 -0700 | [diff] [blame] | 864 | if (mFolder != null && mFolder.isSyncInProgress()) { |
Alice Yang | 03752f3 | 2013-05-05 15:05:16 -0700 | [diff] [blame] | 865 | LogUtils.d(LOG_TAG, "CLF.checkSyncStatus still syncing"); |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 866 | // Still syncing, ignore |
| 867 | } else { |
| 868 | // Finished syncing: |
Alice Yang | 03752f3 | 2013-05-05 15:05:16 -0700 | [diff] [blame] | 869 | LogUtils.d(LOG_TAG, "CLF.checkSyncStatus done syncing"); |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 870 | mConversationListView.onSyncFinished(); |
| 871 | } |
| 872 | } |
| 873 | |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 874 | /** |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 875 | * Displays the indefinite progress bar indicating a sync is in progress. This |
| 876 | * should only be called if user manually requested a sync, and not for background syncs. |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 877 | */ |
| 878 | protected void showSyncStatusBar() { |
Alice Yang | 486e63e | 2013-04-05 13:01:50 -0700 | [diff] [blame] | 879 | mConversationListView.showSyncStatusBar(); |
Alice Yang | 0d74a66 | 2013-03-25 14:01:24 -0700 | [diff] [blame] | 880 | } |
Rohan Shah | d4f2287 | 2013-04-19 17:06:37 -0700 | [diff] [blame] | 881 | |
| 882 | /** |
| 883 | * Clears all items in the list. |
| 884 | */ |
| 885 | public void clear() { |
| 886 | mListView.setAdapter(null); |
| 887 | } |
Vikram Aggarwal | b9e1a35 | 2012-01-24 15:23:38 -0800 | [diff] [blame] | 888 | } |