Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.messaging.ui;
     17 
     18 import android.content.Context;
     19 import android.view.LayoutInflater;
     20 import android.view.View;
     21 import android.view.ViewGroup;
     22 import android.widget.BaseExpandableListAdapter;
     23 
     24 import com.android.messaging.R;
     25 import com.android.messaging.datamodel.media.VCardResourceEntry;
     26 import com.android.messaging.datamodel.media.VCardResourceEntry.VCardResourceEntryDestinationItem;
     27 
     28 import java.util.List;
     29 
     30 /**
     31  * Displays a list of expandable contact cards shown in the VCardDetailActivity.
     32  */
     33 public class VCardDetailAdapter extends BaseExpandableListAdapter {
     34     private final List<VCardResourceEntry> mVCards;
     35     private final LayoutInflater mInflater;
     36 
     37     public VCardDetailAdapter(final Context context, final List<VCardResourceEntry> vCards) {
     38         mVCards = vCards;
     39         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     40     }
     41 
     42     @Override
     43     public Object getChild(final int groupPosition, final int childPosition) {
     44         return mVCards.get(groupPosition).getContactInfo().get(childPosition);
     45     }
     46 
     47     @Override
     48     public long getChildId(final int groupPosition, final int childPosition) {
     49         return childPosition;
     50     }
     51 
     52     @Override
     53     public View getChildView(final int groupPosition, final int childPosition,
     54             final boolean isLastChild, final View convertView, final ViewGroup parent) {
     55         PersonItemView v;
     56         if (convertView == null) {
     57             v = instantiateView(parent);
     58         } else {
     59             v = (PersonItemView) convertView;
     60         }
     61 
     62         final VCardResourceEntryDestinationItem item = (VCardResourceEntryDestinationItem)
     63                 getChild(groupPosition, childPosition);
     64 
     65         v.bind(item.getDisplayItem());
     66         return v;
     67     }
     68 
     69     @Override
     70     public int getChildrenCount(final int groupPosition) {
     71         return mVCards.get(groupPosition).getContactInfo().size();
     72     }
     73 
     74     @Override
     75     public Object getGroup(final int groupPosition) {
     76         return mVCards.get(groupPosition);
     77     }
     78 
     79     @Override
     80     public int getGroupCount() {
     81         return mVCards.size();
     82     }
     83 
     84     @Override
     85     public long getGroupId(final int groupPosition) {
     86         return groupPosition;
     87     }
     88 
     89     @Override
     90     public View getGroupView(final int groupPosition, final boolean isExpanded,
     91             final View convertView, final ViewGroup parent) {
     92         PersonItemView v;
     93         if (convertView == null) {
     94             v = instantiateView(parent);
     95         } else {
     96             v = (PersonItemView) convertView;
     97         }
     98 
     99         final VCardResourceEntry item = (VCardResourceEntry) getGroup(groupPosition);
    100         v.bind(item.getDisplayItem());
    101         return v;
    102     }
    103 
    104     @Override
    105     public boolean isChildSelectable(final int groupPosition, final int childPosition) {
    106         return true;
    107     }
    108 
    109     @Override
    110     public boolean hasStableIds() {
    111         return true;
    112     }
    113 
    114     private PersonItemView instantiateView(final ViewGroup parent) {
    115         final PersonItemView v = (PersonItemView) mInflater.inflate(R.layout.people_list_item_view,
    116                 parent, false);
    117         v.setClickable(false);
    118         return v;
    119     }
    120 }
    121