Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -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; |
| 21 | import android.text.Html; |
| 22 | import android.util.AttributeSet; |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 23 | import android.view.View; |
| 24 | import android.view.View.OnClickListener; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 25 | import android.widget.RelativeLayout; |
| 26 | import android.widget.TextView; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 27 | |
| 28 | import com.android.mail.R; |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 29 | import com.android.mail.browse.ConversationCursor; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 30 | import com.android.mail.providers.Account; |
| 31 | import com.android.mail.providers.Conversation; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 32 | import com.google.common.collect.ImmutableList; |
| 33 | |
Andy Huang | 62d7962 | 2012-07-24 18:50:34 -0700 | [diff] [blame^] | 34 | public class LeaveBehindItem extends AnimatingItemView implements OnClickListener, |
Mindy Pereira | 07b8b1b | 2012-04-17 15:48:01 -0700 | [diff] [blame] | 35 | SwipeableItemView { |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 36 | |
Mindy Pereira | d3367499 | 2012-06-25 16:26:30 -0700 | [diff] [blame] | 37 | private ToastBarOperation mUndoOp; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 38 | private Account mAccount; |
| 39 | private AnimatedAdapter mAdapter; |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 40 | private ConversationCursor mConversationCursor; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 41 | |
| 42 | public LeaveBehindItem(Context context) { |
| 43 | this(context, null); |
| 44 | } |
| 45 | |
| 46 | public LeaveBehindItem(Context context, AttributeSet attrs) { |
| 47 | this(context, attrs, -1); |
| 48 | } |
| 49 | |
| 50 | public LeaveBehindItem(Context context, AttributeSet attrs, int defStyle) { |
| 51 | super(context, attrs, defStyle); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onClick(View v) { |
| 56 | int id = v.getId(); |
| 57 | switch (id) { |
| 58 | case R.id.undo_button: |
| 59 | if (mAccount.undoUri != null) { |
| 60 | // NOTE: We might want undo to return the messages affected, |
| 61 | // in which case |
| 62 | // the resulting cursor might be interesting... |
| 63 | // TODO: Use UIProvider.SEQUENCE_QUERY_PARAMETER to indicate |
| 64 | // the set of |
| 65 | // commands to undo |
Andy Huang | 62d7962 | 2012-07-24 18:50:34 -0700 | [diff] [blame^] | 66 | mAdapter.clearLeaveBehind(getData()); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 67 | mAdapter.setUndo(true); |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 68 | mConversationCursor.undo(getContext(), mAccount.undoUri); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 69 | } |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
Mindy Pereira | d3367499 | 2012-06-25 16:26:30 -0700 | [diff] [blame] | 74 | public void bindOperations(Account account, AnimatedAdapter adapter, ToastBarOperation undoOp, |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 75 | Conversation target) { |
| 76 | mUndoOp = undoOp; |
| 77 | mAccount = account; |
| 78 | mAdapter = adapter; |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 79 | mConversationCursor = (ConversationCursor)adapter.getCursor(); |
Andy Huang | 62d7962 | 2012-07-24 18:50:34 -0700 | [diff] [blame^] | 80 | setData(target); |
Mindy Pereira | 07b8b1b | 2012-04-17 15:48:01 -0700 | [diff] [blame] | 81 | ((TextView) findViewById(R.id.undo_descriptionview)).setText(Html.fromHtml(mUndoOp |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 82 | .getDescription(getContext()))); |
Mindy Pereira | 07b8b1b | 2012-04-17 15:48:01 -0700 | [diff] [blame] | 83 | ((RelativeLayout) findViewById(R.id.undo_button)).setOnClickListener(this); |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | public void commit() { |
Andy Huang | 62d7962 | 2012-07-24 18:50:34 -0700 | [diff] [blame^] | 87 | Conversation conv = getData(); |
| 88 | mConversationCursor.delete(getContext(), ImmutableList.of(conv)); |
| 89 | mAdapter.clearLeaveBehind(conv); |
| 90 | } |
| 91 | |
| 92 | public long getConversationId() { |
| 93 | return getData().id; |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Paul Westbrook | bf232c3 | 2012-04-18 03:17:41 -0700 | [diff] [blame] | 96 | @Override |
Mindy Pereira | 6c72a78 | 2012-04-07 14:29:15 -0700 | [diff] [blame] | 97 | public View getView() { |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void cancelTap() { |
| 103 | // Do nothing. |
| 104 | } |
| 105 | } |