mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Merge pull request #1340 from Bnyro/master
dont hardcode navbar defaults
This commit is contained in:
commit
a5856e7572
@ -2,6 +2,6 @@ package com.github.libretube.obj
|
|||||||
|
|
||||||
data class NavBarItem(
|
data class NavBarItem(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
val titleResource: Int = 0,
|
val title: String = "",
|
||||||
var isEnabled: Boolean = true
|
var isEnabled: Boolean = true
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ class NavBarOptionsAdapter(
|
|||||||
override fun onBindViewHolder(holder: NavBarOptionsViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: NavBarOptionsViewHolder, position: Int) {
|
||||||
val item = items[position]
|
val item = items[position]
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
title.text = root.context.getString(item.titleResource)
|
title.text = item.title
|
||||||
checkbox.isChecked = item.isEnabled
|
checkbox.isChecked = item.isEnabled
|
||||||
checkbox.setOnClickListener {
|
checkbox.setOnClickListener {
|
||||||
if (!checkbox.isChecked && getEnabledItemsCount() < 2) {
|
if (!checkbox.isChecked && getEnabledItemsCount() < 2) {
|
||||||
|
@ -18,7 +18,7 @@ class NavBarOptionsDialog : DialogFragment() {
|
|||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
binding = DialogNavbarOptionsBinding.inflate(layoutInflater)
|
binding = DialogNavbarOptionsBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
val options = NavBarHelper.getNavBarItems()
|
val options = NavBarHelper.getNavBarItems(requireContext())
|
||||||
|
|
||||||
val adapter = NavBarOptionsAdapter(options.toMutableList())
|
val adapter = NavBarOptionsAdapter(options.toMutableList())
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package com.github.libretube.util
|
package com.github.libretube.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import android.widget.PopupMenu
|
||||||
|
import androidx.core.view.forEach
|
||||||
import com.fasterxml.jackson.core.type.TypeReference
|
import com.fasterxml.jackson.core.type.TypeReference
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
@ -11,26 +15,11 @@ 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 {
|
||||||
val preferenceKey = "nav_bar_items"
|
private const val preferenceKey = "nav_bar_items"
|
||||||
|
|
||||||
val defaultNavBarItems = listOf(
|
private val mapper = ObjectMapper()
|
||||||
NavBarItem(
|
|
||||||
R.id.homeFragment,
|
|
||||||
R.string.startpage
|
|
||||||
),
|
|
||||||
NavBarItem(
|
|
||||||
R.id.subscriptionsFragment,
|
|
||||||
R.string.subscriptions
|
|
||||||
),
|
|
||||||
NavBarItem(
|
|
||||||
R.id.libraryFragment,
|
|
||||||
R.string.library
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
val mapper = ObjectMapper()
|
fun getNavBarItems(context: Context): List<NavBarItem> {
|
||||||
|
|
||||||
fun getNavBarItems(): List<NavBarItem> {
|
|
||||||
return try {
|
return try {
|
||||||
val type = object : TypeReference<List<NavBarItem>>() {}
|
val type = object : TypeReference<List<NavBarItem>>() {}
|
||||||
mapper.readValue(
|
mapper.readValue(
|
||||||
@ -41,6 +30,17 @@ object NavBarHelper {
|
|||||||
type
|
type
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
val p = PopupMenu(context, null)
|
||||||
|
MenuInflater(context).inflate(R.menu.bottom_menu, p.menu)
|
||||||
|
val defaultNavBarItems = mutableListOf<NavBarItem>()
|
||||||
|
p.menu.forEach {
|
||||||
|
defaultNavBarItems.add(
|
||||||
|
NavBarItem(
|
||||||
|
it.itemId,
|
||||||
|
it.title.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
return defaultNavBarItems
|
return defaultNavBarItems
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ object NavBarHelper {
|
|||||||
}
|
}
|
||||||
bottomNav.labelVisibilityMode = labelVisibilityMode
|
bottomNav.labelVisibilityMode = labelVisibilityMode
|
||||||
|
|
||||||
val navBarItems = getNavBarItems()
|
val navBarItems = getNavBarItems(bottomNav.context)
|
||||||
|
|
||||||
val menuItems = mutableListOf<MenuItem>()
|
val menuItems = mutableListOf<MenuItem>()
|
||||||
// remove the old items
|
// remove the old items
|
||||||
|
Loading…
Reference in New Issue
Block a user