 
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.AskApplyDialog;
import com.lianxin.panqq.edit.AskJoinDialog;
import com.lianxin.panqq.edit.BanGroupDialog;
import com.lianxin.panqq.edit.EditTypenameDialog;
import com.lianxin.panqq.edit.MarkGroupDialog;
import com.lianxin.panqq.edit.MoneyGiveGroupDialog;
import com.lianxin.panqq.edit.MyAlertDialog;
import com.lianxin.panqq.edit.SetupGuardDialog;
import com.lianxin.panqq.edit.SetupSightDialog;
//import com.lianxin.panqq.file.GroupFileUtil;
import com.lianxin.panqq.client.AskClient;
import com.lianxin.panqq.client.EditClient;
import com.lianxin.panqq.client.getClient;
import com.lianxin.panqq.client.markClient;
import com.lianxin.panqq.client.moneyClient;
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.EditResult;
import com.lianxin.panqq.common.GloableParams;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.list.bean.Depart;
import com.lianxin.panqq.list.bean.DepartMent;
import com.lianxin.panqq.list.bean.EMGroup;
import com.lianxin.panqq.list.bean.GroupNode;
import com.lianxin.panqq.list.bean.Member;
import com.lianxin.panqq.list.utils.AddressUtils;
import com.lianxin.panqq.list.utils.CityUtils;
import com.lianxin.panqq.list.utils.CollegeUtils;
import com.lianxin.panqq.list.utils.DepartUtils;
import com.lianxin.panqq.list.utils.FriendUtils;
import com.lianxin.panqq.list.utils.GroupManger;
import com.lianxin.panqq.list.utils.UserUtil;
import com.lianxin.panqq.common.utils.CaptionUtils;
import com.lianxin.panqq.common.utils.KeywordUtils;
import com.lianxin.panqq.common.utils.OpenLevelUtils;
import com.lianxin.panqq.common.utils.PowerUtils;
import com.lianxin.pubqq.chat.EMChatActivity;
import com.lianxin.panqq.common.DefineUser;
import com.lianxin.panqq.picker.AddressPickerDialog;
import com.lianxin.panqq.picker.CityPickerDialog;
import com.lianxin.panqq.picker.DeptPickerDialog;
import com.lianxin.panqq.picker.GradePickerDialog;
import com.lianxin.panqq.picker.KeyPickerDialog;
import com.lianxin.panqq.utils.MoneyUtil;
import com.lianxin.panqq.utils.ImagesUtils;
//import com.lianxin.panqq.chat.entity.EMMessage;
import com.lianxin.panqq.common.bean.AskInfo;
import com.lianxin.panqq.common.bean.GroupEditInfo;
import com.lianxin.panqq.common.bean.GroupInfo;
//我的分类信息界面
public class MytypeInfoActivity extends BaseActivity implements OnClickListener {
	private TextView txt_title,txt_right;
	private ImageView img_back, img_right; 
	private ImageView img_photo;  //用户头像
	
	private TextView txt_groupid; //用户id
	private TextView txt_groupname;  //用户名	
	private TextView cap_groupid, cap_groupname;	
	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 TextView txt_enyear;   //用户地区
	private TextView txt_type;   //用户职业
	private TextView txt_openlevel;  //用户在哪动态
	private TextView cap_type, cap_enyear;
	
	private Button btn_satrtchat;
	private Button btn_editgroup;
	private Button btn_exitgroup;	
	private Button btn_askapply;
	//private Button btn_jubao;
	private Button btn_setsight;
	private Button btn_setguard;
	private Button btn_listmember;	
	private Button btn_adminmember;	
	private Button btn_toblack;	
	private Button btn_markgroup;
	private Button btn_liftgroup;
	private Button btn_invite;	
	private RelativeLayout lay_nickname;
	private RelativeLayout lay_power;  
	private RelativeLayout lay_index;
	private RelativeLayout lay_type;  
	private RelativeLayout lay_enyear;
	
	private int nType = 10100;//用户唯一id
	private int nGroupId = 10100;//用户唯一id
	private String strGroupName = "情已停机";
	private int groupType = DefineUser.TYPE_CROWD;	
	private int iImage = 10;
	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 int nKeyword = 30;
	private int nAddress = 2;	
	private int iLevel = 2;	
	
