ConversationFooterView.java revision e2a30e19a9fff0e4368c4ec36280a3fcd4ca03e2
1package com.android.mail.browse;
2
3import android.content.Context;
4import android.util.AttributeSet;
5import android.view.View;
6import android.widget.LinearLayout;
7
8import com.android.mail.R;
9import com.android.mail.browse.ConversationViewAdapter.ConversationFooterItem;
10import com.android.mail.browse.ConversationViewAdapter.MessageHeaderItem;
11import com.android.mail.compose.ComposeActivity;
12import com.android.mail.providers.Account;
13import com.android.mail.providers.Message;
14import com.android.mail.utils.LogTag;
15import com.android.mail.utils.LogUtils;
16
17/**
18 * A view placed at the bottom of the conversation view that allows the user to
19 * reply/reply all/forward to the last message in the conversation.
20 */
21public class ConversationFooterView extends LinearLayout implements View.OnClickListener {
22
23    private static final String LOG_TAG = LogTag.getLogTag();
24
25    private ConversationFooterItem mFooterItem;
26    private ConversationAccountController mAccountController;
27
28    public ConversationFooterView(Context context) {
29        super(context);
30    }
31
32    public ConversationFooterView(Context context, AttributeSet attrs) {
33        super(context, attrs);
34    }
35
36    public ConversationFooterView(Context context, AttributeSet attrs, int defStyle) {
37        super(context, attrs, defStyle);
38    }
39
40    @Override
41    protected void onFinishInflate() {
42        super.onFinishInflate();
43
44        findViewById(R.id.reply_button).setOnClickListener(this);
45        findViewById(R.id.reply_all_button).setOnClickListener(this);
46        findViewById(R.id.forward_button).setOnClickListener(this);
47    }
48
49    @Override
50    public void onClick(View v) {
51        if (mFooterItem == null) {
52            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on unbound view");
53            return;
54        }
55        final MessageHeaderItem headerItem = mFooterItem.getLastMessageHeaderItem();
56        if (headerItem == null) {
57            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null header item");
58            return;
59        }
60        final Message message = headerItem.getMessage();
61        if (message == null) {
62            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null message");
63            return;
64        }
65        final int id = v.getId();
66        if (id == R.id.reply_button) {
67            ComposeActivity.reply(getContext(), getAccount(), message);
68        } else if (id == R.id.reply_all_button) {
69            ComposeActivity.replyAll(getContext(), getAccount(), message);
70        } else if (id == R.id.forward_button) {
71            ComposeActivity.forward(getContext(), getAccount(), message);
72        }
73    }
74
75    public void bind(ConversationFooterItem footerItem) {
76        mFooterItem = footerItem;
77    }
78
79    public void setAccountController(ConversationAccountController accountController) {
80        mAccountController = accountController;
81    }
82
83    private Account getAccount() {
84        return mAccountController != null ? mAccountController.getAccount() : null;
85    }
86}
87