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

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

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import cn.net.caoyao.cpzshandset.common.config.Config;
import cn.net.caoyao.cpzshandset.common.config.HandsetSettingOption;
import cn.net.caoyao.cpzshandset.common.config.HandsetVersionConstant;
import cn.net.caoyao.cpzshandset.service.bll.config.ConfigBll;
import cn.net.caoyao.cpzshandset.service.presenter.SettingConstact;
import cn.net.caoyao.cpzshandset.service.presenter.SettingConstact.View;
import cn.net.caoyao.cpzshandset.service.presenter.base.impl.SettingConstactImpl;
import cn.net.caoyao.cpzshandset.ui.activity.DeviceIdConfigActivity;
import cn.net.caoyao.cpzshandset.ui.activity.ModifyHandsetVersionActivity;
import cn.net.caoyao.cpzshandset.ui.adapter.SettingAdapter;

/** 
 * @author  作者 李扬: 
 * @date 创建时间：2017-4-20 下午3:50:21 
 * @version 1.0 
 * @parameter 
 * @since  
 * @return  
 */
public class ChinatexSettingPresenter extends SettingConstactImpl {
	
	private SettingConstact.View sView;
	private Context context;
	private List<HandsetSettingOption> beans = new ArrayList<>();
	private ConfigBll configBll;
	private ProgressDialog bProgressDialog = null;
	private int currentHandsetVersion = HandsetVersionConstant.HANDSET_CHINATEX_VERSION_MODE;
	
	public ChinatexSettingPresenter(View sView, Context context) {	
		this.sView = sView;
		this.context = context;
		start();
	}

	@Override
	public void start() {
		if (!checkViewAvailable())
			return;
		configBll = new ConfigBll(context);
		initSettingData();
		SettingAdapter adapter = new SettingAdapter(beans);
		sView.setAdapter(adapter);
	}
	private void initSettingData() {
		beans.add(HandsetSettingOption.SETTING_CONFIG_DEVICE_ID_MODE);
		//beans.add(HandsetSettingOption.SETTING_UPDATE_PRODUCT_LIST_MODE);
		if (Config.canSwitchHandsetVersionMode) {
			beans.add(HandsetSettingOption.SETTING_HANDSET_MODE_SWITCH_MODE);
		}
	}

	@Override
	public boolean checkViewAvailable() {
		boolean b = false;
		if (sView != null && context != null) {
			b = true;
		}
		return b;
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Handler getHandler() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onItemClickListener(int position) {
		// TODO Auto-generated method stub
		selectOption(beans.get(position));
	}
	private void selectOption(HandsetSettingOption setOption) {
		switch (setOption) {
		case SETTING_HANDSET_MODE_SWITCH_MODE:
			// 修改手持机版本模式
			Intent modifyVersionIntent = new Intent(context,
					ModifyHandsetVersionActivity.class);
			context.startActivity(modifyVersionIntent);
			break;
		case SETTING_CONFIG_DEVICE_ID_MODE:
			// 配置设备ID
			Intent intent = new Intent(context, DeviceIdConfigActivity.class);
			context.startActivity(intent);
			break;	

		default:
			break;
		}
	}
}
