package com.swago.baseswago.util

import android.content.Context
import android.content.SharedPreferences

/**
 *@date 2021/8/30 17:05
 *description:
 */
object SpUtil {

    private var sp:SharedPreferences? = null

    private fun getInstance(): SharedPreferences {
        if (sp==null){
           sp =  AppContext.getContext().getSharedPreferences("Swago", Context.MODE_PRIVATE)
        }
        return sp!!
    }


    fun putString(key:String,value:String){
        getInstance().edit().putString(key,value).apply()
    }

    fun readString(key:String): String? {
        return getInstance().getString(key,"")
    }

    fun putInt(key: String,value:Int){
        getInstance().edit().putInt(key,value).apply()
    }

    fun readInt(key:String):Int{
        return getInstance().getInt(key,0)
    }

    fun clearSp(){
        getInstance().edit().clear().commit()
    }

}