package com.kfzs.duanduan.react;

import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by realicing on 2018/1/7.
 * realicing@sina.com
 */

public class ReactUtil {
    /**
     * 是否进入rn调试模式
     */
    public static final boolean isSmallDebug() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir != null && new File(sdDir, "smallSheep.debug").exists();
    }
    /**
     * 是否进入rn调试模式
     */
    public static final boolean isRnDebug() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir != null && new File(sdDir, "duanduanReactNative.debug").exists();
    }

    /**
     * 是否加载rn
     */
    public static final boolean isLoadRn() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir != null && new File(sdDir, "duanduanReactNative.load").exists();
    }

    /**
     * 是否加载rn_BorrowPlay
     */
    public static final boolean isLoadRn_BorrowPlay() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir != null && new File(sdDir, "duanduanReactNative.load_bp").exists();
    }

    /**
     * 是否包含用户名密码文件
     */
    public static final boolean isHasUserFile() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir != null && new File(sdDir, "duanduan.zh").exists();
    }

    public static Map<String, String> MAP_PWD;

    public static List<String> initArr() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在
        if (sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        if (sdDir != null && new File(sdDir, "duanduan.zh").exists()) {
            List<String> list = FileUtil.readLines(new File(sdDir, "duanduan.zh").getAbsolutePath());
            if (list != null && !list.isEmpty()) {
                List<String> arr = new ArrayList<>();
                MAP_PWD = new HashMap<>(list.size());
                int i = 0;
                for (String line : list) {
                    if (line.contains("\t")) {
                        String[] items = line.split("\t");
                        arr.add(items[0]);
                        MAP_PWD.put(items[0], items[1]);
                    }
                    i++;
                }
                return arr;
            }
        }
        return new ArrayList<>();
    }



}
