 
package com.lianxin.pubqq.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lianxin.pubqq.R;
import com.lianxin.panqq.edit.AddFriendDialog;
import com.lianxin.panqq.edit.BanMemberDialog;
import com.lianxin.panqq.edit.EditFriendPowerDialog;
import com.lianxin.panqq.edit.EditNicknameDialog;
import com.lianxin.panqq.edit.EditPowerDialog;
import com.lianxin.panqq.edit.MarkUserDialog;
import com.lianxin.panqq.edit.MoneyGiveUserDialog;
import com.lianxin.panqq.edit.MyAlertDialog;
import com.lianxin.panqq.client.AskClient;
import com.lianxin.panqq.client.EditClient;
import com.lianxin.panqq.client.getClient;
import com.lianxin.panqq.client.getHeadClient;
import com.lianxin.panqq.client.markClient;
import com.lianxin.panqq.client.callback.askCallBack;
import com.lianxin.panqq.client.callback.getCallBack;
import com.lianxin.panqq.common.BaseActivity;
import com.lianxin.panqq.common.DefineChat;
import com.lianxin.panqq.common.EditResult;
import com.lianxin.panqq.common.GloableParams;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.list.bean.DepartMent;
import com.lianxin.panqq.list.bean.GroupNode;
import com.lianxin.panqq.list.bean.Member;
import com.lianxin.panqq.list.bean.UserNode;
import com.lianxin.panqq.list.utils.AddressUtils;
import com.lianxin.panqq.list.utils.FriendTypeUtils;
import com.lianxin.panqq.list.utils.FriendUtils;
import com.lianxin.panqq.list.utils.UserUtil;
import com.lianxin.panqq.common.utils.PowerUtils;
import com.lianxin.panqq.common.utils.UserheadUtils;
import com.lianxin.pubqq.chat.EMChatActivity;
import com.lianxin.panqq.common.DefineUser;
import com.lianxin.panqq.list.utils.GroupManger;
import com.lianxin.panqq.utils.ImagesUtils;
import com.lianxin.panqq.utils.TimeUtil;
//import com.lianxin.panqq.chat.entity.EMMessage;
//import com.lianxin.panqq.file.GroupFileUtil;
//import com.lianxin.panqq.file.UserFileUtil;
import com.lianxin.panqq.common.bean.AskInfo;
import com.lianxin.panqq.common.bean.UserEditInfo;
import com.lianxin.panqq.common.bean.UserInfo;
//成员信息界面
public class MemberInfoActivity extends BaseActivity implements OnClickListener {
	private TextView txt_title,txt_right;
	private ImageView img_back, img_right; 
	private ImageView img_photo;  //用户头像
	private TextView txt_userid; //用户id
	private TextView txt_username;  //用户名	
	private TextView txt_nickname; //用户昵称
	private TextView txt_sex;  //用户性别
	private TextView txt_age;  //用户年龄
	private TextView txt_address;   //用户地区
	private TextView txt_power;   //用户职业
	private TextView txt_index;   //用户签名
	private TextView txt_jointime;  //用户在哪动态

	private Button btn_satrtchat;
	private Button btn_addfriend;
	private Button btn_delmember;	
	private Button btn_toblack;
	private Button btn_markuser;
	private Button btn_givemoney;	
	private Button btn_detail;
	private Button btn_admin;
	private RelativeLayout lay_nickname;
	private RelativeLayout lay_power;  
	private RelativeLayout lay_index;

	private int nUserId = 10100;//用户唯一id
	private String strUserName = "情已停机";
	private int image = 10;
	private long userHead = 0;	
	private String strNickName = "赵八方";
	private int iSex = 1;
	private String Sex = "男";	
	private int iAge = 20;
	private int iAddress = 10;
	private int iPower = 1;
	private int iIndex = 10;
	private long joinTime = 0;	
	
	private int nTypeId = 10001;
	//private int nTypeType =  EMMessage.ChatType.ChatType_DEPART;
	private int groupType = DefineUser.TYPE_CROWD;
	private UserInfo userInfo;	

