Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [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 | |
| 20 | import android.content.Context; |
Mindy Pereira | f913894 | 2012-04-05 19:25:31 -0700 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Mindy Pereira | bcd784c | 2012-08-10 09:53:24 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Mindy Pereira | 8db7e40 | 2012-07-13 10:32:47 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.view.MotionEvent; |
| 26 | import android.view.View; |
Mindy Pereira | f913894 | 2012-04-05 19:25:31 -0700 | [diff] [blame] | 27 | import android.view.ViewConfiguration; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 28 | import android.widget.ListView; |
| 29 | |
| 30 | import com.android.mail.R; |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 31 | import com.android.mail.browse.ConversationCursor; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 32 | import com.android.mail.browse.ConversationItemView; |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 33 | import com.android.mail.browse.SwipeableConversationItemView; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 34 | import com.android.mail.providers.Conversation; |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 35 | import com.android.mail.providers.Folder; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 36 | import com.android.mail.ui.SwipeHelper.Callback; |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 37 | import com.android.mail.utils.LogTag; |
Mindy Pereira | b0219eb | 2012-07-27 10:48:00 -0700 | [diff] [blame] | 38 | import com.android.mail.utils.LogUtils; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 39 | |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 40 | import java.util.ArrayList; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 41 | import java.util.Collection; |
Mindy Pereira | 8db7e40 | 2012-07-13 10:32:47 -0700 | [diff] [blame] | 42 | import java.util.HashMap; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 43 | |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 44 | public class SwipeableListView extends ListView implements Callback { |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 45 | private SwipeHelper mSwipeHelper; |
Mindy Pereira | ff9aff3 | 2012-04-03 15:40:05 -0700 | [diff] [blame] | 46 | private boolean mEnableSwipe = false; |
Andy Huang | 489dd22 | 2012-03-29 14:52:55 -0700 | [diff] [blame] | 47 | |
Paul Westbrook | b334c90 | 2012-06-25 11:42:46 -0700 | [diff] [blame] | 48 | public static final String LOG_TAG = LogTag.getLogTag(); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 49 | |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 50 | private ConversationSelectionSet mConvSelectionSet; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 51 | private int mSwipeAction; |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 52 | private Folder mFolder; |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 53 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 54 | public SwipeableListView(Context context) { |
| 55 | this(context, null); |
| 56 | } |
| 57 | |
| 58 | public SwipeableListView(Context context, AttributeSet attrs) { |
| 59 | this(context, attrs, -1); |
| 60 | } |
| 61 | |
| 62 | public SwipeableListView(Context context, AttributeSet attrs, int defStyle) { |
| 63 | super(context, attrs, defStyle); |
| 64 | float densityScale = getResources().getDisplayMetrics().density; |
Mindy Pereira | f913894 | 2012-04-05 19:25:31 -0700 | [diff] [blame] | 65 | float pagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop(); |
Mindy Pereira | 6f0b2be | 2012-07-27 15:03:38 -0700 | [diff] [blame] | 66 | mSwipeHelper = new SwipeHelper(context, SwipeHelper.X, this, densityScale, |
| 67 | pagingTouchSlop); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Mindy Pereira | f913894 | 2012-04-05 19:25:31 -0700 | [diff] [blame] | 70 | @Override |
| 71 | protected void onConfigurationChanged(Configuration newConfig) { |
| 72 | super.onConfigurationChanged(newConfig); |
| 73 | float densityScale = getResources().getDisplayMetrics().density; |
| 74 | mSwipeHelper.setDensityScale(densityScale); |
| 75 | float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); |
| 76 | mSwipeHelper.setPagingTouchSlop(pagingTouchSlop); |
| 77 | } |
| 78 | |
Mindy Pereira | ff9aff3 | 2012-04-03 15:40:05 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Enable swipe gestures. |
| 81 | */ |
| 82 | public void enableSwipe(boolean enable) { |
| 83 | mEnableSwipe = enable; |
| 84 | } |
| 85 | |
Mindy Pereira | f07269f | 2012-04-04 15:22:07 -0700 | [diff] [blame] | 86 | public boolean isSwipeEnabled() { |
| 87 | return mEnableSwipe; |
| 88 | } |
| 89 | |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 90 | public void setSwipeAction(int action) { |
| 91 | mSwipeAction = action; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Mindy Pereira | de3e74a | 2012-07-24 09:43:10 -0700 | [diff] [blame] | 94 | public int getSwipeAction() { |
| 95 | return mSwipeAction; |
| 96 | } |
| 97 | |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 98 | public void setSelectionSet(ConversationSelectionSet set) { |
| 99 | mConvSelectionSet = set; |
| 100 | } |
| 101 | |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 102 | public void setCurrentFolder(Folder folder) { |
| 103 | mFolder = folder; |
| 104 | } |
| 105 | |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 106 | @Override |
| 107 | public ConversationSelectionSet getSelectionSet() { |
| 108 | return mConvSelectionSet; |
| 109 | } |
| 110 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 111 | @Override |
| 112 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Mindy Pereira | ff9aff3 | 2012-04-03 15:40:05 -0700 | [diff] [blame] | 113 | if (mEnableSwipe) { |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 114 | return mSwipeHelper.onInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev); |
Mindy Pereira | 19bf5f5 | 2012-03-20 10:28:53 -0700 | [diff] [blame] | 115 | } else { |
| 116 | return super.onInterceptTouchEvent(ev); |
| 117 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public boolean onTouchEvent(MotionEvent ev) { |
Mindy Pereira | ff9aff3 | 2012-04-03 15:40:05 -0700 | [diff] [blame] | 122 | if (mEnableSwipe) { |
Mindy Pereira | 19bf5f5 | 2012-03-20 10:28:53 -0700 | [diff] [blame] | 123 | return mSwipeHelper.onTouchEvent(ev) || super.onTouchEvent(ev); |
| 124 | } else { |
| 125 | return super.onTouchEvent(ev); |
| 126 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public View getChildAtPosition(MotionEvent ev) { |
| 131 | // find the view under the pointer, accounting for GONE views |
| 132 | final int count = getChildCount(); |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 133 | int touchY = (int) ev.getY(); |
| 134 | int childIdx = 0; |
| 135 | View slidingChild; |
| 136 | for (; childIdx < count; childIdx++) { |
| 137 | slidingChild = getChildAt(childIdx); |
| 138 | if (slidingChild.getVisibility() == GONE) { |
| 139 | continue; |
| 140 | } |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 141 | if (touchY >= slidingChild.getTop() && touchY <= slidingChild.getBottom()) { |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 142 | if (slidingChild instanceof SwipeableConversationItemView) { |
| 143 | return ((SwipeableConversationItemView) slidingChild).getSwipeableItemView(); |
| 144 | } |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 145 | return slidingChild; |
| 146 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 147 | } |
| 148 | return null; |
| 149 | } |
| 150 | |
| 151 | @Override |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 152 | public boolean canChildBeDismissed(SwipeableItemView v) { |
| 153 | View view = v.getView(); |
| 154 | return view instanceof ConversationItemView || view instanceof LeaveBehindItem; |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 158 | public void onChildDismissed(SwipeableItemView v) { |
| 159 | View view = v.getView(); |
Mindy Pereira | c3180e0 | 2012-07-29 10:13:21 -0700 | [diff] [blame] | 160 | if (view != null) { |
| 161 | if (view instanceof ConversationItemView) { |
Mindy Pereira | c6e22c7 | 2012-08-10 10:14:18 -0700 | [diff] [blame] | 162 | dismissChild((ConversationItemView) view); |
Mindy Pereira | c3180e0 | 2012-07-29 10:13:21 -0700 | [diff] [blame] | 163 | } else if (view instanceof LeaveBehindItem) { |
Mindy Pereira | 9a604d0 | 2012-08-09 12:19:13 -0700 | [diff] [blame] | 164 | ((LeaveBehindItem) view).dismiss(); |
Mindy Pereira | c3180e0 | 2012-07-29 10:13:21 -0700 | [diff] [blame] | 165 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 166 | } |
Mindy Pereira | 866d319 | 2012-03-26 09:50:00 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 169 | // Call this whenever a new action is taken; this forces a commit of any |
| 170 | // existing destructive actions. |
| 171 | public void commitDestructiveActions() { |
Mindy Pereira | 0fb5518 | 2012-07-24 08:22:30 -0700 | [diff] [blame] | 172 | final AnimatedAdapter adapter = getAnimatedAdapter(); |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 173 | if (adapter != null) { |
| 174 | adapter.commitLeaveBehindItems(); |
| 175 | } |
| 176 | } |
| 177 | |
Mindy Pereira | c6e22c7 | 2012-08-10 10:14:18 -0700 | [diff] [blame] | 178 | private void dismissChild(final ConversationItemView target) { |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 179 | final Context context = getContext(); |
Mindy Pereira | d3367499 | 2012-06-25 16:26:30 -0700 | [diff] [blame] | 180 | final ToastBarOperation undoOp; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 181 | |
Mindy Pereira | c6e22c7 | 2012-08-10 10:14:18 -0700 | [diff] [blame] | 182 | undoOp = new ToastBarOperation(1, mSwipeAction, ToastBarOperation.UNDO); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 183 | Conversation conv = target.getConversation(); |
Mindy Pereira | 13e6243 | 2012-08-10 17:52:05 -0700 | [diff] [blame] | 184 | target.getConversation().position = findConversation(target, conv); |
Mindy Pereira | 0fb5518 | 2012-07-24 08:22:30 -0700 | [diff] [blame] | 185 | final AnimatedAdapter adapter = getAnimatedAdapter(); |
Mindy Pereira | 09f1ae9 | 2012-07-18 08:28:46 -0700 | [diff] [blame] | 186 | if (adapter == null) { |
| 187 | return; |
| 188 | } |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 189 | adapter.setupLeaveBehind(conv, undoOp, conv.position); |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 190 | ConversationCursor cc = (ConversationCursor) adapter.getCursor(); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 191 | switch (mSwipeAction) { |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame^] | 192 | case R.id.remove_folder: |
Mindy Pereira | 8db7e40 | 2012-07-13 10:32:47 -0700 | [diff] [blame] | 193 | FolderOperation folderOp = new FolderOperation(mFolder, false); |
| 194 | HashMap<Uri, Folder> targetFolders = Folder |
Mindy Pereira | 68f8384 | 2012-07-27 09:43:31 -0700 | [diff] [blame] | 195 | .hashMapForFolders(conv.getRawFolders()); |
Mindy Pereira | 8db7e40 | 2012-07-13 10:32:47 -0700 | [diff] [blame] | 196 | targetFolders.remove(folderOp.mFolder.uri); |
Mindy Pereira | 85c4a77 | 2012-07-30 10:47:26 -0700 | [diff] [blame] | 197 | conv.setRawFolders(Folder.getSerializedFolderString(targetFolders.values())); |
Mindy Pereira | 8db7e40 | 2012-07-13 10:32:47 -0700 | [diff] [blame] | 198 | cc.mostlyDestructiveUpdate(context, Conversation.listOf(conv), |
Mindy Pereira | 85c4a77 | 2012-07-30 10:47:26 -0700 | [diff] [blame] | 199 | Conversation.UPDATE_FOLDER_COLUMN, conv.getRawFoldersString()); |
Mindy Pereira | 06642fa | 2012-07-12 16:23:27 -0700 | [diff] [blame] | 200 | break; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 201 | case R.id.archive: |
Mindy Pereira | a8ead90 | 2012-07-12 12:06:51 -0700 | [diff] [blame] | 202 | cc.mostlyArchive(context, Conversation.listOf(conv)); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 203 | break; |
| 204 | case R.id.delete: |
Mindy Pereira | a8ead90 | 2012-07-12 12:06:51 -0700 | [diff] [blame] | 205 | cc.mostlyDelete(context, Conversation.listOf(conv)); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 206 | break; |
| 207 | } |
| 208 | adapter.notifyDataSetChanged(); |
Mindy Pereira | a8ead90 | 2012-07-12 12:06:51 -0700 | [diff] [blame] | 209 | if (mConvSelectionSet != null && !mConvSelectionSet.isEmpty() |
| 210 | && mConvSelectionSet.contains(conv)) { |
| 211 | mConvSelectionSet.toggle(null, conv); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 212 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public void onBeginDrag(View v) { |
| 217 | // We do this so the underlying ScrollView knows that it won't get |
| 218 | // the chance to intercept events anymore |
| 219 | requestDisallowInterceptTouchEvent(true); |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 220 | SwipeableConversationItemView view = null; |
| 221 | if (v instanceof ConversationItemView) { |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 222 | view = (SwipeableConversationItemView) v.getParent(); |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 223 | } |
| 224 | if (view != null) { |
| 225 | view.addBackground(getContext(), getSwipeActionText()); |
| 226 | view.setBackgroundVisibility(View.VISIBLE); |
| 227 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Override |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 231 | public void onDragCancelled(SwipeableItemView v) { |
Mindy Pereira | 709a174 | 2012-07-26 09:22:04 -0700 | [diff] [blame] | 232 | SwipeableConversationItemView view = null; |
| 233 | if (v instanceof ConversationItemView) { |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 234 | view = (SwipeableConversationItemView) ((View) v).getParent(); |
Mindy Pereira | 709a174 | 2012-07-26 09:22:04 -0700 | [diff] [blame] | 235 | } |
| 236 | if (view != null) { |
| 237 | view.removeBackground(); |
| 238 | } |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Mindy Pereira | 07118a0 | 2012-04-02 16:35:01 -0700 | [diff] [blame] | 241 | /** |
| 242 | * Archive items using the swipe away animation before shrinking them away. |
| 243 | */ |
Mindy Pereira | c79aec7 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 244 | public void destroyItems(final ArrayList<ConversationItemView> views, |
Mindy Pereira | 68f8384 | 2012-07-27 09:43:31 -0700 | [diff] [blame] | 245 | final DestructiveAction listener) { |
Mindy Pereira | 07118a0 | 2012-04-02 16:35:01 -0700 | [diff] [blame] | 246 | if (views == null || views.size() == 0) { |
| 247 | return; |
| 248 | } |
Mindy Pereira | c79aec7 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 249 | // Need to find the items in the LIST! |
Mindy Pereira | 07118a0 | 2012-04-02 16:35:01 -0700 | [diff] [blame] | 250 | final ArrayList<Conversation> conversations = new ArrayList<Conversation>(); |
| 251 | for (ConversationItemView view : views) { |
Mindy Pereira | de3e74a | 2012-07-24 09:43:10 -0700 | [diff] [blame] | 252 | Conversation conv = view.getConversation(); |
Mindy Pereira | 067ef97 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 253 | conv.position = findConversation(view, conv); |
Mindy Pereira | de3e74a | 2012-07-24 09:43:10 -0700 | [diff] [blame] | 254 | conversations.add(conv); |
Mindy Pereira | 07118a0 | 2012-04-02 16:35:01 -0700 | [diff] [blame] | 255 | } |
Mindy Pereira | c79aec7 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 256 | AnimatedAdapter adapter = getAnimatedAdapter(); |
| 257 | if (adapter != null) { |
Mindy Pereira | 067ef97 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 258 | adapter.swipeDelete(conversations, listener); |
Mindy Pereira | c79aec7 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 259 | } |
Mindy Pereira | 07118a0 | 2012-04-02 16:35:01 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Mindy Pereira | 067ef97 | 2012-08-08 14:04:06 -0700 | [diff] [blame] | 262 | private int findConversation(ConversationItemView view, Conversation conv) { |
| 263 | int position = conv.position; |
| 264 | long convId = conv.id; |
| 265 | try { |
| 266 | if (position == INVALID_POSITION) { |
| 267 | position = getPositionForView(view); |
| 268 | } |
| 269 | } catch (Exception e) { |
| 270 | position = INVALID_POSITION; |
| 271 | LogUtils.w(LOG_TAG, "Exception finding position; using alternate strategy"); |
| 272 | } |
| 273 | if (position == INVALID_POSITION) { |
| 274 | // Try the other way! |
| 275 | Conversation foundConv; |
| 276 | long foundId; |
| 277 | for (int i = 0; i < getChildCount(); i++) { |
| 278 | View child = getChildAt(i); |
| 279 | if (child instanceof SwipeableConversationItemView) { |
| 280 | foundConv = ((SwipeableConversationItemView) child).getSwipeableItemView() |
| 281 | .getConversation(); |
| 282 | foundId = foundConv.id; |
| 283 | if (foundId == convId) { |
| 284 | position = i; |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | return position; |
| 291 | } |
| 292 | |
Mindy Pereira | 0fb5518 | 2012-07-24 08:22:30 -0700 | [diff] [blame] | 293 | private AnimatedAdapter getAnimatedAdapter() { |
| 294 | return (AnimatedAdapter) getAdapter(); |
| 295 | } |
| 296 | |
Mindy Pereira | f6a6b50 | 2012-03-15 15:24:26 -0700 | [diff] [blame] | 297 | public interface SwipeCompleteListener { |
| 298 | public void onSwipeComplete(Collection<Conversation> conversations); |
| 299 | } |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 300 | |
| 301 | @Override |
| 302 | public boolean performItemClick(View view, int pos, long id) { |
Mindy Pereira | dd9d3a1 | 2012-08-06 16:35:36 -0700 | [diff] [blame] | 303 | boolean handled = super.performItemClick(view, pos, id); |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 304 | // Commit any existing destructive actions when the user selects a |
| 305 | // conversation to view. |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 306 | commitDestructiveActions(); |
Mindy Pereira | dd9d3a1 | 2012-08-06 16:35:36 -0700 | [diff] [blame] | 307 | return handled; |
Mindy Pereira | 8937bf1 | 2012-07-23 14:05:02 -0700 | [diff] [blame] | 308 | } |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 309 | |
| 310 | /** |
| 311 | * Get the text resource corresponding to the result of a swipe. |
| 312 | */ |
Mindy Pereira | bcd784c | 2012-08-10 09:53:24 -0700 | [diff] [blame] | 313 | public String getSwipeActionText() { |
| 314 | Resources res = getContext().getResources(); |
Mindy Pereira | 01f3050 | 2012-08-14 10:30:51 -0700 | [diff] [blame^] | 315 | if (mSwipeAction == R.id.remove_folder) { |
Mindy Pereira | bcd784c | 2012-08-10 09:53:24 -0700 | [diff] [blame] | 316 | return res.getString(R.string.remove_folder, mFolder.name); |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 317 | } |
Mindy Pereira | bcd784c | 2012-08-10 09:53:24 -0700 | [diff] [blame] | 318 | return res.getString(mSwipeAction == R.id.archive ? R.string.archive : R.string.delete); |
Mindy Pereira | 1ef988f | 2012-07-24 12:06:03 -0700 | [diff] [blame] | 319 | } |
Mindy Pereira | 00ffece | 2012-07-27 08:49:56 -0700 | [diff] [blame] | 320 | } |