import com.easy.clean.utils.AppPreferences
import com.easy.clean.utils.LogEx

object SpStringUtils {

    private val TAG = "SpStringUtils"

    const val _KEY = ""

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

    fun addSpString(key: String, value: String) {
        LogEx.logDebug(TAG, "key=$key value=$value")
        val list = getSpStringList(key).toMutableList()
        list.add(value)
        val string = list.joinToString(separator = "|||")
        AppPreferences.getInstance().put(key, string)
    }

    fun deleteSpString(key: String, value: String) {
        val list = getSpStringList(key).toMutableList()
        list.remove(value)
        val string = list.joinToString(separator = "|||")
        AppPreferences.getInstance().put(key, string)
    }

}