 
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.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lianxin.pubqq.R;
import com.lianxin.panqq.edit.BanGroupDialog;
import com.lianxin.panqq.edit.EditOpenLevelDialog;
import com.lianxin.panqq.edit.MarkGroupDialog;
import com.lianxin.panqq.edit.MoneyGiveGroupDialog;
import com.lianxin.panqq.edit.MyAlertDialog;
//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.GloableParams;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.list.bean.GroupNode;
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.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.ImagePickerDialog;
import com.lianxin.panqq.picker.KeyPickerDialog;
import com.lianxin.panqq.utils.MoneyUtil;
import com.lianxin.panqq.utils.ImagesUtils;
import com.lianxin.panqq.main.EMContactManager;
import com.lianxin.panqq.common.bean.AskInfo;
import com.lianxin.panqq.common.bean.GroupEditInfo;
import com.lianxin.panqq.common.bean.GroupInfo;
import com.lianxin.panqq.common.bean.UserInfo;

// 群组信息界面
public class GroupEditActivity 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 EditText txt_groupname;  //用户名	
	private TextView txt_enyear;   //用户地区
	private TextView txt_type;   //用户职业
	private TextView txt_number;   //用户签名
	private TextView txt_openlevel;  //用户在哪动态
	private TextView cap_type, cap_enyear;	
	private TextView cap_groupid, cap_groupname;
	//private Button btn_joingroup;
	//private Button btn_jubao;
	private Button btn_editgroup;
	private Button btn_deletegroup;	
	private Button btn_toblack;	
	private Button btn_markgroup;
	private Button btn_liftgroup;	
	private Button btn_listmember;	
	private RelativeLayout lay_image;	
	private RelativeLayout lay_groupname;
	private RelativeLayout lay_type;  
	private RelativeLayout lay_enyear;
	private RelativeLayout lay_openlevel;
	
	private int nGroupId = 10100;//用户唯一id
	private String strGroupName = "情已停机";
	private int groupType = DefineUser.TYPE_CROWD;		
	private int nImage = 10;	
	int nKeyword = 2;
	int nAddress = 2;
	int nCollege = 2;
	int nEnyear = 2;
	int nDept = 30;
	int nCity = 2;		
	private int iNumber = 20;
	private int iLevel = 2;
	private String bakGroupName;	
	int bakKeyword = 2;
	int bakAddress = 2;
	private int bakLevel = 2;
	
	public static final int REQUEST_CODE_ADD_TO_CONTACT = 226;
	public static final int REQUEST_CODE_ADD_TO_BLACKLIST = 225;
	
	private LinearLayout lay_right;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_groupedit);
		
		initControl();
		initView();
		initData();
		setListener();	
		
		getRemoteGroupInfo();		
	}

	protected void initControl() {
		txt_title = (TextView) findViewById(R.id.txt_title);
		img_back = (ImageView) findViewById(R.id.img_back);
		img_back.setVisibility(View.VISIBLE);	
		txt_groupid = (TextView)findViewById(R.id.tv_groupid);
		txt_groupname = (EditText)findViewById(R.id.tv_groupname);		
		img_photo = (ImageView)findViewById(R.id.iv_image);
	//	txt_nickname = (TextView)findViewById(R.id.tv_user_nickname);
		txt_type = (TextView)findViewById(R.id.tv_type);
		txt_enyear = (TextView)findViewById(R.id.tv_enyear);
		txt_number = (TextView)findViewById(R.id.tv_number1);
		txt_openlevel = (TextView)findViewById(R.id.tv_openlevel);
		cap_groupid = (TextView) findViewById(R.id.tv_groupid_cap);			
		cap_groupname = (TextView) findViewById(R.id.tv_groupname_cap);
		cap_type = (TextView) findViewById(R.id.tv_type_cap);			
		cap_enyear = (TextView) findViewById(R.id.tv_enyear_cap);
		lay_image = (RelativeLayout) findViewById(R.id.rl_group_pic);		
		lay_groupname = (RelativeLayout) findViewById(R.id.rl_groupname);
		lay_type = (RelativeLayout) findViewById(R.id.rl_type);
		lay_enyear = (RelativeLayout) findViewById(R.id.rl_enyear);
		lay_openlevel = (RelativeLayout) findViewById(R.id.rl_openlevel);		
	//	btn_satrtchat = (Button)findViewById(R.id.btn_startchat);
	//	btn_joingroup = (Button)findViewById(R.id.btn_joingroup);
		btn_editgroup = (Button)findViewById(R.id.btn_editgroup);
		btn_deletegroup = (Button)findViewById(R.id.btn_deletegroup);
		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_listmember = (Button)findViewById(R.id.btn_listmember);		
		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() {

		nGroupId = getIntent().getIntExtra("Info_GroupId", 10010);		
		strGroupName = getIntent().getStringExtra("Info_GroupName");
		groupType = getIntent().getIntExtra("Info_GroupType", 3);		
		nCollege = getIntent().getIntExtra("Info_Type", 20);
		nEnyear = getIntent().getIntExtra("Info_Enyear", 10);
		nKeyword = nCollege;
		nAddress = nEnyear;	
		nDept = nAddress;
		
		nImage = getIntent().getIntExtra("Info_Image", 23);
		iNumber = getIntent().getIntExtra("Info_Number", 10);
		iLevel = getIntent().getIntExtra("Info_Open", 10);	
		bakGroupName = strGroupName;	
		bakKeyword = nCollege;
		bakAddress = nEnyear;
		bakLevel = iLevel;		

        setGroupInfo();       
	}
	
	protected void setGroupInfo() {	
		txt_groupid.setText(""+nGroupId); 
		txt_groupname.setText(strGroupName);	
	//	txt_nickname.setText(strNickName);		
        if(nImage<0) nImage = -nImage;		
        if(nImage>80) nImage = nImage%80;
        img_photo.setImageResource(ImagesUtils.images[nImage]);	
       
        txt_number.setText(""+iNumber);		
		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:	
			nCollege = nKeyword;
			nEnyear = nAddress;	
			txt_type.setText(CollegeUtils.getCollege(nCollege));	
			txt_enyear.setText("" + nEnyear);				
			break;
		case DefineUser.TYPE_DEPART:
			nDept = nAddress;
			txt_type.setText(DepartUtils.getDepartName(nDept));						
			txt_enyear.setText(DepartUtils.getDepartTypeName(nDept));			
			break;		
		case DefineUser.TYPE_PARTY:
			nDept = nAddress;
			txt_type.setText(DepartUtils.getDepartName(nDept));						
			txt_enyear.setText(DepartUtils.getDepartTypeName(nDept));	
			break;
		case DefineUser.TYPE_GROUP:
			nCity = nAddress;
			txt_type.setText(CityUtils.getCityTypeName(nCity));						
			txt_enyear.setText(CityUtils.getCityName(nCity));	
			break;
		case DefineUser.TYPE_CITY:
			nCity = nAddress;
			txt_type.setText(CityUtils.getCityTypeName(nCity));						
			txt_enyear.setText(CityUtils.getCityName(nCity));
			break;		
	
		default:
			txt_type.setText(KeywordUtils.getKeyword(nKeyword));
			txt_enyear.setText(AddressUtils.getAddress(nAddress));			
			break;
		}  				
	}	

	protected void setCaption() {
		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 reSetData() {
		//getRemoteEditTypeInfo();

        setGroupInfo();      
	}	
	
	protected void setListener() {
		img_back.setOnClickListener(this);		
		lay_right.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
		//0314		startActivity(new Intent(Userinfo.this , UserActivity.class).putExtra("userId", userId));
			}
		});
	//	btn_satrtchat.setOnClickListener(this);
	//	btn_joingroup.setOnClickListener(this); 
		btn_editgroup.setOnClickListener(this);
		btn_deletegroup.setOnClickListener(this);	
		btn_toblack.setOnClickListener(this);		
		btn_markgroup.setOnClickListener(this);
		btn_liftgroup.setOnClickListener(this);		
		btn_listmember.setOnClickListener(this);			
		lay_image.setOnClickListener(this);			
		lay_type.setOnClickListener(this); 
		lay_enyear.setOnClickListener(this); 
		lay_openlevel.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(GroupEditActivity.this);
			//finish();
			//finish(GroupInfoActivity.this);
		} else if (id == R.id.btn_editgroup) {
			new MyAlertDialog(GroupEditActivity.this, "修改群组？",
					"你确定要按新数据修改该群组吗？",
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
							GroupInfo uinfo = new GroupInfo(strGroupName, nImage, nKeyword, nAddress);
							uinfo.level = 2;
							uinfo.index = 10;
							uinfo.openlevel = iLevel;
							editGroup(uinfo);
						}
					}).show();
		} else if (id == R.id.btn_deletegroup) {
			new MyAlertDialog(GroupEditActivity.this, "解散群组？",
					"你确定要从列表中解散该群组吗？",
					new MyAlertDialog.OnSetListener() {
						@Override
						public void onSelect(int comm) {
							GroupInfo uinfo = new GroupInfo(strGroupName, nImage, nKeyword, nAddress);
							uinfo.openlevel = iLevel;
							deleteGroup(uinfo);
						}
					}).show();
		} else if (id == R.id.btn_listmember) {
			Intent intent_list = new Intent(this, MemberListActivity.class);
			intent_list.putExtra("TypeID", nGroupId);
			intent_list.putExtra("TypeType", groupType);
			startActivity(intent_list);
		} else if (id == R.id.btn_toblack) {
			new BanGroupDialog(GroupEditActivity.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(GroupEditActivity.this, groupType, nGroupId, strGroupName,
					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(GroupEditActivity.this, groupType, nGroupId, strGroupName,
					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.rl_openlevel) {
			new EditOpenLevelDialog(GroupEditActivity.this, iLevel,
					new EditOpenLevelDialog.OnSetListener() {
						@Override
						public void onSelect(int level) {
							iLevel = level;
							txt_openlevel.setText(OpenLevelUtils.getOpenLevelText(iLevel));
						}
					}).show();
		} else if (id == R.id.rl_type) {
			Select_Type();
		} else if (id == R.id.rl_enyear) {//修改城市
			Select_Enyear();
		} else if (id == R.id.rl_group_pic) {//修改头像
			change_image();
		}
	} 
	
	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(GroupEditActivity.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(GroupEditActivity.this, textString);
					}
				}).show();
	}

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

	public void change_grade() {
		new GradePickerDialog(GroupEditActivity.this,
				GradePickerDialog.THEME_HOLO_LIGHT,nCollege,nEnyear,
				new GradePickerDialog.OnGradeSetListener() {
					@Override
					public void onGradeSelect(int minage,int maxage) {
						nCollege = minage;
						nEnyear = maxage;	
						nKeyword = nCollege;
						nAddress = nEnyear;						
						txt_type.setText(CollegeUtils.getCollege(nCollege));	
						txt_enyear.setText("" + nEnyear);							
						String textString = "" + minage+"-" + maxage;
				//		txt_age.setText(""+ageMin+"-"+ageMax);						
						Utils.showLongToast(GroupEditActivity.this, textString);
					}
				}).show();
	}	
	
	public void change_keyword() {
		new KeyPickerDialog(GroupEditActivity.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(GroupEditActivity.this, textString);
					}
				}).show();
	}
	public void change_image(){
		 
		new ImagePickerDialog(this,
				ImagePickerDialog.THEME_HOLO_LIGHT,
				new ImagePickerDialog.OnImageSetListener() {
					@Override
					public void onImageSelect(int imageid) {
						nImage = imageid;
					//	img_user.setImageResource(ImagesUtils.images[imageid]);
				        img_photo.setImageResource(ImagesUtils.images[nImage]);						
					}
				}).show();	
	}

	private void getRemoteGroupInfo(){
		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 = GroupFileUtil.readGroupNode( groupType,nGroupId );
			GroupNode groupNode = UserUtil.readGroupNode( groupType,nGroupId );			
			if(groupNode!=null){		
			    strGroupName = groupNode.classname;
			    nKeyword = groupNode.keyword;
			    nAddress = groupNode.address;
			    nImage = groupNode.imageid;			
                iLevel = groupNode.openlevel;	
                reSetData();
			}
			Utils.showLongToast(GroupEditActivity.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;
						nImage = typeInfo.imageid;						
						//iPower = typeInfo.power;
						//iIndex = typeInfo.index;
						iLevel = typeInfo.openlevel;
						iNumber = typeInfo.number;					
						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(GroupEditActivity.this, str);
					}
				});	
			}
		});	 
	}	
	
	public void editGroup(GroupInfo uinfo){

		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(GroupEditActivity.this, "你还没有登录服务器!");
			return;
		}	
		if(GroupManger.getMyAdminPower( )>0){//判断自己是否是系统管理员
		
		}else if(GroupManger.getMemberPower( groupType, GloableParams.m_szUserId, nGroupId )<=2){//判断自己是否是系统管理员
			Utils.showLongToast(GroupEditActivity.this, "你不是系统管理员也不是群组管理员，\n无权修改!");
			return;			
		}
		if(!strGroupName.equals(bakGroupName)){			
		}else if(bakKeyword != nCollege||bakAddress != nEnyear||bakLevel != iLevel){
		}else{
			Utils.showLongToast(GroupEditActivity.this, "你还没有对数据作有效修改!");
			return;
		}		
		getLoadingDialog("正在发送请求...").show();	
		boolean isStart =
		EditClient.editGroup(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(GroupEditActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(GroupEditActivity.this, str);
					}
				});	
			}
		});	
		if(!isStart){//没有投递成功
			getLoadingDialog("正在发送请求...").dismiss();			
			Utils.showLongToast(GroupEditActivity.this, "系统忙，稍后再试!");
			return;			
		}		
	}	

	public void deleteGroup(GroupInfo uinfo){

		if(TextUtils.isEmpty(GloableParams.m_szServerIp)){//判断是否已经登录服务器
			Utils.showLongToast(GroupEditActivity.this, "你还没有登录服务器!");
			return;
		}	
		if(GroupManger.getMyAdminPower( )<=0){//判断自己是否是系统管理员
			Utils.showLongToast(GroupEditActivity.this, "你不是系统管理员，无权修改!");
			return;			
		}		
		getLoadingDialog("正在发送请求...").show();	
		boolean isStart =
		EditClient.deleteGroup(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(GroupEditActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(GroupEditActivity.this, str);
					}
				});	
			}
		});	
		if(!isStart){//没有投递成功
			getLoadingDialog("正在发送请求...").dismiss();			
			Utils.showLongToast(GroupEditActivity.this, "系统忙，稍后再试!");
			return;			
		}		
	}	
	
	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(GroupEditActivity.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(GroupEditActivity.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(GroupEditActivity.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(GroupEditActivity.this, "你还没有登录服务器!");
			return;
		}		
		getLoadingDialog("正在赠送中...").show();		
		moneyClient.putMoneyLift(groupType,nGroupId,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {
				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(GroupEditActivity.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(GroupEditActivity.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(GroupEditActivity.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(GroupEditActivity.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(GroupEditActivity.this, str);
					}
				});	
			}
		});	 
	}	
	/**
	 * onActivityResult
	 */
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) { // 清空消息
			if (requestCode == REQUEST_CODE_ADD_TO_CONTACT) { // 加好友
				//EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1)); 
				String sendstr = data.getStringExtra("edittext");
	
			}else if(requestCode == REQUEST_CODE_ADD_TO_BLACKLIST){
				//EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
	//			addUserToBlacklist(userId);
			}
		}
	}

	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(GroupEditActivity.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(GroupEditActivity.this, str);
					}
				});				
			}
			@Override
			public void onFailure(int statusCode,  String message) {
				getLoadingDialog("正在发送请求...").dismiss();
				final String str = message;
				runOnUiThread(new Runnable() {
					public void run() {
						Utils.showLongToast(GroupEditActivity.this, str);
					}
				});	
			}
		});	 
	}		
	/**
	 * 返回
	 * 
	 * @param view
	 */
	public void back(View view) {
		//finish();
		Utils.finish(GroupEditActivity.this);		
	}
	

}
