package com.hd.live.wallpapers.others

import android.content.Context
import android.content.SharedPreferences
import com.hd.live.wallpapers.LiveApp

object SaveUtils {

    val KEY_CURRENT_WAPPPAPER_PATH = "wallpaper_path"
    val DB_INIT_DATAT = "init_db_data"
    val IS_POST = "is_post"
    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)
        }


    var isPost: Boolean
        get() = queryBoolean(
            IS_POST,
            false
        )
        set(value) {
            saveBoolean(IS_POST, value)
        }



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

    }


    fun saveBoolean(key: String, value: Boolean) {
        getShared().edit()
            .putBoolean(key, value).apply()
    }

    fun queryBoolean(key: String, defaultValue: Boolean): Boolean {
        return getShared()
            .getBoolean(key, defaultValue)
    }


    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()
    }

}