package androidpath.ll.leshare.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.parse.ParseUser;

import java.util.List;

import androidpath.ll.leshare.R;
import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Le on 2015/5/12.
 */
public class UserAdapter extends ArrayAdapter<ParseUser> {

    protected Context mContext;
    protected List<ParseUser> mUsers;


    public UserAdapter(Context context, List<ParseUser> users) {
        super(context, R.layout.user_items, users);
        mContext = context;
        mUsers = users;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.user_items, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }

        ParseUser user = mUsers.get(position);

        //set icon
//        if (message.getString(ParseConstants.KEY_FILE_TYPE).equals(ParseConstants.TYPE_IMAGE)) {
//            holder.iconImageView.setImageResource(R.mipmap.ic_picture);
//        } else {
//            holder.iconImageView.setImageResource(R.mipmap.ic_video);
//        }
        holder.userNameLabel.setText(user.getUsername());
        return convertView;
    }

    static class ViewHolder {
        //        @InjectView(R.id.message_Icon)
//        ImageView iconImageView;
        @InjectView(R.id.name_label)
        TextView userNameLabel;


        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    public void update(List<ParseUser> users) {
        mUsers.clear();
        mUsers.addAll(users);
        notifyDataSetChanged();
    }
}



@@ -191,24 +191,57 @@
 rayAdapter;%0A
+import android.widget.ImageView;%0A
 import andro
@@ -288,16 +288,53 @@
 rseUser;
+%0Aimport com.squareup.picasso.Picasso;
 %0A%0Aimport
@@ -384,16 +384,61 @@
 hare.R;%0A
+import androidpath.ll.leshare.Utils.MD5Util;%0A
 import b
@@ -1304,16 +1304,712 @@
 sition);
+%0A        String email = user.getEmail().toLowerCase();%0A        if (email.equals(%22%22)) %7B%0A            holder.userImageView.setImageResource(R.mipmap.avatar_empty);%0A        %7D else %7B%0A            // http://en.gravatar.com/site/implement/images/java/%0A            //get profile pic from gravatar base on email%0A            String hash = MD5Util.md5Hex(email);%0A            String gravatarUrl = %22http://www.gravatar.com/avatar/%22 + hash%0A                    + %22?s=204&d=404%22;%0A            Picasso.with(mContext)%0A                    .load(gravatarUrl)%0A                    .placeholder(R.mipmap.avatar_empty)  //if 404 code returned, show default image.%0A                    .into(holder.userImageView);%0A        %7D
 %0A%0A      
@@ -2420,26 +2420,16 @@
 older %7B%0A
-        //
         
@@ -2449,24 +2449,23 @@
 .id.
-message_Icon)%0A//
+userImageView)%0A
     
@@ -2478,20 +2478,20 @@
 ageView 
-icon
+user
 ImageVie

load profile pic from gravatar for each user, if 404 returned, then load default one.