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

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.service.presenter.UploadStatusConstact;
import cn.net.caoyao.cpzshandset.service.presenter.UploadStatusConstact.Presenter;
import cn.net.caoyao.cpzshandset.ui.activity.base.BaseActivity;

@SuppressLint("SimpleDateFormat")
public class UploadStatusActivity extends BaseActivity implements OnClickListener,UploadStatusConstact.View {

//	private UploadStatusBll bll;
	private ListView lv_upload_status;
	private TextView tv_title_common;
	private UploadStatusConstact.Presenter presenter;
	private ViewGroup lin_upload_status_custom_display;
	
	
	@Override
	public int loadView() {
	//	bll = new UploadStatusBll(this);
		return R.layout.activity_upload_status;
	}

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

	}

	@Override
	public void initView() {
		lv_upload_status = (ListView) findViewById(R.id.lv_upload_status);
		lin_upload_status_custom_display = (ViewGroup) findViewById(R.id.lin_upload_status_custom_display);
		
		//lv_upload_status.setOnItemClickListener(this);
//		View btn_add_data = findViewById(R.id.btn_add_data);
//		View btn_query_all = findViewById(R.id.btn_query_all);
//		View btn_query_for_7_days = findViewById(R.id.btn_query_for_7_days);
//		View btn_del_before_7_days = findViewById(R.id.btn_del_before_7_days);
//		View btn_del_all_info = findViewById(R.id.btn_del_all_info);
//		View btn_query_date_for_7_days = findViewById(R.id.btn_query_date_for_7_days);
//		
//		btn_add_data.setOnClickListener(this);
//		btn_query_all.setOnClickListener(this);
//		btn_query_for_7_days.setOnClickListener(this);
//		btn_del_before_7_days.setOnClickListener(this);
//		btn_del_all_info.setOnClickListener(this);
//		btn_query_date_for_7_days.setOnClickListener(this);
	}

	@Override
	public void initPresenter() {
		presenter = createService.createUploadStatusPresenter(cacheG, this, this, getIntent());

	}

	@Override
	public void setListener() {
		
	}

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

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.image_title_back_common:
			//返回
			finish();
			break;
//		case R.id.btn_add_data:
//			LogUtil.i(TConfig.Echo, "插入数据");
//			addTestData();
//			LogUtil.i(TConfig.Echo, "插入数据成功");
//			break;
//		case R.id.btn_query_all:
//			LogUtil.i(TConfig.Echo, "查询所有数据");
//			List<UploadBean> l = bll.queryAllUploadStatus(null);
//			if (l != null) {
//				LogUtil.d(TConfig.Echo, l.size() + "  查询数据:" + l.toString());
//			} else {
//				LogUtil.d(TConfig.Echo, "查询所有结果为空") ;
//			}
//			break;
//		case R.id.btn_query_for_7_days:
//			LogUtil.i(TConfig.Echo, "查询七天数据");
//			List<UploadBean> l1 = bll.queryUploadStatusFor7Days();
//			if (l1 != null) {
//				LogUtil.d(TConfig.Echo, l1.size() + "  查询数据:" + l1.toString());
//			} else {
//				LogUtil.d(TConfig.Echo, "查询所有结果为空") ;
//			}
//			break;
//		case R.id.btn_del_before_7_days:
//			LogUtil.i(TConfig.Echo, "删除七天数据");
//			bll.delete7DaysBefore();
//			LogUtil.i(TConfig.Echo, "删除七天数据  完成");
//			break;
//		case R.id.btn_del_all_info:
//			LogUtil.i(TConfig.Echo, "删除所有数据");
//			bll.deleteAllUploadStatus();
//			LogUtil.i(TConfig.Echo, "删除所有数据  完成");
//			break;
//		case R.id.btn_query_date_for_7_days:
//			LogUtil.i(TConfig.Echo, "查询七天的日期信息");
//			queryDateInfoFor7Days();
//			LogUtil.i(TConfig.Echo, "查询七天的日期信息 成功");
//			break;
		}
		
	}

//	private void queryDateInfoFor7Days() {
//		List<String> dates = bll.queryUploadDateFor7Days();
//		if (dates == null) {
//			LogUtil.e(TConfig.Echo, "查到的信息为空");
//		} else {
//			LogUtil.d(TConfig.Echo, "时间信息:" + dates.toString());
//			for (String str : dates) {
//				LogUtil.e(TConfig.Echo,"date:" +str);
//				LogUtil.d(TConfig.Echo, "激活：" + bll.queryLabelCountByOptionAndDate(HandsetOperation.OPERATION_ACTIVATE_CONSTANT.getOption(), str));
//				LogUtil.d(TConfig.Echo, "打包：" + bll.queryLabelCountByOptionAndDate(HandsetOperation.OPERATION_PACK_CONSTANT.getOption(), str));
//				LogUtil.d(TConfig.Echo, "拆包：" + bll.queryLabelCountByOptionAndDate(HandsetOperation.OPERATION_UNPACK_CONSTANT.getOption(), str));
//				LogUtil.d(TConfig.Echo, "出库：" + bll.queryLabelCountByOptionAndDate(HandsetOperation.OPERATION_OUT_WAREHOUSE_CONSTANT.getOption(), str));
//			}
//		}
//		
//	}

//	private void addTestData() {
//		Date d = new Date();
//		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//		for (int i = 0; i < 20; i++) {
//			String date = df.format(d.getTime() - i * 24 * 60 * 60 * 1000);
//			UploadBean b = new UploadBean();
//			b.setLabel_count(20);
//			b.setOption_type(HandsetOperation.OPERATION_ACTIVATE_CONSTANT.getOption());
//			b.setStatus(0);
//			b.setUpload_date(date);
//			bll.insertUploadStatus(b);
//		}
//		
//	}

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

	@Override
	public void startAcForResult(int reqCode, Intent intent) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showMsgToast(String msg, int duration) {
		
	}

	@Override
	public void setAdapter(BaseAdapter adapter) {
		if (lv_upload_status != null && adapter != null) {
			lv_upload_status.setAdapter(adapter);
		}
	}

	@Override
	public void setPageTitle(String pageTitleStr) {
		if (tv_title_common != null && pageTitleStr != null) {
			tv_title_common.setText(pageTitleStr+"");
		}
		
	}

	@Override
	public void addCustomView(View v) {
		if(lin_upload_status_custom_display == null || v == null) return;
		lin_upload_status_custom_display.removeAllViews();
		lin_upload_status_custom_display.addView(v);
		
	}

}
