1/*
2 * Copyright (C) 2008 Esmertec AG.
3 * Copyright (C) 2008 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.mms.ui;
19
20import android.content.Context;
21import android.text.TextUtils;
22import android.util.AttributeSet;
23import android.view.View;
24import android.widget.ImageView;
25import android.widget.LinearLayout;
26import android.widget.TextView;
27
28import com.android.mms.R;
29import com.android.mms.data.Contact;
30
31/**
32 * This class displays the status for a single recipient of a message.  It is used in
33 * the ListView of DeliveryReportActivity.
34 */
35public class DeliveryReportListItem extends LinearLayout {
36    private TextView mRecipientView;
37    private TextView mStatusView;
38    private TextView mDeliveryDateView;
39    private ImageView mIconView;
40
41    DeliveryReportListItem(Context context) {
42        super(context);
43    }
44
45    @Override
46    protected void onFinishInflate() {
47        super.onFinishInflate();
48
49        mRecipientView = (TextView) findViewById(R.id.recipient);
50        mStatusView = (TextView) findViewById(R.id.status);
51        mDeliveryDateView = (TextView) findViewById(R.id.delivery_date);
52        mIconView = (ImageView) findViewById(R.id.icon);
53    }
54
55    public DeliveryReportListItem(Context context, AttributeSet attrs) {
56        super(context, attrs);
57    }
58
59    public final void bind(String recipient, String status, String deliveryDate) {
60        // Recipient
61        if (!TextUtils.isEmpty(recipient)) {
62            mRecipientView.setText(Contact.get(recipient, false).getName());
63        } else {
64            mRecipientView.setText("");
65        }
66        // Status text
67        mStatusView.setText(status);
68
69        // Status icon
70        Context context = getContext();
71        String receivedStr = context.getString(R.string.status_received);
72        String failedStr = context.getString(R.string.status_failed);
73        String pendingStr = context.getString(R.string.status_pending);
74        String rejectStr = context.getString(R.string.status_rejected);
75
76        if (status.compareTo(receivedStr) == 0) {
77            mIconView.setImageResource(R.drawable.ic_sms_mms_delivered);
78        } else if (status.compareTo(failedStr) == 0) {
79            mIconView.setImageResource(R.drawable.ic_sms_mms_not_delivered);
80        } else if (status.compareTo(pendingStr) == 0) {
81            mIconView.setImageResource(R.drawable.ic_sms_mms_pending);
82        } else if (status.compareTo(rejectStr) == 0) {
83            // FIXME: need replace ic_sms_mms_not_delivered by a rejected icon.
84            mIconView.setImageResource(R.drawable.ic_sms_mms_not_delivered);
85        } else {
86            // No status report or unknown
87        }
88
89        if (TextUtils.isEmpty(deliveryDate)) {
90            mDeliveryDateView.setVisibility(View.GONE);
91        } else {
92            mDeliveryDateView.setVisibility(View.VISIBLE);
93            mDeliveryDateView.setText(deliveryDate);
94        }
95    }
96}
97