package com.mq.mylibrary.base;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.mq.mylibrary.MyDatabaseHelper;
import com.mq.mylibrary.tool.LogTool;
import com.mq.mylibrary.tool.SPTool;
import com.mq.mylibrary.tool.ToastTool;

/**
 * 创建人 mQ
 * 创建时间 2019/8/7 0007 11:09
 * 文件名称 BaseApp
 * 说明:  application基类
 **/
public abstract class BaseApp extends Application {

    protected abstract String getChannelName();

    private static MyDatabaseHelper mDatabaseHelper;
    private static Context mContext;

    //跳过读卡，直接走流程。生产环境请关闭！！
    public static boolean isSkipCard = false;

    public static String mChannelName = "";

    @Override
    public void onCreate() {
        super.onCreate();
        ToastTool.init(this);
        LogTool.isDebug(true);
        mContext = this;
        getDBHelper();
        SPTool.init(this, "handheld_device");
        mChannelName = getChannelName();
        LogTool.i("渠道名称：" + mChannelName);
    }

    public static SQLiteDatabase getDBHelper() {
        if (mDatabaseHelper == null)
            mDatabaseHelper = new MyDatabaseHelper(mContext, "handheld_device.db");
        return mDatabaseHelper.getWritableDatabase();
    }

    public static Context getAppContext() {
        return mContext;
    }

    /**
     * 读写卡数据是否加密
     */
    public static void saveIsEncryption(boolean isEncryption) {
        SPTool.save("isEncryption", isEncryption);
    }

    /**
     * 读写卡数据是否加密
     */
    public static boolean getIsEncryption() {
        return (boolean) SPTool.get("isEncryption", true);
    }

}
