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

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

public class SeedsHomePresenter extends HomeConstactImpl {

	private HomeConstact.View homeView;
	private Context context;
	private List<HandsetOperation> homeBeans = new ArrayList<HandsetOperation>();

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

	@Override
	public void start() {
		initHomeBeans();
		if(!checkViewAvailable())
			return ;
		clearStatusData();
		homeView.setAdapter(new HomeAdapter(homeBeans));
		homeView.setHomeTitle(context.getResources().getString(R.string.home_seeds_title_str));
	}
	/*
	 * 清除七天前的纪录
	 */
	private void clearStatusData()  {
		
	}
	
	private void initHomeBeans() {
		homeBeans.add(HandsetOperation.OPERATION_ACTIVATE_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;
		selectOption(homeBeans.get(position));
	}
	
	private void selectOption(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;
		default:
			
			break;
		}
	}

}
