54ca46e615a43e559917c1c4d06685c30c1d74d4
[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.common.utils.Log_OC;
33 import com.owncloud.android.lib.resources.shares.OCShare;
34 import com.owncloud.android.lib.resources.shares.ShareType;
35
36 import java.util.ArrayList;
37
38 /**
39 * Adapter to show a user/group in Share With List
40 */
41 public class ShareUserListAdapter extends ArrayAdapter {
42
43 private Context mContext;
44 private ArrayList<OCShare> mShares;
45
46 private ImageView mUnshareButton;
47
48 public ShareUserListAdapter(Context context, int resource, ArrayList<OCShare>shares) {
49 super(context, resource);
50 mContext= context;
51 mShares = shares;
52 }
53
54 @Override
55 public int getCount() {
56 return mShares.size();
57 }
58
59 @Override
60 public Object getItem(int position) {
61 return mShares.get(position);
62 }
63
64 @Override
65 public long getItemId(int position) {
66 return 0;
67 }
68
69 @Override
70 public View getView(final int position, View convertView, ViewGroup parent) {
71 LayoutInflater inflator = (LayoutInflater) mContext
72 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
73 View view = inflator.inflate(R.layout.share_user_item, parent, false);
74
75 if (mShares != null && mShares.size() > position) {
76 OCShare share = mShares.get(position);
77
78 TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
79 String name = share.getSharedWithDisplayName();
80 if (share.getShareType() == ShareType.GROUP) {
81 name = name + mContext.getResources().getString(R.string.share_group_indicator);
82 }
83 userName.setText(name);
84
85 mUnshareButton = (ImageView) view.findViewById(R.id.unshareButton);
86 mUnshareButton.setVisibility(View.GONE);
87 mUnshareButton.setOnClickListener(new View.OnClickListener() {
88 @Override
89 public void onClick(View v) {
90 // TODO: Unshare
91
92 Log_OC.d("TAG - ShareUserListAdapter", "TODO Unshare - " +
93 mShares.get(position).getSharedWithDisplayName());
94 }
95 });
96
97
98 }
99 return view;
100 }
101
102
103
104 }