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