package cn.net.caoyao.cpzshandset.service.presenter.impl.home.chinatex;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;

import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.common.config.HandsetOperation;
import cn.net.caoyao.cpzshandset.service.presenter.HomeConstact;
import cn.net.caoyao.cpzshandset.service.presenter.HomeConstact.View;
import cn.net.caoyao.cpzshandset.service.presenter.base.impl.HomeConstactImpl;
import cn.net.caoyao.cpzshandset.ui.activity.JianCeActivity;
import cn.net.caoyao.cpzshandset.ui.activity.OptionHistoryListStyleActivity;
import cn.net.caoyao.cpzshandset.ui.activity.QueryActivity;
import cn.net.caoyao.cpzshandset.ui.activity.SettingActivity;
import cn.net.caoyao.cpzshandset.ui.adapter.HomeAdapter;

/**
 * @author 作者 李扬:
 * @date 创建时间：2017-4-20 下午3:08:08
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class ChinatexHomePresenter extends HomeConstactImpl{
	private HomeConstact.View homeView;
	private Context context;
	private List<HandsetOperation> homeBeans = new ArrayList<HandsetOperation>();

	public ChinatexHomePresenter(Context context ,View homeView) {
		this.homeView = homeView;
		this.context = context;
		start();
	}

	@Override
	public void start() {
		initHomeBeans();
		if (!checkViewAvailable()) return;
		//清除七天前的提交记录数据
		clearStatusData();
		homeView.setAdapter(new HomeAdapter(homeBeans));
		homeView.setHomeTitle(context.getResources().getString(R.string.home_chinatex_title_str));

	}
	private void clearStatusData() {
		/*UploadStatusBll uploadStatusBll = new UploadStatusBll(context);
		uploadStatusBll.delete7DaysBefore();*/
	}
	private void initHomeBeans() {
		homeBeans.add(HandsetOperation.OPERATION_BACK_WAREHOUSE_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_OUT_WAREHOUSE_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_QUERY_CONSTANT);
		//homeBeans.add(HandsetOperation.OPERATION_UPLOAD_STATUS_CONSTANT); 提交状态
		homeBeans.add(HandsetOperation.OPERATION_INSPECT_CONSTANT);
		homeBeans.add(HandsetOperation.OPERATION_SETTING_CONSTANT);
		
//		
	}
	@Override
	public boolean checkViewAvailable() {
		boolean b = false;
        if (homeView != null && context != null) {
            b = true;
        }
        return b;
	}

	

	@Override
	public void onItemClickListener(int position) {
		if (!checkViewAvailable() || homeBeans == null || homeBeans.size() < position)return;
		switchCurrentOption(homeBeans.get(position));

	}
	private void switchCurrentOption(HandsetOperation homeBean) {
	
		switch (homeBean) {
		case OPERATION_SETTING_CONSTANT:
			//设置  
			if (!checkViewAvailable()) return;
			Intent settingIntent = new Intent(context,SettingActivity.class);
			context.startActivity(settingIntent);
			break;
		case OPERATION_INSPECT_CONSTANT:
			//检测
			if (!checkViewAvailable()) return;
			Intent intent = new Intent(context, JianCeActivity.class);
			context.startActivity(intent);
			break;
		case OPERATION_QUERY_CONSTANT:
			//查询
			if (!checkViewAvailable()) return;
			Intent queryIntent = new Intent(context, QueryActivity.class);
			context.startActivity(queryIntent);
			break;
		default:
			switchPage(homeBean);
			break;
		}
		
	}
	private void switchPage(HandsetOperation homeBean) {
		Intent activateIntent = new Intent(context, OptionHistoryListStyleActivity.class);
		activateIntent.putExtra("optionMode", homeBean);
		context.startActivity(activateIntent);		
	}
}
