package com.free.video.wallpaper.helper

import android.content.Context
import android.content.SharedPreferences
import com.free.video.wallpaper.baseapp.MyWallpaperApp

object Store {

    val KEY_CURRENT_WAPPPAPER_PATH = "wallpaper_path"
    val DB_INIT_DATAT = "init_db_data"

    private var shared: SharedPreferences? = null

    var video_path: String
        get() = queryString(
            KEY_CURRENT_WAPPPAPER_PATH,
            ""
        )
        set(value) {
            saveString(KEY_CURRENT_WAPPPAPER_PATH, value)
        }
    var dbinit: String
        get() = queryString(
            DB_INIT_DATAT,
            "0"
        )
        set(value) {
            saveString(DB_INIT_DATAT, value)
        }

    private fun getShared(): SharedPreferences {
        if (shared == null) {
            shared = MyWallpaperApp.getApplication().getSharedPreferences("", Context.MODE_PRIVATE)
        }
        return shared!!

    }





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

    fun queryString(key: String, defaultValue: String): String {
        return getShared()
            .getString(key, defaultValue).orEmpty()
    }

}