mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +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
|
import com.google.android.material.navigation.NavigationBarView
|
||||||
|
|
||||||
object NavBarHelper {
|
object NavBarHelper {
|
||||||
|
|
||||||
private const val SEPARATOR = ","
|
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
|
// contains "-" -> invisible menu item, else -> visible menu item
|
||||||
fun getNavBarItems(context: Context): List<MenuItem> {
|
fun getNavBarItems(context: Context): List<MenuItem> {
|
||||||
val prefItems = try {
|
val prefItems = try {
|
||||||
PreferenceHelper.getString(
|
getNavBarPrefs()
|
||||||
PreferenceKeys.NAVBAR_ITEMS,
|
|
||||||
""
|
|
||||||
).split(SEPARATOR)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("fail to parse nav items", e.toString())
|
Log.e("fail to parse nav items", e.toString())
|
||||||
return getDefaultNavBarItems(context)
|
return getDefaultNavBarItems(context)
|
||||||
@ -126,4 +133,11 @@ object NavBarHelper {
|
|||||||
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
val index = getDefaultNavBarItems(context).indexOfFirst { it.itemId == itemId }
|
||||||
PreferenceHelper.putInt(PreferenceKeys.START_FRAGMENT, index)
|
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