blob: 3482183a15411d37963582539eb672826a3fa218 [file] [log] [blame]
Mindy Pereira6c72a782012-04-07 14:29:15 -07001/*
2 * Copyright (C) 2012 Google Inc.
3 * Licensed to The Android Open Source Project.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mail.ui;
19
20import android.content.Context;
21import android.text.Html;
22import android.util.AttributeSet;
Paul Westbrookbf232c32012-04-18 03:17:41 -070023import android.view.View;
24import android.view.View.OnClickListener;
Mindy Pereira6c72a782012-04-07 14:29:15 -070025import android.widget.RelativeLayout;
26import android.widget.TextView;
Mindy Pereira6c72a782012-04-07 14:29:15 -070027
28import com.android.mail.R;
Paul Westbrookbf232c32012-04-18 03:17:41 -070029import com.android.mail.browse.ConversationCursor;
Mindy Pereira6c72a782012-04-07 14:29:15 -070030import com.android.mail.providers.Account;
31import com.android.mail.providers.Conversation;
Mindy Pereira6c72a782012-04-07 14:29:15 -070032import com.google.common.collect.ImmutableList;
33
Andy Huang62d79622012-07-24 18:50:34 -070034public class LeaveBehindItem extends AnimatingItemView implements OnClickListener,
Mindy Pereira07b8b1b2012-04-17 15:48:01 -070035 SwipeableItemView {
Mindy Pereira6c72a782012-04-07 14:29:15 -070036
Mindy Pereirad33674992012-06-25 16:26:30 -070037 private ToastBarOperation mUndoOp;
Mindy Pereira6c72a782012-04-07 14:29:15 -070038 private Account mAccount;
39 private AnimatedAdapter mAdapter;
Paul Westbrookbf232c32012-04-18 03:17:41 -070040 private ConversationCursor mConversationCursor;
Mindy Pereira6c72a782012-04-07 14:29:15 -070041
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 Huang62d79622012-07-24 18:50:34 -070066 mAdapter.clearLeaveBehind(getData());
Mindy Pereira6c72a782012-04-07 14:29:15 -070067 mAdapter.setUndo(true);
Paul Westbrookbf232c32012-04-18 03:17:41 -070068 mConversationCursor.undo(getContext(), mAccount.undoUri);
Mindy Pereira6c72a782012-04-07 14:29:15 -070069 }
70 break;
71 }
72 }
73
Mindy Pereirad33674992012-06-25 16:26:30 -070074 public void bindOperations(Account account, AnimatedAdapter adapter, ToastBarOperation undoOp,
Mindy Pereira6c72a782012-04-07 14:29:15 -070075 Conversation target) {
76 mUndoOp = undoOp;
77 mAccount = account;
78 mAdapter = adapter;
Paul Westbrookbf232c32012-04-18 03:17:41 -070079 mConversationCursor = (ConversationCursor)adapter.getCursor();
Andy Huang62d79622012-07-24 18:50:34 -070080 setData(target);
Mindy Pereira07b8b1b2012-04-17 15:48:01 -070081 ((TextView) findViewById(R.id.undo_descriptionview)).setText(Html.fromHtml(mUndoOp
Mindy Pereira6c72a782012-04-07 14:29:15 -070082 .getDescription(getContext())));
Mindy Pereira07b8b1b2012-04-17 15:48:01 -070083 ((RelativeLayout) findViewById(R.id.undo_button)).setOnClickListener(this);
Mindy Pereira6c72a782012-04-07 14:29:15 -070084 }
85
86 public void commit() {
Andy Huang62d79622012-07-24 18:50:34 -070087 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 Pereira6c72a782012-04-07 14:29:15 -070094 }
95
Paul Westbrookbf232c32012-04-18 03:17:41 -070096 @Override
Mindy Pereira6c72a782012-04-07 14:29:15 -070097 public View getView() {
98 return this;
99 }
100
101 @Override
102 public void cancelTap() {
103 // Do nothing.
104 }
105}