package com.base.pdfreaderallpdfreader.utils

object SpStringUtils {
    private val TAG = "SpStringUtils"

    const val BOOKMARK_KEY = "bookmark_key"

    //key=last_view_key value=/data/user/0/com.ttesst.gododo.redause/files/demo/DEMO.pdf_/_1728703007625
    const val LAST_VIEW_KEY = "last_view_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)
    }
}