<commit_before>package com.easemob.easeui.utils;

import java.util.HashMap;
import java.util.Map;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONObject;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.easemob.easeui.Constant;
import com.easemob.easeui.R;
import com.easemob.easeui.bean.SimiUser;
import com.easemob.easeui.controller.EaseUI;
import com.easemob.easeui.controller.EaseUI.EaseUserProfileProvider;
import com.easemob.easeui.database.DBHelper;
import com.easemob.easeui.domain.EaseUser;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

public class EaseUserUtils {
    
    static EaseUserProfileProvider userProvider;
    
    static {
        userProvider = EaseUI.getInstance().getUserProfileProvider();
    }
    
    /**
     * 根据username获取相应user
     * @param username
     * @return
     */
    public static EaseUser getUserInfo(String username){
        if(userProvider != null)
            return userProvider.getUser(username);
        
        return null;
    }
    
    /**
     * 设置用户头像
     * @param username
     */
    public static void setUserAvatar(Context context, String username, ImageView imageView){
    	EaseUser user = getUserInfo(username);
        if(user != null && !TextUtils.isEmpty(user.getAvatar())){//modify by garry
            try {
                int avatarResId = Integer.parseInt(user.getAvatar());
                Picasso.with(context).load(avatarResId).into(imageView);
            } catch (Exception e) {
                //正常的string路径
//                Picasso.with(context).load(user.getAvatar()).placeholder(R.drawable.ease_default_avatar).into(imageView);
            	Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
            }
        }else{
            Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
        }
    }
    
    /**
     * 设置用户昵称
     */
    public static void setUserNick(String username,TextView textView){
        if(textView != null){
        	EaseUser user = getUserInfo(username);
        	if(user != null && user.getNick() != null){
        		textView.setText(user.getNick());
        	}else{
        		textView.setText(username);
        	}
        }
    }
    
    /**
     * 设置用户头像
     * 
     * by garry
     */
    public static void setUserAvatar(Context context, EaseUser user, ImageView imageView){
        if(user != null && !TextUtils.isEmpty(user.getAvatar())){//modify by garry
            try {
                int avatarResId = Integer.parseInt(user.getAvatar());
                Picasso.with(context).load(avatarResId).into(imageView);
            } catch (Exception e) {
                //正常的string路径
//                Picasso.with(context).load(user.getAvatar()).placeholder(R.drawable.ease_default_avatar).into(imageView);
            	Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);//modify by garry
            }
        }else{
            Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
        }
    }
    
    /**
     * 设置用户头像 和 昵称
     * 
     * by garry
     */
    public static void setUserAvatarAndNick(Context context, String username, ImageView imageView, TextView textView){
    	SimiUser simiUser = DBHelper.getInstance(context).getSimiUserInfo(context, username);
    	<commit_msg>fix imageView<commit_after>package com.easemob.easeui.utils;

import java.util.HashMap;
import java.util.Map;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import net.tsz.afinal.http.AjaxParams;

import org.json.JSONObject;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.easemob.easeui.Constant;
import com.easemob.easeui.R;
import com.easemob.easeui.bean.SimiUser;
import com.easemob.easeui.controller.EaseUI;
import com.easemob.easeui.controller.EaseUI.EaseUserProfileProvider;
import com.easemob.easeui.database.DBHelper;
import com.easemob.easeui.domain.EaseUser;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

public class EaseUserUtils {
    
    static EaseUserProfileProvider userProvider;
    
    static {
        userProvider = EaseUI.getInstance().getUserProfileProvider();
    }
    
    /**
     * 根据username获取相应user
     * @param username
     * @return
     */
    public static EaseUser getUserInfo(String username){
        if(userProvider != null)
            return userProvider.getUser(username);
        
        return null;
    }
    
    /**
     * 设置用户头像
     * @param username
     */
    public static void setUserAvatar(Context context, String username, ImageView imageView){
    	EaseUser user = getUserInfo(username);
        if(user != null && !TextUtils.isEmpty(user.getAvatar())){//modify by garry
            try {
//                int avatarResId = Integer.parseInt(user.getAvatar());
                Picasso.with(context).load(user.getAvatar()).into(imageView);
            } catch (Exception e) {
                //正常的string路径
//                Picasso.with(context).load(user.getAvatar()).placeholder(R.drawable.ease_default_avatar).into(imageView);
            	Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
            }
        }else{
            Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
        }
    }
    
    /**
     * 设置用户昵称
     */
    public static void setUserNick(String username,TextView textView){
        if(textView != null){
        	EaseUser user = getUserInfo(username);
        	if(user != null && user.getNick() != null){
        		textView.setText(user.getNick());
        	}else{
        		textView.setText(username);
        	}
        }
    }
    
    /**
     * 设置用户头像
     * 
     * by garry
     */
    public static void setUserAvatar(Context context, EaseUser user, ImageView imageView){
        if(user != null && !TextUtils.isEmpty(user.getAvatar())){//modify by garry
            try {
//                int avatarResId = Integer.parseInt(user.getAvatar());
            	Picasso.with(context).load(user.getAvatar()).into(imageView);
            } catch (Exception e) {
                //正常的string路径
//                Picasso.with(context).load(user.getAvatar()).placeholder(R.drawable.ease_default_avatar).into(imageView);
            	Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);//modify by garry
            }
        }else{
            Picasso.with(context).load(R.drawable.ease_default_avatar).into(imageView);
        }
    }
    
    /**
     * 设置用户头像 和 昵称
     * 
     * by garry
     */
    public static void setUserAvatarAndNick(Context context, String username, ImageView imageView, TextView textView){
    	SimiUser simiUser = DBHelper.getInstance(context).getSimiUserInfo(context, username);
    	
{'fraction_non_alphanumeric': 0.11545518701482005, 'fraction_numerical': 0.0, 'mean_word_length': 2.5483224837255882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '407114', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2271, 'n_words': 341}