mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
Create function to check if there are Navigation bars.
This commit is contained in:
parent
ed13edffec
commit
b7550b903b
@ -16,15 +16,22 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
|
||||
object NavBarHelper {
|
||||
|
||||
private const val SEPARATOR = ","
|
||||
|
||||
fun hasTabs(): Boolean {
|
||||
val prefsItems = getNavBarPrefs()
|
||||
|
||||
val tabsUnchanged = prefsItems.isEmpty()
|
||||
val allTabsHidden = prefsItems.all { it.contains("-") }
|
||||
|
||||
return tabsUnchanged || !allTabsHidden
|
||||
}
|
||||
|
||||
// contains "-" -> invisible menu item, else -> visible menu item
|
||||
fun getNavBarItems(context: Context): List<MenuItem> {
|
||||
val prefItems = try {
|
||||
PreferenceHelper.getString(
|
||||
PreferenceKeys.NAVBAR_ITEMS,
|
||||
""
|
||||
).split(SEPARATOR)
|
||||
getNavBarPrefs()
|
||||
} catch (e: Exception) {
|
||||
Log.e("fail to parse nav items", e.toString())
|
||||
return getDefaultNavBarItems(context)
|
||||
@ -126,4 +133,11 @@ object NavBarHelper {
|
||||
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
||||
PreferenceHelper.putInt(PreferenceKeys.START_FRAGMENT, index)
|
||||
}
|
||||
|
||||
private fun getNavBarPrefs(): List<String> {
|
||||
return PreferenceHelper
|
||||
.getString(PreferenceKeys.NAVBAR_ITEMS, "")
|
||||
.split(SEPARATOR)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user