	private String  sCaption = ""; //服务器各自定制的标题字符串
	private String[]  arrCaption = null; //标题字符串数组	
	private LinearLayout lay_right;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mytypeinfo);
		
		initControl();
		initView();
		initData();
		setListener();	
		
		getRemoteEditTypeInfo();	
	}

	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_groupid = (TextView)findViewById(R.id.tv_groupid);
		txt_groupname = (TextView)findViewById(R.id.tv_groupname);		
		cap_groupid = (TextView) findViewById(R.id.tv_groupid_cap);			
		cap_groupname = (TextView) findViewById(R.id.tv_groupname_cap);	
		img_photo = (ImageView)findViewById(R.id.iv_user_image);
		txt_nickname = (TextView)findViewById(R.id.tv_user_nickname);
		//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);	
		lay_type = (RelativeLayout) findViewById(R.id.rl_type);
		lay_enyear = (RelativeLayout) findViewById(R.id.rl_enyear);
		//lay_openlevel = (RelativeLayout) findViewById(R.id.rl_openlevel);	
		txt_type = (TextView)findViewById(R.id.tv_type);
		txt_enyear = (TextView)findViewById(R.id.tv_enyear);
		txt_openlevel = (TextView)findViewById(R.id.tv_openlevel);
		cap_type = (TextView) findViewById(R.id.tv_type_cap);			
		cap_enyear = (TextView) findViewById(R.id.tv_enyear_cap);		
		btn_satrtchat = (Button)findViewById(R.id.btn_startchat);
		btn_askapply = (Button)findViewById(R.id.btn_askapply);
		btn_editgroup = (Button)findViewById(R.id.btn_editgroup);
		btn_exitgroup = (Button)findViewById(R.id.btn_exitgroup);		
		btn_setsight = (Button)findViewById(R.id.btn_setsight);
		btn_setguard = (Button)findViewById(R.id.btn_setguard);	
		btn_listmember = (Button)findViewById(R.id.btn_listmember);	
		btn_adminmember = (Button)findViewById(R.id.btn_adminmember);
		btn_toblack = (Button)findViewById(R.id.btn_toblack);		
		btn_markgroup = (Button)findViewById(R.id.btn_markgroup);
		btn_liftgroup = (Button)findViewById(R.id.btn_liftgroup);
		btn_invite = (Button)findViewById(R.id.btn_invite);	
		lay_right = (LinearLayout)findViewById(R.id.layout_right);
		txt_right = (TextView)findViewById(R.id.tv_right);
	}

	protected void initView() {
		nGroupId = getIntent().getIntExtra("Info_GroupId", 10010);		
		strGroupName = getIntent().getStringExtra("Info_GroupName");
		groupType = getIntent().getIntExtra("Info_GroupType", 3);
		setCaption();

	}
	
	protected void initData() {

		//nType = getIntent().getIntExtra("TypeType", EMMessage.ChatType.ChatType_DEPART);
		nGroupId = getIntent().getIntExtra("TypeID", 10010);		
	//	strGroupName = getIntent().getStringExtra("TypeName");
	//	nGroupId = getIntent().getIntExtra("Info_GroupId", 10010);		
	//	strGroupName = getIntent().getStringExtra("Info_GroupName");		
		groupType = getIntent().getIntExtra("Info_GroupType", 3);
		strNickName = getIntent().getStringExtra("Info_NickName");		
		//iImage = getIntent().getIntExtra("Info_Image", 23);		
		//iAddress = getIntent().getIntExtra("Info_Address", 10);
		//iPower = getIntent().getIntExtra("Info_Power", 1);
		//iIndex = getIntent().getIntExtra("Info_Index", 10);
		if (groupType==DefineUser.TYPE_DEPART||groupType==DefineUser.TYPE_CITY) {
			Depart group = GroupManger.getDepart(groupType, nGroupId);
			strNickName = group.getName();
			strGroupName = group.getName();			
			iImage = group.imageid;
			nKeyword = group.type;
			nAddress = group.type;		
			iAddress = group.type;
			iPower = group.getPower();
			iIndex = group.index;
		}else {
			EMGroup group = GroupManger.getGroup(groupType,  nGroupId);
			strNickName = group.getName();
			strGroupName = group.getName();			
			iImage = group.imageid;
			nKeyword = group.type;
			nAddress = group.enyear;		
			iAddress = group.enyear;
			iPower = group.getPower();
			iIndex = group.index;
		}		
		txt_groupid.setText(""+nGroupId); 
		txt_groupname.setText(strGroupName);	
		//strNickName = strGroupName;		
		txt_nickname.setText(strNickName);		
        if(iImage<0) iImage = -iImage;		
        if(iImage>80) iImage = iImage%80;
        img_photo.setImageResource(ImagesUtils.images[iImage]);	
        
        if(groupType==DefineUser.TYPE_DEPART||groupType==DefineUser.TYPE_CITY)
		    iPower = PowerUtils.getMemberPower(groupType,nGroupId,GloableParams.m_szUserId);       
        iPower = PowerUtils.getMemberPower(groupType,nGroupId,GloableParams.m_szUserId); 
	//	txt_address.setText(AddressUtils.getAddress(iAddress));        
 
        txt_power.setText(PowerUtils.getPowerText(groupType,iPower));         
        txt_index.setText(""+iIndex);
        setGroupInfo();       
	}	

	protected void reSetData() {
		//getRemoteEditTypeInfo();
			
		txt_groupid.setText(""+nGroupId); 
		txt_groupname.setText(strGroupName);	
		//strNickName = strGroupName;		
		txt_nickname.setText(strNickName);		
        if(iImage<0) iImage = -iImage;		
        if(iImage>80) iImage = iImage%80;
        img_photo.setImageResource(ImagesUtils.images[iImage]);	
	//	txt_address.setText(AddressUtils.getAddress(iAddress));        
 
        txt_power.setText(PowerUtils.getPowerText(groupType,iPower));         
        txt_index.setText(""+iIndex);
        if(iPower<1)
        	btn_askapply.setText("申请加入");  
        setGroupInfo();      
	}	
	

	
	protected void setGroupInfo() {

		txt_openlevel.setText(OpenLevelUtils.getOpenLevelText(iLevel));
		switch (groupType) {
		case DefineUser.TYPE_FRIEND:
			txt_type.setText(KeywordUtils.getKeyword(nKeyword));
			txt_enyear.setText(AddressUtils.getAddress(nAddress));	
			break;		
		case DefineUser.TYPE_CROWD:
			txt_type.setText(KeywordUtils.getKeyword(nKeyword));
			txt_enyear.setText(AddressUtils.getAddress(nAddress));			
			break;
		case DefineUser.TYPE_MYCLASS:		
			txt_type.setText(CollegeUtils.getCollege(nKeyword));	
			txt_enyear.setText("" + nAddress);				
			break;
		case DefineUser.TYPE_DEPART:
			txt_type.setText(DepartUtils.getDepartName(nAddress));						
			txt_enyear.setText(DepartUtils.getDepartTypeName(nAddress));			
			break;		
		case DefineUser.TYPE_PARTY:
			txt_type.setText(DepartUtils.getDepartName(nAddress));						
			txt_enyear.setText(DepartUtils.getDepartTypeName(nAddress));	
			break;
		case DefineUser.TYPE_GROUP:
			txt_type.setText(CityUtils.getCityTypeName(nAddress));						
			txt_enyear.setText(CityUtils.getCityName(nAddress));	
			break;
		case DefineUser.TYPE_CITY:
			txt_type.setText(CityUtils.getCityTypeName(nAddress));						
			txt_enyear.setText(CityUtils.getCityName(nAddress));
			break;		
	
		default:
			txt_type.setText(KeywordUtils.getKeyword(nKeyword));
			txt_enyear.setText(AddressUtils.getAddress(nAddress));			
			break;
		}  				
	}	

	protected void setCaption() {
		//加载服务器定制标题字符串
		loadCustomCaption();
		//如果服务器有自定义字符串
		if( arrCaption != null && arrCaption.length > 10 ){
			txt_title.setText(arrCaption[0]);
			if( groupType == DefineUser.TYPE_DEPART && groupType == DefineUser.TYPE_CITY ){			
			    cap_groupid.setText(arrCaption[6]);
			    cap_groupname.setText(arrCaption[7]);
			    cap_type.setText(arrCaption[8]);
			    cap_enyear.setText(arrCaption[9]);
			}else{
			    cap_groupid.setText(arrCaption[5]);
			    cap_groupname.setText(arrCaption[6]);
			    cap_type.setText(arrCaption[7]);
			    cap_enyear.setText(arrCaption[8]);			
			}
			return;	
		}
		//如果服务器没有自定义字符串		
		switch (groupType) {
		case DefineUser.TYPE_FRIEND:
			txt_title.setText("分类");
			cap_groupid.setText("分类ID");
			cap_groupname.setText("分类名称");
			cap_type.setText("关  键  字");
			cap_enyear.setText("兴趣地域");	
			break;		
		case DefineUser.TYPE_CROWD:
			txt_title.setText("群资料");
			cap_groupid.setText("群ID");
			cap_groupname.setText("群名称");
			cap_type.setText("关  键  字");
			cap_enyear.setText("兴趣地域");			
			break;
		case DefineUser.TYPE_MYCLASS:
			txt_title.setText("班资料");
			cap_groupid.setText("班ID");
			cap_groupname.setText("班名称");
			cap_type.setText("所属院系");
			cap_enyear.setText("入学年份");	
			break;
		case DefineUser.TYPE_DEPART:
			txt_title.setText("部门资料");
			cap_groupid.setText("部门ID");
			cap_groupname.setText("部门名称");
			cap_type.setText("所属父项");
			cap_enyear.setText("主管部门");	
			break;		
		case DefineUser.TYPE_PARTY:
			txt_title.setText("会议室资料");
			cap_groupid.setText("会议ID");
			cap_groupname.setText("会议名称");
			cap_type.setText("所属父项");
			cap_enyear.setText("主管部门");	
			break;
		case DefineUser.TYPE_GROUP:
			txt_title.setText("俱乐部资料");
			cap_groupid.setText("输入部ID");
			cap_groupname.setText("输入部名");
			cap_type.setText("所属省份");
			cap_enyear.setText("所在城市");	
			break;
		case DefineUser.TYPE_CITY:
			txt_title.setText("地域资料");
			cap_groupid.setText("地域ID");
			cap_groupname.setText("地域名称");
			cap_type.setText("所属省份");
			cap_enyear.setText("所在城市");	
			break;		
	
		default:
			txt_title.setText("类别资料");
			cap_groupid.setText("分类ID");
			cap_groupname.setText("分类名称");
			cap_type.setText("关  键  字");
			cap_enyear.setText("兴趣地域");				
			break;
		}			
	}	
	//加载服务器定制标题字符串
	protected void loadCustomCaption() {
		//得到对话框的标识字
		int keyword = 0;
		switch (groupType) {
		case DefineUser.TYPE_FRIEND:	
			break;		
		case DefineUser.TYPE_CROWD:
			keyword = CaptionUtils.IDS_CROWD_EDITTYPE;			
			break;
		case DefineUser.TYPE_MYCLASS:
			keyword = CaptionUtils.IDS_CLASS_EDITTYPE;	
			break;
		case DefineUser.TYPE_DEPART:
			keyword = CaptionUtils.IDS_DEPART_EDITTYPE;	
			break;		
		case DefineUser.TYPE_PARTY:
			keyword = CaptionUtils.IDS_PARTY_EDITTYPE;	
			break;
		case DefineUser.TYPE_GROUP:
			keyword = CaptionUtils.IDS_GROUP_EDITTYPE;	
			break;
		case DefineUser.TYPE_CITY:
			keyword = CaptionUtils.IDS_CITY_EDITTYPE;	
			break;			
		default:			
			break;
		}
		//查找有什么对应的定制字符串
		if( keyword > 0 ){
		    sCaption = CaptionUtils.LoadCaption( keyword );
		    if(!TextUtils.isEmpty(sCaption)&&sCaption.length() > 20)
		        arrCaption = CaptionUtils.SplitCaption( sCaption );	
		}
	}
	
	protected void setListener() {
		img_back.setOnClickListener(this);		
		lay_right.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
			}
		});
		btn_satrtchat.setOnClickListener(this);
		btn_editgroup.setOnClickListener(this);
		btn_exitgroup.setOnClickListener(this);		
		btn_askapply.setOnClickListener(this); 		
		btn_setsight.setOnClickListener(this);
		btn_setguard.setOnClickListener(this);	
		btn_listmember.setOnClickListener(this);
		btn_adminmember.setOnClickListener(this);
		btn_toblack.setOnClickListener(this);		
		btn_markgroup.setOnClickListener(this);
		btn_liftgroup.setOnClickListener(this);
		btn_invite.setOnClickListener(this);			
		lay_nickname.setOnClickListener(this); 
		lay_power.setOnClickListener(this);
		lay_index.setOnClickListener(this); 
		//lay_type.setOnClickListener(this); 
		//lay_enyear.setOnClickListener(this); 
		//lay_openlevel.setOnClickListener(this); 		
	}	
	
	@Override
	public void onClick(View arg0) {
		Intent intent1 = new Intent();
		int id = arg0.getId();
		if (id == R.id.img_back) {
			Utils.finish(MytypeInfoActivity.this);
			//finish();
			//finish(MytypeInfoActivity.this);
		} else if (id == R.id.btn_startchat) {
			Intent intent = new Intent(this, EMChatActivity.class);
			intent.putExtra("Chat_ID", nGroupId);
			intent.putExtra("Chat_Type", groupType);
			//intent.putExtra("Chat_Name", strGroupName);
			intent.putExtra("Chat_Name", strNickName);
			//startActivity(intent);
			Utils.start_Activity(this, intent);
		} else if (id == R.id.btn_editgroup) {
			intent1 = new Intent(this, GroupEditActivity.class);
			intent1.putExtra("Info_GroupId", nGroupId);
			intent1.putExtra("Info_GroupType", groupType);
			intent1.putExtra("Info_GroupName", strGroupName);
			intent1.putExtra("Info_Type", nKeyword);
			intent1.putExtra("Info_Enyear", nAddress);
			intent1.putExtra("Info_Image", iImage);
			intent1.putExtra("Info_Open", iLevel);
			//startActivity(intent1);
			Utils.start_Activity(this, intent1);
		} else if (id == R.id.btn_askapply) {
			AskInfo uinfo = new AskInfo(nGroupId, strGroupName, iImage);
			if (iPower < 1) {
				new AskJoinDialog(MytypeInfoActivity.this, uinfo,
						new AskJoinDialog.OnSetListener() {
							@Override
							public void onSelect(AskInfo askInfo) {
								joinGroup(askInfo);
							}
						}).show();
			} else {

				new AskApplyDialog(MytypeInfoActivity.this, uinfo, iPower,
						new AskApplyDialog.OnSetListener() {
							@Override
							public void onSelect(AskInfo askInfo) {
								applyGroup(askInfo);
							}
						}).show();
			}
		} else if (id == R.id.btn_exitgroup) {
			String title = "";
			String message = "";
			switch (groupType) {
				case DefineUser.TYPE_FRIEND:
					break;
				case DefineUser.TYPE_CROWD:
					title = "退出该群？";
					message = "你确定要退出该群吗？";
					break;
				case DefineUser.TYPE_MYCLASS:
					title = "退出该班？";
					message = "你确定要退出该班吗？";
					break;
				case DefineUser.TYPE_DEPART:
					title = "退出该部门？";
					message = "你确定要退出该部门吗？";
					break;
				case DefineUser.TYPE_PARTY:
					title = "退出该会议室？";
					message = "你确定要退出该会议室吗？";
					break;
				case DefineUser.TYPE_GROUP:
					title = "退出该俱乐部？";
					message = "你确定要退出该俱乐部？";
					break;
				case DefineUser.TYPE_CITY:
					title = "退出该地区？";
					message = "你确定要退出该地区吗？";
					break;
				default:

					break;
			}
			new MyAlertDialog(MytypeInfoActivity.this, title, message,
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
							//addFriend(askInfo);
							GroupInfo uinfo = new GroupInfo(nGroupId, strNickName, iImage, iPower, iIndex);
							exitGroup(uinfo);
						}
					}).show();
		} else if (id == R.id.btn_setsight) {
			int admin = 0x2828;
			new SetupSightDialog(MytypeInfoActivity.this, groupType, admin,
					new SetupSightDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							setSight(option);
							// txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_setguard) {
			int admin1 = 0x2828;
			new SetupGuardDialog(MytypeInfoActivity.this, groupType, admin1,
					new SetupGuardDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							setGuard(option);
							// txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_listmember) {
			Intent intent_list = new Intent(this, MemberListActivity.class);
			//Intent intent_list = new Intent(this, AdminMemberListActivity.class);
			intent_list.putExtra("TypeID", nGroupId);
			intent_list.putExtra("TypeType", groupType);
			startActivity(intent_list);
		} else if (id == R.id.btn_adminmember) {//Intent intent_list = new Intent(this, MemberListActivity.class);
			Intent intent_admin = new Intent(this, MemberAdminListActivity.class);
			intent_admin.putExtra("TypeID", nGroupId);
			intent_admin.putExtra("TypeType", groupType);
			startActivity(intent_admin);
		} else if (id == R.id.btn_toblack) {
			new BanGroupDialog(MytypeInfoActivity.this, groupType, nGroupId, strGroupName,
					new BanGroupDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							//addFriend(askInfo);
							txt_power.setText("" + option);
						}
					}).show();
		} else if (id == R.id.btn_markgroup) {
			new MarkGroupDialog(MytypeInfoActivity.this, groupType, nGroupId, strNickName,
					new MarkGroupDialog.OnSetListener() {
						@Override
						public void onSelect(int option) {
							MarkGroup(option);
							// txt_power.setText(""+admin);
						}
					}).show();
		} else if (id == R.id.btn_liftgroup) {
			new MoneyGiveGroupDialog(MytypeInfoActivity.this, groupType, nGroupId, strNickName,
					new MoneyGiveGroupDialog.OnSetListener() {
						@Override
						public void onSelect(int option, int money) {
							//addFriend(askInfo);
							// txt_power.setText(""+money);
							if (option == 0)
								LiftGroup(option);
							else
								GiveDiamond(option, money);
						}
					}).show();
		} else if (id == R.id.btn_invite) {
			Intent intent3 = new Intent(MytypeInfoActivity.this, AddnewMemberActivity.class);
			intent3.putExtra("Chat_ID", nGroupId);
			intent3.putExtra("Chat_Type", groupType);
			intent3.putExtra("Chat_Name", strGroupName);
			startActivity(intent3);
		} else if (id == R.id.rl_user_nickname) {
			GroupInfo uinfo3 = new GroupInfo(nGroupId, strNickName, iImage, iPower, iIndex);
			new EditTypenameDialog(MytypeInfoActivity.this, uinfo3, iIndex,
					new EditTypenameDialog.OnSetListener() {
						@Override
						public void onSelect(GroupInfo uinfo) {
							String strname = uinfo.nickname;
							txt_nickname.setText(strname);
							txt_index.setText("" + uinfo.index);
							editTypename(uinfo);
						}
					}).show();
		} else if (id == R.id.rl_user_power) {
			AskInfo uinfo2 = new AskInfo(nGroupId, strGroupName, iImage);
			new AskApplyDialog(MytypeInfoActivity.this, uinfo2, iPower,
					new AskApplyDialog.OnSetListener() {
						@Override
						public void onSelect(AskInfo askInfo) {
							applyGroup(askInfo);
						}
					}).show();
		} else if (id == R.id.rl_type) {
			//Select_Type();
		} else if (id == R.id.rl_enyear) {//修改城市
			//Select_Enyear();
		}
	} 

	private void getRemoteEditTypeInfo(){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			GroupNode groupNode = UserUtil.readGroupNode( groupType,nGroupId );
			if(groupNode!=null){			
			    strGroupName = groupNode.classname;
			    nKeyword = groupNode.keyword;
			    nAddress = groupNode.address;
   
			    iIndex = groupNode.index;
			    iImage = groupNode.imageid;			
                iLevel = groupNode.openlevel;	
                reSetData();  
			}
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在刷新数据...").show();		
		getClient.GetEditType(groupType,nGroupId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();		
				final GroupEditInfo typeInfo = new GroupEditInfo(recvBuf);				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();							
						strGroupName = typeInfo.groupname;						
						strNickName = typeInfo.nickname;
						//iAddress = userInfo.imageid;
						iImage = typeInfo.imageid;						
						iPower = typeInfo.power;
						iIndex = typeInfo.index;
						nKeyword = typeInfo.type;
						nAddress = typeInfo.enyear;						
						reSetData();						
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在刷新数据...").dismiss();							
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void applyGroup(AskInfo uinfo){
		int nDestid = uinfo.destid;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		AskClient.AskApplyGroup(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(MytypeInfoActivity.this, str);
					
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	public void editTypename(GroupInfo uinfo){
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.EditTypeName(groupType,uinfo); //修改本地数据				
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		EditClient.EditTypeName(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(MytypeInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void exitGroup(GroupInfo uinfo){
		int nDestid = uinfo.groupid;
		if(nDestid == GloableParams.m_szUserId){//判断是否是自己
		}	
		if(FriendUtils.getFriendList(nDestid)>0){//判断是否已经是好友

		}
		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			EditResult.ExitGroup(groupType,uinfo); //修改本地数据				
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		EditClient.exitGroup(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(MytypeInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	public void joinGroup(AskInfo uinfo){
		int nDestid = uinfo.destid;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();		
		AskClient.AskJoinGroup(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(MytypeInfoActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	private void setSight( int sight ){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在修改设置...").show();		
		markClient.setSightOption(groupType,nGroupId,sight,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();		
				//final GroupEditInfo typeInfo = new GroupEditInfo(recvBuf);				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(MytypeInfoActivity.this, "服务器修改成功!");							
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void setGuard( int guard ){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在修改设置...").show();		
		markClient.setGuardOption(groupType,nGroupId,guard,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();		
				//final GroupEditInfo typeInfo = new GroupEditInfo(recvBuf);				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(MytypeInfoActivity.this, "服务器修改成功!");							
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				//getLoadingDialog("正在刷新数据...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改设置...").dismiss();							
						Utils.showLongToast(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void MarkGroup( int option ){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在投票中...").show();		
		markClient.putMarkVote(groupType,nGroupId,option,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				int temp = recvBuf[4];	
				if(temp<0) temp += 0x100;				
				final int count = temp;	
				temp = recvBuf[8];	
				if(temp<0) temp += 0x100;				
				final int max = temp;	
				//if(count<0) count = count+0x100;				
				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(MytypeInfoActivity.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(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void LiftGroup( int option ){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在赠送中...").show();		
		moneyClient.putMoneyLift(groupType,nGroupId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//final int money = (recvBuf[4]+recvBuf[5]*0x100+recvBuf[6]*0x10000)/100;	
				//final int excharge = recvBuf[8]+recvBuf[9]*0x100;	
				final int money = (MoneyUtil.ByteArrayToInt(recvBuf[4],recvBuf[5],recvBuf[6],recvBuf[7])+50)/100;
				final int excharge = (MoneyUtil.ByteArrayToInt(recvBuf[8],recvBuf[9],recvBuf[10],recvBuf[11])+50)/100;				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();
						String str = "成功升级群组。\n自己金钱:"+money+"\n对方级别:"+excharge;										
						Utils.showLongToast(MytypeInfoActivity.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(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	private void GiveDiamond( final int option,int money ){
		int nDestid = nGroupId;
		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)){//判断是否已经登录服务器
			Utils.showLongToast(MytypeInfoActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在赠送中...").show();		
		moneyClient.putMoneyDiamond(groupType,nGroupId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				//getLoadingDialog("正在刷新数据...").dismiss();	
				//final int money = (recvBuf[4]+recvBuf[5]*0x100+recvBuf[6]*0x10000)/100;	
				final String strDiamond = ""+recvBuf[8]+":"+recvBuf[9]+":"+recvBuf[10]+":"+recvBuf[11];	
				final int money = (MoneyUtil.ByteArrayToInt(recvBuf[4],recvBuf[5],recvBuf[6],recvBuf[7])+50)/100;				
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在赠送中...").dismiss();
						String strType = "";
						if( option == 0)
							strType = "绿卡";
						else if( option == 1)
							strType = "蓝盾";
						else if( option == 2)
							strType = "红运";
						else if( option == 3)
							strType = "金钻";						
						String str = "成功赠送"+strType+"。\n自己金钱余额:"+money+"\n对方钻石:"+strDiamond;						
						
						Utils.showLongToast(MytypeInfoActivity.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(MytypeInfoActivity.this, str);
					}
				});	
			}
		});	 
	}
	
	protected void Select_Type() {
		switch (groupType) {
		case DefineUser.TYPE_FRIEND:
			change_keyword();
			break;		
		case DefineUser.TYPE_CROWD:
			change_keyword();		
			break;
		case DefineUser.TYPE_MYCLASS:
			change_grade();					
			break;
		case DefineUser.TYPE_DEPART:
			change_depart();
			break;		
		case DefineUser.TYPE_PARTY:
			change_depart();
			break;
		case DefineUser.TYPE_GROUP:
			change_city();	
			break;
		case DefineUser.TYPE_CITY:
			change_city();
			break;			
		default:
			change_keyword();		
			break;
		}  		
	}	

	protected void Select_Enyear() {
		switch (groupType) {
		case DefineUser.TYPE_FRIEND:
			change_address();
			break;		
		case DefineUser.TYPE_CROWD:
			change_address();		
			break;
		case DefineUser.TYPE_MYCLASS:
			change_grade();					
			break;
		case DefineUser.TYPE_DEPART:
			change_depart();
			break;		
		case DefineUser.TYPE_PARTY:
			change_depart();
			break;
		case DefineUser.TYPE_GROUP:
			change_city();	
			break;
		case DefineUser.TYPE_CITY:
			change_city();
			break;			
		default:
			change_address();		
			break;
		}  		
	}	
	
	public void change_address() {
		new AddressPickerDialog(MytypeInfoActivity.this,
				AddressPickerDialog.THEME_HOLO_LIGHT,nAddress,false,
				new AddressPickerDialog.OnAddressSetListener() {
					@Override
					public void onAddressSelect(int address) {
						nAddress = address;
						txt_enyear.setText(AddressUtils.getAddress(address));						
						String textString = "" + address;
						Utils.showLongToast(MytypeInfoActivity.this, textString);
					}
				}).show();
	}

	public void change_city() {
		new CityPickerDialog(MytypeInfoActivity.this,
				CityPickerDialog.THEME_HOLO_LIGHT,nAddress,false,
				new CityPickerDialog.OnCitySetListener() {
					@Override
					//public void onCitySelect(int province,int city) {					
					public void onCitySelect(int city) {
						nAddress = city;
						txt_type.setText(CityUtils.getCityTypeName(city));						
						txt_enyear.setText(CityUtils.getCityName(city));						
						String textString = "" + city;
						Utils.showLongToast(MytypeInfoActivity.this, textString);
					}
				}).show();
	}	
	
	public void change_depart() {
		new DeptPickerDialog(MytypeInfoActivity.this,
				DeptPickerDialog.THEME_HOLO_LIGHT,nAddress,false,
				new DeptPickerDialog.OnDeptSetListener() {
					@Override
					public void onDeptSelect(int address) {
						nAddress = address;
						txt_type.setText(DepartUtils.getDepartName(address));						
						txt_enyear.setText(DepartUtils.getDepartTypeName(address));						
						String textString = "" + address;
						Utils.showLongToast(MytypeInfoActivity.this, textString);
					}
				}).show();
	}

	public void change_grade() {
		new GradePickerDialog(MytypeInfoActivity.this,
				GradePickerDialog.THEME_HOLO_LIGHT,nKeyword,nAddress,
				new GradePickerDialog.OnGradeSetListener() {
					@Override
					public void onGradeSelect(int minage,int maxage) {
						nKeyword = minage;
						nAddress = maxage;	
						txt_type.setText(CollegeUtils.getCollege(nKeyword));	
						txt_enyear.setText("" + nAddress);							
						String textString = "" + minage+"-" + maxage;
				//		txt_age.setText(""+ageMin+"-"+ageMax);						
						Utils.showLongToast(MytypeInfoActivity.this, textString);
					}
				}).show();
	}	
	
	public void change_keyword() {
		new KeyPickerDialog(MytypeInfoActivity.this,
				KeyPickerDialog.THEME_HOLO_LIGHT,nKeyword,
				new KeyPickerDialog.OnKeySetListener() {
					@Override
					public void onKeySelect(int keyword) {
						String textString = KeywordUtils.getKeyword(keyword);
						nKeyword = keyword;
						txt_type.setText(KeywordUtils.getKeyword(nKeyword));						
						Utils.showLongToast(MytypeInfoActivity.this, textString);
					}
				}).show();
	}	
}