package com.lemonhc.mplus.app

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.multidex.MultiDexApplication
import com.lemonhc.mplus.barcode.BarcodeServiceImpl

/**
 * Created by Kangsh on 2020. 1. 17..
 */

class MPlusApplication : MultiDexApplication() {

    lateinit var mContext:Context
    private var barcode: BarcodeServiceImpl? = null

    init {
        instance = this
    }

    companion object {
        private var instance: MPlusApplication? = null

        fun applicationContext() : Context {
            return instance!!.applicationContext
        }

        // sharedPreference
        @JvmStatic
        fun getPreference(key: String, defValue: Int): Int {
            return getPreference().getInt(key, defValue)
        }

        @JvmStatic
        fun getPreference(): SharedPreferences {
            return PreferenceManager.getDefaultSharedPreferences(instance)
        }

        @JvmStatic
        fun setPreference(key: String, value: Int) {
            getPreference().edit().putInt(key, value).apply()
        }
    }

    override fun onCreate() {
        super.onCreate()

        mContext = applicationContext()

        //fatima 전용.. 공통으로 사용하게할 필요 있음.
        this.barcode = BarcodeServiceImpl(this)
        this.barcode?.initScanBarcode()
    }
}
