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

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.base.impl.HomeConstactImpl;
import cn.net.caoyao.cpzshandset.ui.activity.CheckLabelStatusActivity;
import cn.net.caoyao.cpzshandset.ui.activity.JianCeActivity;
import cn.net.caoyao.cpzshandset.ui.activity.OptionHistoryListStyleActivity;
import cn.net.caoyao.cpzshandset.ui.activity.SettingActivity;
import cn.net.caoyao.cpzshandset.ui.adapter.HomeAdapter;

public class MedicineXYHomePresenter extends HomeConstactImpl {
	private final HomeConstact.View homeView;
	private Context context;
	private List<HandsetOperation> homeBeans = new ArrayList<HandsetOperation>();
	
	public MedicineXYHomePresenter(Context context,HomeConstact.View homeView){
		this.context = context;
		this.homeView = homeView;
		start();
	}

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


	private void initHomeEumnBeans() {
		homeBeans.add(HandsetOperation.OPERATION_CHECK_LABEL_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 option) {
//		if (homeBean == null || homeBean.getOperationId() < 0) return;
		switch (option) {
		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;
//			homeView.showMsgToast("检测", Toast.LENGTH_SHORT);
			Intent intent = new Intent(context, JianCeActivity.class);
			context.startActivity(intent);
			break;
		case OPERATION_CHECK_LABEL_STATUS_CONSTANT:
			//检测标签状态
			if (!checkViewAvailable()) return;
//			homeView.showMsgToast("检测", Toast.LENGTH_SHORT);
			Intent intent1 = new Intent(context, CheckLabelStatusActivity.class);
			intent1.putExtra("option_type", option);
			context.startActivity(intent1);
			break;
			default :
//				switchPage(option);
				break;

		}
		
	}

	private void switchPage(HandsetOperation option) {
		Intent activateIntent = new Intent(context, OptionHistoryListStyleActivity.class);
		activateIntent.putExtra("optionMode", option);
		context.startActivity(activateIntent);		
	}

}
