|
@@ -22,6 +22,7 @@ package com.owncloud.android.ui.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
@@ -32,7 +33,10 @@ import android.widget.TextView;
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.lib.resources.shares.OCShare;
|
|
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
|
|
+import com.owncloud.android.ui.TextDrawable;
|
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +47,7 @@ public class ShareUserListAdapter extends ArrayAdapter {
|
|
|
private Context mContext;
|
|
|
private ArrayList<OCShare> mShares;
|
|
|
private ShareUserAdapterListener mListener;
|
|
|
+ private float mAvatarRadiusDimension;
|
|
|
|
|
|
public ShareUserListAdapter(Context context, int resource, ArrayList<OCShare>shares,
|
|
|
ShareUserAdapterListener listener) {
|
|
@@ -50,6 +55,8 @@ public class ShareUserListAdapter extends ArrayAdapter {
|
|
|
mContext= context;
|
|
|
mShares = shares;
|
|
|
mListener = listener;
|
|
|
+
|
|
|
+ mAvatarRadiusDimension = context.getResources().getDimension(R.dimen.standard_padding);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -67,32 +74,46 @@ public class ShareUserListAdapter extends ArrayAdapter {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ @NonNull
|
|
|
@Override
|
|
|
- public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
- LayoutInflater inflator = (LayoutInflater) mContext
|
|
|
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
- View view = inflator.inflate(R.layout.share_user_item, parent, false);
|
|
|
+ public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
|
|
|
+ View view = convertView;
|
|
|
+ if (view == null) {
|
|
|
+ LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ view = inflater.inflate(R.layout.share_user_item, parent, false);
|
|
|
+ }
|
|
|
|
|
|
if (mShares != null && mShares.size() > position) {
|
|
|
OCShare share = mShares.get(position);
|
|
|
|
|
|
- TextView userName = (TextView) view.findViewById(R.id.userOrGroupName);
|
|
|
- ImageView iconView = (ImageView) view.findViewById(R.id.icon);
|
|
|
- final ImageView editShareButton = (ImageView) view.findViewById(R.id.editShareButton);
|
|
|
- final ImageView unshareButton = (ImageView) view.findViewById(R.id.unshareButton);
|
|
|
+ TextView userName = view.findViewById(R.id.userOrGroupName);
|
|
|
+ ImageView icon = view.findViewById(R.id.icon);
|
|
|
+ final ImageView editShareButton = view.findViewById(R.id.editShareButton);
|
|
|
+ final ImageView unshareButton = view.findViewById(R.id.unshareButton);
|
|
|
|
|
|
String name = share.getSharedWithDisplayName();
|
|
|
- Drawable icon = getContext().getResources().getDrawable(R.drawable.ic_user);
|
|
|
if (share.getShareType() == ShareType.GROUP) {
|
|
|
name = getContext().getString(R.string.share_group_clarification, name);
|
|
|
- icon = getContext().getResources().getDrawable(R.drawable.ic_group);
|
|
|
+ try {
|
|
|
+ icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
|
|
|
+ } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
|
|
+ icon.setImageResource(R.drawable.ic_group);
|
|
|
+ }
|
|
|
} else if (share.getShareType() == ShareType.EMAIL) {
|
|
|
name = getContext().getString(R.string.share_email_clarification, name);
|
|
|
- icon = getContext().getResources().getDrawable(R.drawable.ic_email);
|
|
|
- editShareButton.setVisibility(View.INVISIBLE);
|
|
|
+ try {
|
|
|
+ icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
|
|
|
+ } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
|
|
+ icon.setImageResource(R.drawable.ic_email);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
|
|
|
+ } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
|
|
+ icon.setImageResource(R.drawable.ic_user);
|
|
|
+ }
|
|
|
}
|
|
|
userName.setText(name);
|
|
|
- iconView.setImageDrawable(icon);
|
|
|
|
|
|
/// bind listener to edit privileges
|
|
|
editShareButton.setOnClickListener(new View.OnClickListener() {
|