package com.sipai.jspatrol.utils;


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.sipai.jspatrol.R;

public class Utils {

	private static final String FILENAME = "userinfo.json"; // 用户保存文件名
	private static final String TAG = "Utils";

	public static int getlight4mp(String name,String value){
		if(name.contains("故障")||name.contains("警告")||name.contains("需维护")||name.contains("过载")||name.contains("超时")){
			if(value!=null && value.equals("1")){
				return R.mipmap.yellow_btn;
			}else{
				return R.mipmap.gray_btn;
			}
		}else{
			if(value!=null && value.contains("1")){
				return R.mipmap.green_btn;
			}else{
				return R.mipmap.red_btn;
			}
		}

	}

	/**
	 * 判断网络是否可用
	 * @param context
	 * @return
	 */
	public static boolean isNetworkConnected(Context context) {
		if (context != null) {
			ConnectivityManager mConnectivityManager = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
			if (mNetworkInfo != null) {
				return mNetworkInfo.isAvailable();
			}
		}
		return false;
	}


	public static int getpointPic(String name){
		if (name.contains("运行")){
			return R.mipmap.iv_eqp;
		}
		else if (name.contains("故障")){
			return R.mipmap.iv_eqp;
		}
		else if (name.contains("功率")||name.toLowerCase().contains("p")&&!name.toLowerCase().contains("ph")&&!name.toLowerCase().contains("tp")){
			return R.mipmap.iv_p;
		}
		else if (name.toLowerCase().contains("ph")){
			return R.mipmap.iv_ph;
		}
		else if (name.contains("氨氮")){
			return R.mipmap.iv_nh3;
		}
		else if (name.contains("温度")){
			return R.mipmap.iv_temp_r;
		}
		else if (name.toLowerCase().contains("cod")){
			return R.mipmap.iv_cod;
		}
		else if (name.contains("流量")){
			return R.mipmap.iv_waterflow;
		}
		else if (name.contains("风量")){
			return R.mipmap.iv_airflow;
		}
		else if (name.contains("电")||name.toLowerCase().contains("ia")||name.toLowerCase().contains("uan")){
			return R.mipmap.iv_ele;
		}
		else if (name.contains("液位")){
			return R.mipmap.iv_waterliqu;
		}
		else if (name.toLowerCase().contains("ss")&&!name.toLowerCase().contains("mlss")){
			return R.mipmap.iv_ss;
		}
		else if (name.toLowerCase().contains("mlss")){
			return R.mipmap.iv_mlss;
		}
		else if (name.toLowerCase().contains("nh3n")){
			return R.mipmap.iv_nh3n;
		}
		else if (name.toLowerCase().contains("pa")||name.contains("压力")){
			return R.mipmap.iv_pa;
		}
		else if (name.toLowerCase().contains("hz")||name.contains("频率")){
			return R.mipmap.iv_hz;
		}
		else if (name.toLowerCase().contains("do1")){
			return R.mipmap.iv_do;
		}
		else if (name.toLowerCase().contains("do2")){
			return R.mipmap.iv_do;
		}
		else if (name.toLowerCase().contains("tn")||name.contains("总氮")){
			return R.mipmap.iv_tn;
		}
		else if (name.toLowerCase().contains("tp")||name.contains("总磷")){
			return R.mipmap.iv_tp;
		}
		else if (name.contains("维护")||name.contains("维修")||name.contains("过载")||name.contains("超时")||name.contains("信号")||name.contains("到位")||name.contains("力矩")||name.contains("报警")||name.contains("次数")){
			return R.mipmap.iv_eqp;
		}
		else{
			return R.mipmap.iv_water;
		}
	}

	public static int getValueArray(String mark){
		if (mark.equals("NOTHING3")){
			return R.array.NOTHING3;
		}else if (mark.equals("HAVE2")){
			return R.array.HAVE2;
		}else if (mark.equals("HIGH2")){
			return R.array.HIGH2;
		}else if (mark.equals("START3")){
			return R.array.START3;
		}else if (mark.equals("YELLOW3")){
			return R.array.YELLOW3;
		}else if (mark.equals("HIGH3")){
			return R.array.HIGH3;
		}else if (mark.equals("NORMAL2")){
			return R.array.NORMAL2;
		}else if (mark.equals("FULL2")){
			return R.array.FULL2;
		}else if (mark.equals("FULL3")){
			return R.array.FULL3;
		}else if (mark.equals("MORE3")){
			return R.array.MORE3;
		}else if (mark.equals("OPEN2")){
			return R.array.OPEN2;
		}else if (mark.equals("DAMAGE2")){
			return R.array.DAMAGE2;
		}else if (mark.equals("GOOD2")){
			return R.array.GOOD2;
		}else if (mark.equals("YES2")){
			return R.array.YES2;
		}else if (mark.equals("VOL2")){
			return R.array.VOL2;
		}else if (mark.equals("VOL3")){
			return R.array.VOL3;
		}else if (mark.equals("FLOW2")){
			return R.array.FLOW2;
		}else if (mark.equals("DRY2")){
			return R.array.DRY2;
		}else {
			return R.array.HIGH2;
		}
	}
}
