package com.base.browserwhite.utils

object SpBeanUtils {


    const val BOOKMARK_SP_KEY = "bookmark_sp_key"
    const val SEARCH_RECORD_SP_KEY = "SEARCH_RECORD_SP_KEY"

    fun getSpBeanList(key: String): List<String> {
        val sp = AppPreferences.getInstance().getString(key, "")
        return if (sp.equals("")) {
            listOf()
        } else {
            sp.split(",")
        }
    }

    fun deleteSpBean(key: String, value: String) {
        val list = getSpBeanList(key).toMutableList()
        list.remove(value)
        val string = list.joinToString(separator = ",")

        AppPreferences.getInstance().put(key, string)
    }

    fun addSpBean(key: String, value: String) {
        val list = getSpBeanList(key).toMutableList()
        list.add(value)
        val string = list.joinToString(separator = ",")
        AppPreferences.getInstance().put(key, string)
    }


    fun clearSpBean(key: String) {
        AppPreferences.getInstance().put(key, "")
    }

}