package com.lianxin.pubqq.setup;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.lianxin.pubqq.R;
import com.lianxin.pubqq.main.MyApp;
import com.lianxin.panqq.common.BaseActivity;
import com.lianxin.panqq.common.DefineUser;
import com.lianxin.panqq.common.GloableParams;
import com.lianxin.panqq.common.Utils;
import com.lianxin.panqq.client.callback.getCallBack;
import com.lianxin.panqq.client.setInfoClient;

//联系方式
public class SetupContactActivity extends BaseActivity implements OnClickListener {
	private ImageView img_back;
	private Button btn_modify, btn_logout,btn_exit, btn_regoff;
	private RelativeLayout lay_address;	
	private EditText txt_tele, txt_phone, txt_address, txt_homepage;	
	private EditText txt_qq, txt_weim, txt_pay, txt_info;	
	private String strTele = "";
	private String strPhone = "";	
	private String strAddress = "";	
	private String strHomePage;  //个人主页
	private String strQQ = "";
	private String strWeim = "";
	private String strPay = "";
	private String strInfo = "";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.setup_contact);
		super.onCreate(savedInstanceState);
		
		initControl();
		initData();		
		initView();

		setListener();		
	}

	protected void initControl() {
		img_back = (ImageView) findViewById(R.id.img_back);		
		btn_modify = (Button) findViewById(R.id.btn_modify);
		btn_logout = (Button) findViewById(R.id.btn_logout);
		btn_exit = (Button) findViewById(R.id.btn_exit);
		btn_regoff = (Button) findViewById(R.id.btn_regoff);
		txt_tele = (EditText) findViewById(R.id.tv_user_tele);		
		txt_phone = (EditText) findViewById(R.id.tv_user_phone);
		txt_homepage = (EditText) findViewById(R.id.tv_user_homepage);		
	//	img_user = (ImageView)findViewById(R.id.iv_user_image); 		
		txt_qq = (EditText) findViewById(R.id.tv_user_qq);
		txt_weim = (EditText) findViewById(R.id.tv_user_weim);
		txt_address = (EditText) findViewById(R.id.tv_user_address);		
//		lay_image = (RelativeLayout) findViewById(R.id.rl_user_image);
		lay_address = (RelativeLayout) findViewById(R.id.rl_user_address);		
		txt_pay = (EditText) findViewById(R.id.tv_user_pay);
		txt_info = (EditText) findViewById(R.id.tv_user_info);		

	}

	protected void initView() {
		txt_tele.setText(strTele);
		txt_phone.setText(strPhone);
		txt_homepage.setText(strHomePage);	
		txt_address.setText(strAddress);
		txt_info.setText(strInfo);			
	}

	protected void initData() {
		strTele = GloableParams.myUserInfo.m_strTele;
		strPhone = GloableParams.myUserInfo.m_strPhone;	
		//strAddress = GloableParams.myUserInfo.m_strAddress;
		strAddress = GloableParams.myUserInfo.m_strEmploy;			
		strHomePage = GloableParams.myUserInfo.m_strHomePage;	
		strInfo = GloableParams.myUserInfo.m_strIntro;		
	}

	protected void setListener() {
		img_back.setOnClickListener(this);
		btn_modify.setOnClickListener(this);
		btn_logout.setOnClickListener(this);
		btn_exit.setOnClickListener(this);
		btn_regoff.setOnClickListener(this);		

	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		if (id == R.id.img_back) {
			Utils.finish(SetupContactActivity.this);
			//	finish(RegisterActivity.this);
			//    super.onBackPressed();
			//finish();
			//overridePendingTransition(R.anim.push_right_in,
			//		R.anim.push_right_out);
		} else if (id == R.id.btn_modify) {
			sendModify();
		} else if (id == R.id.btn_logout) {//MyApp.getInstance().logout();
			MyApp.getInstance().userLogOffline(0);
			//Intent intent1 = new Intent(this, SetupLogoffActivity.class);
			//startActivity(intent1);
		} else if (id == R.id.btn_exit) {
			Utils.finish(SetupContactActivity.this);
			MyApp.getInstance().exit();
		} else if (id == R.id.btn_regoff) {//MyApp.getInstance().exit();
			Intent intent2 = new Intent(this, SetupRegoutActivity.class);
			startActivity(intent2);
		}
	}
    
	/*修改扩展资料*/
	private void sendModify() {
		strTele = txt_tele.getText().toString().trim();
		strPhone = txt_phone.getText().toString().trim();
		strQQ = txt_qq.getText().toString().trim();
		strWeim = txt_weim.getText().toString().trim();	
		strPay = txt_pay.getText().toString().trim();	
		strAddress = txt_address.getText().toString().trim();
		strHomePage = txt_homepage.getText().toString().trim();
		
		strInfo = txt_info.getText().toString().trim();		
		//电话,手机,,,,单位,个人主页,个人说明
		String info = ""+strTele+","+strPhone+","+strQQ+","+strWeim+","+strPay+","+strAddress+","+strHomePage+","+strInfo;
		getLoadingDialog("正在修改个人信息...").show();	
		setInfoClient.SetExtendInfo(DefineUser.REGT_MODIFY_CONTACT,info,new getCallBack(){	
			@Override
			public void onSuccess(int statusCode, byte[] recvBuf) {	
				//UserDetailInfo userExInfo = new UserDetailInfo(recvBuf);					
				runOnUiThread(new Runnable() {
					public void run() {
						getLoadingDialog("正在修改个人信息...").dismiss();						
						Utils.showLongToast(SetupContactActivity.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(SetupContactActivity.this, str);
					}
				});	
			}
		});	 
	}

}
