package cn.net.caoyao.cpzshandset.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.service.presenter.ExchangeCargoConfigConstact;
import cn.net.caoyao.cpzshandset.service.presenter.ExchangeCargoConfigConstact.Presenter;
import cn.net.caoyao.cpzshandset.service.presenter.impl.exchange.sheepEx.SheepExCargoConfigPresenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseActivity;
import cn.net.caoyao.cpzshandset.ui.weight.AllCapTransformationMethod;
import cn.net.caoyao.cpzshandset.ui.weight.MyToast;
import cn.net.cpzslibs.prot.utils.StrUtils;

public class ExchangeCargoConfigActivity extends BaseActivity implements ExchangeCargoConfigConstact.View, OnClickListener{
	private ExchangeCargoConfigConstact.Presenter presenter;
	private TextView tv_title_common,tv_from_dealer_name,tv_to_dealer_name;
	private Button btn_title_more_option;
	private View btn_exchange_cargo_config_single,btn_exchange_cargo_config_batch;
	private EditText et_from_dealer_code,et_to_dealer_code,et_exchange_cargo_count;
	private MyToast myToast;
	private Context context;
	@Override
	public int loadView() {
		context = this;
		myToast = new MyToast(context);
		return R.layout.activity_exchange_cargo_config_template;
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		if(presenter != null) presenter.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (myToast != null) {
			myToast.cancel();
		}
	}
	@Override
	public void initTitleView() {
		View image_title_back_common = findViewById(R.id.image_title_back_common);
		image_title_back_common.setVisibility(View.VISIBLE);
		image_title_back_common.setOnClickListener(this);
		tv_title_common = (TextView) findViewById(R.id.tv_title_common);
		btn_title_more_option = (Button) findViewById(R.id.btn_title_more_option);
		btn_title_more_option.setOnClickListener(this);		
	}

	@Override
	public void initView() {
		btn_exchange_cargo_config_single = findViewById(R.id.btn_exchange_cargo_config_single);
		btn_exchange_cargo_config_batch = findViewById(R.id.btn_exchange_cargo_config_batch);
		et_from_dealer_code = (EditText) findViewById(R.id.et_from_dealer_code);
		et_from_dealer_code.setTransformationMethod(new AllCapTransformationMethod());
		tv_from_dealer_name = (TextView) findViewById(R.id.tv_from_dealer_name);
		et_to_dealer_code = (EditText) findViewById(R.id.et_to_dealer_code);
		et_to_dealer_code.setTransformationMethod(new AllCapTransformationMethod());
		tv_to_dealer_name = (TextView) findViewById(R.id.tv_to_dealer_name);
		et_exchange_cargo_count = (EditText) findViewById(R.id.et_exchange_cargo_count);
	}

	@Override
	public void initPresenter() {
		presenter = new SheepExCargoConfigPresenter(context, this, getIntent());
	}

	@Override
	public void setListener() {
		btn_exchange_cargo_config_single.setOnClickListener(this);
		btn_exchange_cargo_config_batch.setOnClickListener(this);
	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setPresenter(Presenter presenter) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void startAcForResult(int reqCode, Intent intent) {
		startActivityForResult(intent, reqCode);
	}

	@Override
	public void showMsgToast(String msg, int duration) {
		if(myToast == null || StrUtils.isEmpty(msg)) return;
		myToast.show(msg, duration);
	}

	@Override
	public void setPageTitle(String homeTitle) {
		if(tv_title_common == null || homeTitle == null) return;
		tv_title_common.setText(homeTitle+"");
	}

	@Override
	public void finishPage() {
		finish();
	}

	@Override
	public void setFromDealerCode(String fromDealerCode) {
		if(et_from_dealer_code == null || fromDealerCode == null) return;
		et_from_dealer_code.setText(fromDealerCode+"");
	}

	@Override
	public String getFromDealerCode() {
		return et_from_dealer_code == null ? "" :et_from_dealer_code.getText().toString().trim();
	}

	@Override
	public void addFromDealerTextChangedListener(TextWatcher t) {
		if(et_from_dealer_code == null || t == null) return;
		et_from_dealer_code.addTextChangedListener(t);
	}

	@Override
	public void removeFromDealerTextChangedListener(TextWatcher t) {
		if(et_from_dealer_code == null || t == null) return;
		et_from_dealer_code.removeTextChangedListener(t);	
	}

	@Override
	public void setFromDealerName(String dealerName) {
		if(tv_from_dealer_name == null || dealerName == null) return;
		tv_from_dealer_name.setText(dealerName +"");
	}

	@Override
	public void setToDealerCode(String toDealerCode) {
		if(et_to_dealer_code == null || toDealerCode == null) return;
		et_to_dealer_code.setText(toDealerCode+"");
	}

	@Override
	public String getToDealerCode() {
		return et_to_dealer_code == null ? "":et_to_dealer_code.getText().toString().trim();
	}

	@Override
	public void addToDealerTextChangedListener(TextWatcher t) {
		if(et_to_dealer_code == null || t == null) return;
		et_to_dealer_code.addTextChangedListener(t);
	}

	@Override
	public void removeToDealerTextChangedListener(TextWatcher t) {
		if(et_to_dealer_code == null || t == null) return;
		et_to_dealer_code.removeTextChangedListener(t);	
	}

	@Override
	public void setToDealerName(String dealerName) {
		if(tv_to_dealer_name == null || dealerName == null) return;
		tv_to_dealer_name.setText(dealerName+"");
	}

	@Override
	public void settCargoCount(String count) {
		if(et_exchange_cargo_count == null || count == null) return;
		et_exchange_cargo_count.setText(count+"");
	}

	@Override
	public String getCargoCount() {
		return et_exchange_cargo_count == null ? "" : et_exchange_cargo_count.getText().toString().trim();
	}


	@Override
	public void setSingleBtnVisiable(int visibility) {
		if(btn_exchange_cargo_config_single == null) return;
		btn_exchange_cargo_config_single.setVisibility(visibility);		
	}

	@Override
	public void setBatchBtnVisiable(int visibility) {
		if(btn_exchange_cargo_config_batch == null) return;
		btn_exchange_cargo_config_batch.setVisibility(visibility);
	}

	@Override
	public void setMoreOptionBtnVisiable(int visibility) {
		if(btn_title_more_option == null) return;
		btn_title_more_option.setVisibility(visibility);
	}

	@Override
	public void setMoreOptionBtnStr(String moreStr) {
		if(btn_title_more_option == null || moreStr == null) return;
		btn_title_more_option.setText(moreStr);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_more_option:
			if (presenter != null) {
				presenter.moreOptionClick();
			}
			break;
		case R.id.image_title_back_common:
			// 返回按钮
			if (presenter != null) {
				presenter.backClick();
			}
			break;
		case R.id.btn_exchange_cargo_config_batch:
			//批量激活
			if (presenter != null) {
				presenter.batchClick();
			}
			break;
		case R.id.btn_exchange_cargo_config_single:
			//单标激活
			if (presenter != null) {
				presenter.singleClick();
			}
			break;
		}
	}

}
