mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
apply the style to the app
This commit is contained in:
parent
bd618d032f
commit
d9c7e937c6
@ -33,12 +33,12 @@ import com.github.libretube.models.PlayerViewModel
|
||||
import com.github.libretube.models.SearchViewModel
|
||||
import com.github.libretube.models.SubscriptionsViewModel
|
||||
import com.github.libretube.services.ClosingService
|
||||
import com.github.libretube.util.NavBarHelper
|
||||
import com.github.libretube.util.NetworkHelper
|
||||
import com.github.libretube.util.PreferenceHelper
|
||||
import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.elevation.SurfaceColors
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
|
||||
@ -93,13 +93,7 @@ class MainActivity : BaseActivity() {
|
||||
window.navigationBarColor = color
|
||||
|
||||
// save start tab fragment id
|
||||
startFragmentId =
|
||||
when (PreferenceHelper.getString(PreferenceKeys.DEFAULT_TAB, "home")) {
|
||||
"home" -> R.id.homeFragment
|
||||
"subscriptions" -> R.id.subscriptionsFragment
|
||||
"library" -> R.id.libraryFragment
|
||||
else -> R.id.homeFragment
|
||||
}
|
||||
startFragmentId = NavBarHelper.applyNavBarStyle(binding.bottomNav)
|
||||
|
||||
// set default tab as start fragment
|
||||
navController.graph.setStartDestination(startFragmentId)
|
||||
@ -107,16 +101,6 @@ class MainActivity : BaseActivity() {
|
||||
// navigate to the default fragment
|
||||
navController.navigate(startFragmentId)
|
||||
|
||||
val labelVisibilityMode = when (
|
||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
||||
) {
|
||||
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
||||
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
||||
"never" -> NavigationBarView.LABEL_VISIBILITY_UNLABELED
|
||||
else -> NavigationBarView.LABEL_VISIBILITY_AUTO
|
||||
}
|
||||
binding.bottomNav.labelVisibilityMode = labelVisibilityMode
|
||||
|
||||
binding.bottomNav.setOnApplyWindowInsetsListener(null)
|
||||
|
||||
binding.bottomNav.setOnItemSelectedListener {
|
||||
|
@ -63,7 +63,6 @@ class NavBarOptionsDialog : DialogFragment() {
|
||||
.setTitle(R.string.navigation_bar)
|
||||
.setView(binding.root)
|
||||
.setPositiveButton(R.string.okay) { _, _ ->
|
||||
Log.e("options", adapter.items.toString())
|
||||
NavBarHelper.setNavBarItems(adapter.items)
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.libretube.obj
|
||||
|
||||
data class NavBarItem(
|
||||
val resourceId: Int,
|
||||
val titleResource: Int,
|
||||
val id: Int = 0,
|
||||
val titleResource: Int = 0,
|
||||
var isEnabled: Boolean = true
|
||||
)
|
||||
|
@ -1,9 +1,16 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.fasterxml.jackson.core.type.TypeReference
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.constants.navBarItems
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.obj.NavBarItem
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
|
||||
object NavBarHelper {
|
||||
val preferenceKey = "nav_bar_items"
|
||||
@ -30,4 +37,45 @@ object NavBarHelper {
|
||||
mapper.writeValueAsString(items)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the bottom navigation style configured in the preferences
|
||||
* @return Id of the start fragment
|
||||
*/
|
||||
fun applyNavBarStyle(bottomNav: BottomNavigationView): Int {
|
||||
val labelVisibilityMode = when (
|
||||
PreferenceHelper.getString(PreferenceKeys.LABEL_VISIBILITY, "always")
|
||||
) {
|
||||
"always" -> NavigationBarView.LABEL_VISIBILITY_LABELED
|
||||
"selected" -> NavigationBarView.LABEL_VISIBILITY_SELECTED
|
||||
"never" -> NavigationBarView.LABEL_VISIBILITY_UNLABELED
|
||||
else -> NavigationBarView.LABEL_VISIBILITY_AUTO
|
||||
}
|
||||
bottomNav.labelVisibilityMode = labelVisibilityMode
|
||||
|
||||
val navBarItems = getNavBarItems()
|
||||
|
||||
val menuItems = mutableListOf<MenuItem>()
|
||||
// remove the old items
|
||||
navBarItems.forEach {
|
||||
menuItems.add(
|
||||
bottomNav.menu.findItem(it.id)
|
||||
)
|
||||
bottomNav.menu.removeItem(it.id)
|
||||
}
|
||||
|
||||
navBarItems.forEach { navBarItem ->
|
||||
if (navBarItem.isEnabled) {
|
||||
val menuItem = menuItems.filter { it.itemId == navBarItem.id }[0]
|
||||
|
||||
bottomNav.menu.add(
|
||||
menuItem.groupId,
|
||||
menuItem.itemId,
|
||||
Menu.NONE,
|
||||
menuItem.title
|
||||
).icon = menuItem.icon
|
||||
}
|
||||
}
|
||||
return navBarItems[0].id
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user