package com.sheep.gamegroup.util;

import android.os.Environment;
import android.text.TextUtils;

import java.io.File;
import java.util.List;

import static com.sheep.jiuyan.samllsheep.utils.ClassFileHelper.DIR;

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

public class ConfigUtil {
    private static ConfigUtil instance = new ConfigUtil();
    private ConfigUtil() {
        if(TestUtil.isTest()) {
            File file = new File(DIR, "smallSheep.config");
            isFileExists = file.exists();
            if (isFileExists) {
                content = FileUtil.readLines(file);
            }
        }
    }
    public static ConfigUtil getInstance() {
        if (instance == null) {
            instance = new ConfigUtil();
        }
        return instance;
    }
    private boolean isFileExists;
    private List<String> content;

    public boolean isFileExists() {
        return isFileExists;
    }

    /**
     * 第一行  connectAddress的名字：sheep sheepfz sheeptest   developSheeptest
     * 第二行  是否升级（1为要升级，2为不升级）：1 2
     * 第行
     * @param position
     * @return
     */
    public String getItem(int position){
        return ListUtil.getItem(content, position);
    }

    /**
     * 是否调用升级
     * @return
     */
    public boolean isUpgrade() {
        String item = getItem(1);
        return item == null || TextUtils.equals(item, "1");
    }
    /**
     * 是否进入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();
    }

}
