package com.casic.detector.base

import android.app.Application
import com.casic.detector.greendao.DaoMaster
import com.casic.detector.greendao.DaoSession
import com.pengxh.kt.lite.utils.SaveKeyValues
import kotlin.properties.Delegates

class BaseApplication : Application() {

    private val kTag = "BaseApplication"

    companion object {
        private var application: BaseApplication by Delegates.notNull()

        fun get() = application

        private lateinit var daoSession: DaoSession
    }

    override fun onCreate() {
        super.onCreate()
        application = this
        SaveKeyValues.initSharedPreferences(this)
        val devOpenHelper = DaoMaster.DevOpenHelper(this, "Detector.db", null)
        val daoMaster = DaoMaster(devOpenHelper.writableDatabase)
        daoSession = daoMaster.newSession()
    }

    fun getDaoSession(): DaoSession {
        return daoSession
    }
}