View Javadoc
1   /*
2    * Copyright (C) 2003-2015 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 3 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  package org.exoplatform.ui.social;
20  
21  import java.util.List;
22  
23  import org.exoplatform.R;
24  import org.exoplatform.model.SocialSpaceInfo;
25  
26  import android.content.Context;
27  import android.view.LayoutInflater;
28  import android.view.View;
29  import android.view.ViewGroup;
30  import android.widget.BaseAdapter;
31  import android.widget.ImageView;
32  import android.widget.TextView;
33  
34  import com.squareup.picasso.Picasso;
35  
36  /**
37   * Created by The eXo Platform SAS Author : Philippe Aristote
38   * paristote@exoplatform.com Apr 22, 2015
39   */
40  public class SpaceListAdapter extends BaseAdapter {
41  
42      private Context               mContext;
43  
44      private List<SocialSpaceInfo> mSpaceList;
45  
46      public SpaceListAdapter(Context ctx) {
47          mContext = ctx;
48      }
49  
50      public void setSpaceList(List<SocialSpaceInfo> list) {
51          mSpaceList = list;
52      }
53  
54      @Override
55      public int getCount() {
56          return mSpaceList == null ? 0 : mSpaceList.size();
57      }
58  
59      @Override
60      public Object getItem(int pos) {
61          return mSpaceList == null ? null : mSpaceList.get(pos);
62      }
63  
64      @Override
65      public long getItemId(int pos) {
66          return pos;
67      }
68  
69      @Override
70      public View getView(int index, View convertView, ViewGroup parent) {
71          ViewHolder holder;
72          if (convertView == null) {
73              LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
74              convertView = inflater.inflate(R.layout.compose_message_space_item, parent, false);
75              holder = new ViewHolder();
76              holder.spaceName = (TextView) convertView.findViewById(R.id.item_space_name);
77              holder.spaceAvatar = (ImageView) convertView.findViewById(R.id.item_space_avatar);
78              convertView.setTag(holder);
79          } else {
80              holder = (ViewHolder) convertView.getTag();
81          }
82  
83          SocialSpaceInfo space = (SocialSpaceInfo) getItem(index);
84          holder.spaceName.setText(space.displayName);
85          Picasso.with(mContext)
86                 .load(space.avatarUrl)
87                 .placeholder(R.drawable.icon_space_default)
88                 .error(R.drawable.icon_space_default)
89                 .into(holder.spaceAvatar);
90          return convertView;
91      }
92  
93      static class ViewHolder {
94          ImageView spaceAvatar;
95  
96          TextView  spaceName;
97      }
98  
99  }