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 */
17package com.android.mms.ui;
18
19import java.util.List;
20
21import android.content.Context;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.ArrayAdapter;
26
27import com.android.mms.R;
28
29/**
30 * The back-end data adapter for DeliveryReportActivity.
31 */
32public class DeliveryReportAdapter extends ArrayAdapter<DeliveryReportItem> {
33    static final String LOG_TAG = "DeliveryReportAdapter";
34
35    public DeliveryReportAdapter(Context context, List<DeliveryReportItem> items) {
36        super(context, R.layout.delivery_report_list_item, R.id.recipient, items);
37    }
38
39    @Override
40    public View getView(int position, View view, ViewGroup viewGroup) {
41        DeliveryReportListItem listItem;
42        DeliveryReportItem item = this.getItem(position);
43
44        if (view == null) {
45            LayoutInflater factory = LayoutInflater.from(getContext());
46            listItem = (DeliveryReportListItem) factory.inflate(
47                    R.layout.delivery_report_list_item, viewGroup, false);
48        } else {
49            if (view instanceof DeliveryReportListItem) {
50                listItem = (DeliveryReportListItem) view;
51            } else {
52                return view;
53            }
54        }
55
56        listItem.bind(item.recipient, item.status, item.deliveryDate);
57
58        return listItem;
59    }
60}
61