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

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import cilico.tools.barcode.PhoneScanner;
import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.common.config.HandsetOperation;
import cn.net.caoyao.cpzshandset.common.util.StringUtils;
import cn.net.caoyao.cpzshandset.service.presenter.CheckLabelStatusConstact;
import cn.net.caoyao.cpzshandset.service.presenter.CheckLabelStatusConstact.Presenter;
import cn.net.caoyao.cpzshandset.service.presenter.impl.checkLabelStatus.medicineXY.MedicineXYCheckLabelStatusPresenter;
import cn.net.caoyao.cpzshandset.service.presenter.impl.labelCheck.bottle.JinLineBottleCheckLabelPresenter;
import cn.net.caoyao.cpzshandset.service.presenter.impl.labelCheck.box.JinLineBoxCheckLabelPresenter;
import cn.net.caoyao.cpzshandset.service.presenter.impl.labelCheck.giftbox.JinLineGiftBoxCheckLabelPresenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseScanActivity;
import cn.net.caoyao.cpzshandset.ui.weight.MyToast;

public class CheckLabelStatusActivity extends BaseScanActivity implements CheckLabelStatusConstact.View, OnClickListener{
	private CheckLabelStatusConstact.Presenter presenter;
	private TextView tv_title_common;
	private Button btn_title_more_option;
//	private EditText et_check_label,et_check_code;
	private Context context;
	private ListView lv_check_result;
	private MyToast myToast;

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (myToast != null) {
			myToast.cancel();
		}
	}
	@Override
	protected Handler initHandler() {
		return presenter == null ? null : presenter.getHandler();
	}

	@Override
	public int loadView() {
		context = this;
		myToast = new MyToast(context);
		return R.layout.activity_check_label_status_template;
	}

	@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);
		
	}

	@Override
	public void initView() {
//		et_check_label = (EditText) findViewById(R.id.et_check_label);
//		View btn_check_label_scanner = findViewById(R.id.btn_check_label_scanner);
//		btn_check_label_scanner.setOnClickListener(this);
//		et_check_code = (EditText) findViewById(R.id.et_check_code);
//		View btn_check_label_status = findViewById(R.id.btn_check_label_status);
//		btn_check_label_status.setOnClickListener(this);
		lv_check_result = (ListView) findViewById(R.id.lv_check_result);
		
	}

	@Override
	public void initPresenter() {
		HandsetOperation option_type = (HandsetOperation) getIntent().getSerializableExtra("option_type");
		switch (option_type) {
		case OPERATION_CHECK_LABEL_STATUS_CONSTANT:
			presenter = new MedicineXYCheckLabelStatusPresenter(this, context);
			break;

		case OPERATION_CHECK_BOTTLE_GIFTBOX_CONSTANT:
			//瓶盒校验
			presenter = new JinLineBottleCheckLabelPresenter(this, context);
			break;
		case OPERATION_CHECK_GIFTBOX_BOX_CONSTANT:
			//盒箱校验
			presenter = new JinLineGiftBoxCheckLabelPresenter(this, context);
			break;
		case OPERATION_CHECK_BOX_TRAY_CONSTANT:
			//箱拖校验
			presenter = new JinLineBoxCheckLabelPresenter(this, context);
			break;
		}
		
		
	}

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

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

	@Override
	public void setPresenter(Presenter presenter) {
		if (presenter != null) {
			this.presenter = presenter;
		}
		
	}

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

	@Override
	public void showMsgToast(String msg, int duration) {
		if (myToast == null || StringUtils.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 readQRCode() {
		PhoneScanner.Read(createService, cacheG, context);
		
	}

	@Override
	public void vibrate(int duration) {
		super.vibrateReadQRComplete(duration);
		
	}

//	@Override
//	public void addLabelTextChangedListener(TextWatcher t) {
//		if(et_check_label == null || t == null) return;
//		et_check_label.addTextChangedListener(t);
//		
//	}
//
//	@Override
//	public void removeLabelTextChangedListener(TextWatcher t) {
//		if(et_check_label == null || t == null) return;
//		et_check_label.removeTextChangedListener(t);
//		
//	}
//
//	@Override
//	public void addCheckCodeTextChangedListener(TextWatcher t) {
//		if(et_check_code == null || t == null) return;
//		et_check_code.addTextChangedListener(t);
//		
//	}
//
//	@Override
//	public void removeCheckCodeTextChangedListener(TextWatcher t) {
//		if(et_check_code == null || t == null ) return;
//		et_check_code.removeTextChangedListener(t);
//		
//	}
//
//	@Override
//	public void setLabelStr(String labelStr) {
//		if(et_check_label == null || labelStr == null) return;
//		et_check_label.setText(labelStr+"");
//		
//	}
//
//	@Override
//	public String getLabelStr() {
//		return et_check_label == null ? "" : et_check_label.getText().toString().trim();
//	}
//
//	@Override
//	public void setCheckCodeStr(String checkCodeStr) {
//		if(et_check_code == null || checkCodeStr == null) return;
//		et_check_code.setText(checkCodeStr+"");
//		
//	}
//
//	@Override
//	public String getCheckCodeStr() {
//		return et_check_code == null ? "":et_check_code.getText().toString().trim();
//	}

	
	@Override
	public void setResultAdapter(BaseAdapter adapter) {
		if(lv_check_result == null || adapter == null) return;
		lv_check_result.setAdapter(adapter);
		
	}
	@Override
	public void setMoreOptionVisibility(int visibility) {
		if(btn_title_more_option == null) return;
		btn_title_more_option.setVisibility(visibility);
		
	}

	@Override
	public void setMoreOptionStr(String moreOptionStr) {
		if(btn_title_more_option == null || moreOptionStr == null) return;
		btn_title_more_option.setText(moreOptionStr);
		
	}
	
	@Override
	public void addHeaderView(View headerView) {
		if (lv_check_result == null || headerView == null ) return;
		lv_check_result.addHeaderView(headerView);
	}

	@Override
	public void onBackPressed() {
//		super.onBackPressed();
		if (presenter != null) {
			presenter.onBackPressed();
		}
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.image_title_back_common:
//			finish();
			if(presenter == null) return;
			presenter.backClick();
			break;
//		case R.id.btn_check_label_scanner:
//			if(presenter == null) return;
//			presenter.btnScannerClick();
//			break;
//		case R.id.btn_check_label_status:
//			if(presenter == null) return;
//			presenter.btnCheckClick();
//			break;

		}
		
	}
	


}
