LibreTube/app/src/main/java/com/github/libretube/util/NavBarHelper.kt

34 lines
906 B
Kotlin
Raw Normal View History

2022-09-20 22:06:23 +05:30
package com.github.libretube.util
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.libretube.constants.navBarItems
import com.github.libretube.obj.NavBarItem
object NavBarHelper {
val preferenceKey = "nav_bar_items"
val mapper = ObjectMapper()
fun getNavBarItems(): List<NavBarItem> {
return try {
val type = object : TypeReference<List<NavBarItem>>() {}
mapper.readValue(
PreferenceHelper.getString(
preferenceKey,
""
),
type
)
} catch (e: Exception) {
return navBarItems
}
}
fun setNavBarItems(items: List<NavBarItem>) {
PreferenceHelper.putString(
preferenceKey,
mapper.writeValueAsString(items)
)
}
}