summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/browse/ConversationFooterView.java
blob: b37d564e8832dc057269fb5ceba0690a49fcc53e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package com.android.mail.browse;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.android.mail.R;
import com.android.mail.browse.ConversationViewAdapter.ConversationFooterItem;
import com.android.mail.browse.ConversationViewAdapter.MessageHeaderItem;
import com.android.mail.compose.ComposeActivity;
import com.android.mail.providers.Account;
import com.android.mail.providers.Message;
import com.android.mail.utils.LogTag;
import com.android.mail.utils.LogUtils;

/**
 * A view placed at the bottom of the conversation view that allows the user to
 * reply/reply all/forward to the last message in the conversation.
 */
public class ConversationFooterView extends LinearLayout implements View.OnClickListener {

    private static final String LOG_TAG = LogTag.getLogTag();

    private ConversationFooterItem mFooterItem;
    private ConversationAccountController mAccountController;

    public ConversationFooterView(Context context) {
        super(context);
    }

    public ConversationFooterView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ConversationFooterView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();

        findViewById(R.id.reply_button).setOnClickListener(this);
        findViewById(R.id.reply_all_button).setOnClickListener(this);
        findViewById(R.id.forward_button).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (mFooterItem == null) {
            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on unbound view");
            return;
        }
        final MessageHeaderItem headerItem = mFooterItem.getLastMessageHeaderItem();
        if (headerItem == null) {
            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null header item");
            return;
        }
        final Message message = headerItem.getMessage();
        if (message == null) {
            LogUtils.i(LOG_TAG, "ignoring conversation footer tap on null message");
            return;
        }
        final int id = v.getId();
        if (id == R.id.reply_button) {
            ComposeActivity.reply(getContext(), getAccount(), message);
        } else if (id == R.id.reply_all_button) {
            ComposeActivity.replyAll(getContext(), getAccount(), message);
        } else if (id == R.id.forward_button) {
            ComposeActivity.forward(getContext(), getAccount(), message);
        }
    }

    public void bind(ConversationFooterItem footerItem) {
        mFooterItem = footerItem;
    }

    public void setAccountController(ConversationAccountController accountController) {
        mAccountController = accountController;
    }

    private Account getAccount() {
        return mAccountController != null ? mAccountController.getAccount() : null;
    }
}