76a804fd52be1316dd8878334d9157384dc42b6e
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / adapter / ShareUserListAdapter.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * Copyright (C) 2015 ownCloud Inc.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 package com.owncloud.android.ui.adapter;
22
23 import android.content.Context;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ArrayAdapter;
28 import android.widget.ImageView;
29 import android.widget.TextView;
30
31 import com.owncloud.android.R;
32 import com.owncloud.android.lib.resources.shares.OCShare;
33 import com.owncloud.android.lib.resources.shares.ShareType;
34
35 import java.util.ArrayList;
36
37 /**
38 * Adapter to show a user/group in Share With List
39 */
40 public class ShareUserListAdapter extends ArrayAdapter {
41
42 private Context mContext;
43 private ArrayList<OCShare> mShares;
44
45 public ShareUserListAdapter(Context context, int resource, ArrayList<OCShare>shares) {
46 super(context, resource);
47 mContext= context;
48 mShares = shares;
49 }
50
51 @Override
52 public int getCount() {
53 return mShares.size();
54 }
55
56 @Override
57 public Object getItem(int position) {
58 return mShares.get(position);
59 }
60
61 @Override
62 public long getItemId(int position) {
63 return 0;
64 }
65
66 @Override
67 public View getView(final int position, View convertView, ViewGroup parent) {
68 LayoutInflater inflator = (LayoutInflater) mContext
69 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
70 View view = inflator.inflate(R.layout.share_user_item, parent, false);
71
72 if (mShares != null && mShares.size() > position) {
73 OCShare share = mShares.get(position);
74
75 TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
76 String name = share.getSharedWithDisplayName();
77 if (share.getShareType() == ShareType.GROUP) {
78 name = getContext().getString(R.string.share_group_clarification, name);
79 }
80 userName.setText(name);
81
82 ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton);
83 unshareButton.setVisibility(View.GONE);
84
85 }
86 return view;
87 }
88
89
90
91 }