	private LinearLayout lay_right;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_memberinfo);
		
		initControl();
		initView();
		initData();
		setListener();	

		getRemoteMemberInfo();		
	}

	protected void initControl() {
		txt_title = (TextView) findViewById(R.id.txt_title);
		//txt_title.setText("用户查找");
		img_back = (ImageView) findViewById(R.id.img_back);
		img_back.setVisibility(View.VISIBLE);	
		txt_userid = (TextView)findViewById(R.id.tv_user_userid);
		txt_username = (TextView)findViewById(R.id.tv_user_username);		
		img_photo = (ImageView)findViewById(R.id.iv_user_image);
		txt_nickname = (TextView)findViewById(R.id.tv_user_nickname);
		txt_sex = (TextView)findViewById(R.id.tv_user_sex);
		txt_age = (TextView)findViewById(R.id.tv_user_age);
		txt_address = (TextView)findViewById(R.id.tv_user_address);
		txt_power = (TextView)findViewById(R.id.tv_user_power);
		txt_index = (TextView)findViewById(R.id.tv_user_index);		
		txt_jointime = (TextView)findViewById(R.id.tv_user_jointime);

		lay_nickname = (RelativeLayout) findViewById(R.id.rl_user_nickname);
		lay_power = (RelativeLayout) findViewById(R.id.rl_user_power);
		lay_index = (RelativeLayout) findViewById(R.id.rl_user_index);		
		btn_satrtchat = (Button)findViewById(R.id.btn_startchat);
		btn_addfriend = (Button)findViewById(R.id.btn_addfriend);
		btn_delmember = (Button)findViewById(R.id.btn_delmember);		
		btn_toblack = (Button)findViewById(R.id.btn_toblack);
		btn_markuser = (Button)findViewById(R.id.btn_markuser);
		btn_givemoney = (Button)findViewById(R.id.btn_givemoney);		
		btn_detail = (Button)findViewById(R.id.btn_detail);
		btn_admin = (Button)findViewById(R.id.btn_admin);
		
		lay_right = (LinearLayout)findViewById(R.id.layout_right);
		txt_right = (TextView)findViewById(R.id.tv_right);
	}

	protected void initView() {
		nUserId = getIntent().getIntExtra("Info_UserId", 10010);
		//判断是否是自己				
		if(nUserId == GloableParams.m_szUserId){
			txt_right.setText("我的故事");
			btn_satrtchat.setEnabled(false);
			btn_addfriend.setEnabled(false);
			btn_toblack.setEnabled(false);
			btn_givemoney.setEnabled(false);			
		}
		//判断是否是好友，如果是就把加好友隐藏
		//if(MyApp.getInstance().getContactList().contains(userId)){		
		if(FriendUtils.getFriendList(nUserId)>0){
			//btn_addfriend.setVisibility(View.GONE);
			btn_addfriend.setEnabled(false);			
		}
	
	}
	
	protected void initData() {
		nTypeId = getIntent().getIntExtra("TypeID", 10010);
		groupType = getIntent().getIntExtra("Info_GroupType", 3);
		nUserId = getIntent().getIntExtra("Info_UserId", 10010);	
		strUserName = getIntent().getStringExtra("Info_NickName");
		strNickName = getIntent().getStringExtra("Info_NickName");			
				
		//strUserName = getIntent().getStringExtra("Info_UserName");
		//strNickName = getIntent().getStringExtra("Info_NickName");	
		//strNickName = getIntent().getStringExtra("Info_UserName");			
		/*image = getIntent().getIntExtra("Info_Image", 23);		
		iAge = getIntent().getIntExtra("Info_Age", 20);
		iAddress = getIntent().getIntExtra("Info_Address", 10);
		Sex = getIntent().getStringExtra("Info_Sex");	
		iPower = getIntent().getIntExtra("Info_Power", 1);
		iIndex = getIntent().getIntExtra("Info_Index", 10);*/
		if (groupType==DefineUser.TYPE_DEPART||groupType==DefineUser.TYPE_CITY) {
			DepartMent member = GroupManger.getDepartMent(groupType, nUserId);
			strNickName = member.getName();
			image = member.imageid;
			iAge = member.age;
			iAddress = member.address;
			Sex = member.sex;
			iPower = member.getPower();
			iIndex = member.index;
		}else {
			Member member = GroupManger.getMember(groupType, nUserId, nTypeId);
			strNickName = member.getName();
			image = member.imageid;
			iAge = member.age;
			iAddress = member.address;
			Sex = member.sex;
			iPower = member.getPower();
			iIndex = member.index;
		}
		//如果是本地数据，则读取本地文件
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){		
		    UserNode thisUser = UserUtil.readOneUser(MemberInfoActivity.this, nUserId);	
			strUserName = thisUser.getName();
			iAge = thisUser.age;
			iAddress = thisUser.address;
			//strAddress = thisUser.straddress;				
			image = thisUser.imageid;
			Sex = thisUser.sex;			     			     
		}			
		txt_userid.setText(""+nUserId); 
		txt_username.setText(strUserName);	
		txt_nickname.setText(strNickName);		
        if(image<0) image = -image;		
        if(image>80) image = image%80;
        img_photo.setImageResource(ImagesUtils.images[image]);	
 
		txt_address.setText(AddressUtils.getAddress(iAddress));        
 	
        txt_power.setText(PowerUtils.getPowerText(groupType,iPower));       
        txt_index.setText(""+iIndex);
        txt_sex.setText(Sex);
        txt_age.setText(""+iAge);       
        userInfo = new UserInfo(nUserId,nTypeId,strNickName,image,iPower,iIndex);        
	}	

	protected void reSetData() {
 
		txt_userid.setText(""+nUserId); 
		txt_username.setText(strUserName);	
		txt_nickname.setText(strNickName);		
        if(image<0) image = -image;		
        if(image>80) image = image%80;
        img_photo.setImageResource(ImagesUtils.images[image]);	
		txt_address.setText(AddressUtils.getAddress(iAddress));        	
        txt_power.setText(PowerUtils.getPowerText(groupType,iPower));       
        txt_index.setText(""+iIndex); 
        txt_sex.setText(Sex);
        txt_age.setText(""+iAge);        
        if(joinTime>1000000)
        //txt_jointime.setText(TimeUtil.getMinTime(joinTime)); 
        txt_jointime.setText(TimeUtil.getMinTime(joinTime*1000));         
        if(userHead > 0x10000){
        	int mode = UserheadUtils.showUserHead(nUserId,userHead,img_photo);
        	if(mode>1)
        	getRemoteUserHead();
        }      
	}	
	
	protected void setListener() {
		img_back.setOnClickListener(this);		
		lay_right.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {

			}
		});
		btn_satrtchat.setOnClickListener(this);
		btn_addfriend.setOnClickListener(this); 
		btn_delmember.setOnClickListener(this); 		
		btn_toblack.setOnClickListener(this);
		btn_markuser.setOnClickListener(this);			
		btn_givemoney.setOnClickListener(this);	
		btn_detail.setOnClickListener(this);
		btn_admin.setOnClickListener(this);			
		lay_nickname.setOnClickListener(this); 
		lay_power.setOnClickListener(this);
		lay_index.setOnClickListener(this); 	
	}	
	

	
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		int id = arg0.getId();
		if (id == R.id.img_back) {
			Utils.finish(MemberInfoActivity.this);
			//finish();
			//finish(MemberInfoActivity.this);
		} else if (id == R.id.btn_startchat) {
			Intent intent = new Intent(this, EMChatActivity.class);
			intent.putExtra("Chat_ID", nUserId);
			intent.putExtra("Chat_Type", DefineChat.ChatType_USER);
			intent.putExtra("Chat_Name", strNickName);
			startActivity(intent);
		} else if (id == R.id.btn_addfriend) {
			if (FriendUtils.getFriendList(nUserId) > 0) {//判断是否已经是好友
				UserInfo uinfo2 = new UserInfo(GloableParams.m_szUserId, nUserId, strNickName, image, iPower, iIndex);
				new EditFriendPowerDialog(MemberInfoActivity.this, uinfo2, iPower,
						new EditFriendPowerDialog.OnSetListener() {
							@Override
							public void onSelect(UserInfo uinfo) {
								//   txt_power.setText(""+uinfo.power);
								txt_power.setText(FriendTypeUtils.getTypeName(uinfo.power));
								editFriendPower(uinfo);
							}
						}).show();
			} else {
				AskInfo uinfo = new AskInfo(nUserId, strNickName, image);
				new AddFriendDialog(MemberInfoActivity.this, uinfo,
						new AddFriendDialog.OnSetListener() {
							@Override
							public void onSelect(AskInfo askInfo) {
								addFriend(askInfo);
							}
						}).show();
			}
		} else if (id == R.id.btn_delmember) {
			new MyAlertDialog(MemberInfoActivity.this, "删除成员？",
					"你确定要从此群中删除该成员吗？",
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
							UserInfo uinfo = new UserInfo(nUserId, nTypeId, strNickName, image, iPower, iIndex);
							deleteMember(uinfo);
						}
					}).show();
		} else if (id == R.id.btn_toblack) {
			new BanMemberDialog(MemberInfoActivity.this, groupType, nTypeId, nUserId, strNickName,
					new BanMemberDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							//addFriend(askInfo);
							txt_power.setText("" + option);
						}
					}).show();
			/*new MyAlertDialog(MemberInfoActivity.this,"移入到黑名单？",
					"你确定要将该成员移入到黑名单吗？",
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
						//	UserInfo uinfo = new UserInfo(nUserId,nTypeId,strNickName,image,iPower,iIndex);
						//	deleteMember(uinfo);
						}
					}).show();	*/
		} else if (id == R.id.btn_markuser) {
			new MarkUserDialog(MemberInfoActivity.this, nUserId, strNickName,
					new MarkUserDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							MarkUser(option);
							// txt_power.setText(""+admin);
						}

						@Override
						public void onSelect(int count, int max) {
							String str = "投票成功。\n你今天已经投票" + count + "次，";
							int sub = max - count;
							if (count < max)
								str += "\n还可以投票" + sub + "次\n";
							else
								str += "\n每天的投票最大次数为20+金钻等级。\n超过的每次投票花费0.2个PQ币。\n";
							Utils.showLongToast(MemberInfoActivity.this, str);
						}
					}).show();
		} else if (id == R.id.btn_givemoney) {
			new MoneyGiveUserDialog(MemberInfoActivity.this, nUserId, strNickName,
					new MoneyGiveUserDialog.OnSetListener() {
						@Override
						public void onSelect(int option, int money) {
							//addFriend(askInfo);
							txt_power.setText("" + money);
						}
					}).show();
		} else if (id == R.id.btn_detail) {
			Intent intent3 = new Intent(MemberInfoActivity.this, UserDetailInfoActivity.class);
			intent3.putExtra("Info_UserId", nUserId);
			intent3.putExtra("Info_UserName", strUserName);
			intent3.putExtra("Info_Age", iAge);
			intent3.putExtra("Info_Address", iAddress);
			intent3.putExtra("Info_Image", image);
			intent3.putExtra("Info_Sex", Sex);
			startActivity(intent3);
		} else if (id == R.id.btn_admin) {
			Intent intent4 = new Intent(MemberInfoActivity.this, UserSuperInfoActivity.class);
			intent4.putExtra("Info_UserId", nUserId);
			intent4.putExtra("Info_UserName", strUserName);
			intent4.putExtra("Info_Age", iAge);
			intent4.putExtra("Info_Address", iAddress);

			intent4.putExtra("Info_Image", image);
			intent4.putExtra("Info_Sex", Sex);
			startActivity(intent4);
		} else if (id == R.id.rl_user_nickname) {
			new EditNicknameDialog(MemberInfoActivity.this, userInfo, strUserName, iIndex,
					new EditNicknameDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							String strname = uinfo.nickname;
							txt_nickname.setText(strname);
							txt_index.setText("" + uinfo.index);
							editNickname(uinfo);
						}
					}).show();
		} else if (id == R.id.rl_user_power) {
			new EditPowerDialog(MemberInfoActivity.this, userInfo, iPower,
					new EditPowerDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							//  txt_power.setText(""+uinfo.power);
							txt_power.setText(PowerUtils.getPowerText(groupType, uinfo.power));
							editPower(uinfo);
						}
					}).show();
		} else if (id == R.id.rl_user_index) {//UserInfo uinfo4 = new UserInfo(nUserId,nTypeId,strNickName,image,iPower,iIndex);
			new EditNicknameDialog(MemberInfoActivity.this, userInfo, strUserName, iIndex,
					new EditNicknameDialog.OnSetListener() {
						@Override
						public void onSelect(UserInfo uinfo) {
							String strname = uinfo.nickname;
							txt_nickname.setText(strname);
							txt_index.setText("" + uinfo.index);
							editNickname(uinfo);
						}
					}).show();
		}
	} 

	private void getRemoteMemberInfo(){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "不能添加自己"));
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	startActivity(new Intent(this, AlertDialog.class).putExtra("msg", "此用户已是你的好友"));
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			UserNode userNode = UserUtil.readOneUser( MemberInfoActivity.this,nUserId );
			if(userNode!=null){
			    strUserName = userNode.username;						
			    iAddress = userNode.address;
			    iAge = userNode.age;
			    Sex = userNode.sex;						
			    image = userNode.imageid;						      
                reSetData();
			}
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在刷新数据...").show();	
		getClient.GetEditUser(groupType,nUserId,nTypeId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				//SearUserList searlist = new SearUserList(recvBuf);	
				final UserEditInfo userEditInfo = new UserEditInfo(recvBuf);				
				//final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();						
						strUserName = userEditInfo.username;						
						strNickName = userEditInfo.nickname;
						iAddress = userEditInfo.address;
						iAge = userEditInfo.age;
						Sex = userEditInfo.sex;						
						image = userEditInfo.imageid;	
						//userHead = userInfo.userhead;
						userHead = userEditInfo.userhead;						
						iPower = userEditInfo.power;
						iIndex = userEditInfo.index;	
						joinTime = userEditInfo.jointime;						
						reSetData();						
						//Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();						
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 		
	
	}	

	private void getRemoteUserHead(){

		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器		
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在刷新头像...").show();	
		getHeadClient.GetUserHead(DefineUser.TYPE_FRIEND,nUserId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {

				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新头像...").dismiss();					
						UserheadUtils.showUserHead(nUserId,userHead,img_photo);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {

				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新头像...").dismiss();						
					}
				});	
			}
		});	 		
	
	}	
	
	public void editNickname(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(uinfo.userid==GloableParams.m_szUserId){//如果是自己
		}else if(GroupManger.getMyAdminPower( )>0){//判断自己是否是系统管理员
		}	
		else if(GroupManger.getMemberPower( groupType, GloableParams.m_szUserId, nTypeId)<=1){//判断是否有权限
			Utils.showLongToast(MemberInfoActivity.this, "你没有修改权限!");
			return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditMemberName(groupType,uinfo); //修改本地数据		
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		EditClient.EditMemberName(groupType,uinfo,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void editPower(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(GroupManger.getMyAdminPower( )>0){//判断自己是否是系统管理员
		}	
		else if(GroupManger.getMemberPower( groupType, GloableParams.m_szUserId, nTypeId)<=3){//判断是否有权限
			Utils.showLongToast(MemberInfoActivity.this, "你没有修改权限!");
			return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditMemberPower(groupType,uinfo); //修改本地数据			
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		EditClient.EditMemberPower(groupType,uinfo,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();
			//	UserInfo uinfo1 = uinfo;				
			//	EditResult.EditMemberPower(groupType,uinfo);				
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void deleteMember(UserInfo uinfo){
		int nDestid = uinfo.destid;
        if(GroupManger.getMyAdminPower( )>0){//判断自己是否是系统管理员
		}		
		else if(GroupManger.getMemberPower( groupType, GloableParams.m_szUserId, nTypeId)<=2){//判断是否有权限
			Utils.showLongToast(MemberInfoActivity.this, "你没有修改权限!");
			return;
		}	
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.DeleteMember(groupType,uinfo); //修改本地数据			
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		EditClient.DeleteMember(groupType,uinfo,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	public void addFriend(AskInfo uinfo){
		int nDestid = uinfo.destid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
			Utils.showLongToast(MemberInfoActivity.this, "不能添加自己!");			
			return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
			Utils.showLongToast(MemberInfoActivity.this, "此用户已是你的好友!");			
			return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		AskClient.AskAddFriend(uinfo,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	public void editFriendPower(UserInfo uinfo){
		int nDestid = uinfo.destid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
			Utils.showLongToast(MemberInfoActivity.this, "不能添加自己!");			
			return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
			Utils.showLongToast(MemberInfoActivity.this, "此用户已是你的好友!");			
			return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditMemberPower(DefineUser.TYPE_FRIEND,uinfo); //修改本地数据			
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();	
		//EditClient.EditMemberPower(DefineUser.TYPE_FRIEND,uinfo,new askCallBack(){		
		EditClient.EditFriend(uinfo,DefineUser.ASK_FRIEND_EDITUSER,new askCallBack(){	
			@Override
			public void onSuccess(int statusCode, String message) {
				getLoadingDialog("正在发送请求...").dismiss();	
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void MarkUser( int option ){
		int nDestid = nUserId;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		//	return;
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友
		//	return;
		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(MemberInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在投票中...").show();		
		markClient.putMarkVote(DefineUser.TYPE_FRIEND,nUserId,option,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				final int count = recvBuf[4];	
				final int max = recvBuf[8];				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在投票中...").dismiss();
						String str = "投票成功。\n你今天已经投票"+count+"次，";
						int sub = max - count;
						if(count<max)
							str += "\n还可以投票"+sub +"次\n";
						else
							str += "\n每天的投票最大次数为20+金钻等级。\n超过的每次投票花费0.2个PQ币。\n";						
						Utils.showLongToast(MemberInfoActivity.this, str);
						
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在正在投票中...").dismiss();							
						Utils.showLongToast(MemberInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
}