mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #2299 from Bnyro/master
Possibility to hide the navbar completely
This commit is contained in:
commit
9336ffb81b
@ -5,12 +5,10 @@ import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import androidx.annotation.Nullable
|
||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||
|
||||
class ClosingService : Service() {
|
||||
|
||||
@Nullable
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
}
|
||||
|
@ -85,12 +85,6 @@ class MainActivity : BaseActivity() {
|
||||
navController = findNavController(R.id.fragment)
|
||||
binding.bottomNav.setupWithNavController(navController)
|
||||
|
||||
// gets the surface color of the bottom navigation view
|
||||
val color = SurfaceColors.getColorForElevation(this, 10F)
|
||||
|
||||
// sets the navigation bar color to the previously calculated color
|
||||
window.navigationBarColor = color
|
||||
|
||||
// save start tab fragment id and apply navbar style
|
||||
startFragmentId = try {
|
||||
NavBarHelper.applyNavBarStyle(binding.bottomNav)
|
||||
@ -98,6 +92,11 @@ class MainActivity : BaseActivity() {
|
||||
R.id.homeFragment
|
||||
}
|
||||
|
||||
// sets the navigation bar color to the previously calculated color
|
||||
window.navigationBarColor = if (binding.bottomNav.menu.size() > 0) {
|
||||
SurfaceColors.getColorForElevation(this, 10F)
|
||||
} else ThemeHelper.getThemeColor(this, android.R.attr.colorBackground)
|
||||
|
||||
// set default tab as start fragment
|
||||
navController.graph.setStartDestination(startFragmentId)
|
||||
|
||||
|
@ -3,7 +3,6 @@ package com.github.libretube.ui.adapters
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.databinding.NavOptionsItemBinding
|
||||
@ -39,10 +38,6 @@ class NavBarOptionsAdapter(
|
||||
if (selectedHomeTabId == item.itemId) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (!item.isVisible) {
|
||||
Toast.makeText(root.context, R.string.not_enabled, Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
val oldSelection = items.indexOfFirst { it.itemId == selectedHomeTabId }
|
||||
selectedHomeTabId = item.itemId
|
||||
listOf(position, oldSelection).forEach {
|
||||
@ -50,25 +45,8 @@ class NavBarOptionsAdapter(
|
||||
}
|
||||
}
|
||||
checkbox.setOnClickListener {
|
||||
if (item.itemId == selectedHomeTabId) {
|
||||
Toast.makeText(root.context, R.string.select_other_start_tab, Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (!checkbox.isChecked && getVisibleItemsCount() < 2) {
|
||||
checkbox.isChecked = true
|
||||
Toast.makeText(
|
||||
root.context,
|
||||
R.string.select_at_least_one,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
item.isVisible = checkbox.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getVisibleItemsCount(): Int {
|
||||
return items.filter { it.isVisible }.size
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.PopupMenu
|
||||
import androidx.core.view.forEach
|
||||
import androidx.core.view.get
|
||||
@ -106,6 +107,8 @@ object NavBarHelper {
|
||||
).icon = menuItem.icon
|
||||
}
|
||||
}
|
||||
if (navBarItems.filter { it.isVisible }.isEmpty()) bottomNav.visibility = View.GONE
|
||||
|
||||
return getStartFragmentId(bottomNav.context)
|
||||
}
|
||||
|
||||
@ -113,7 +116,7 @@ object NavBarHelper {
|
||||
val pref = PreferenceHelper.getInt(PreferenceKeys.START_FRAGMENT, Int.MAX_VALUE)
|
||||
val defaultNavItems = getDefaultNavBarItems(context)
|
||||
return if (pref == Int.MAX_VALUE) {
|
||||
getNavBarItems(context).first { it.isVisible }.itemId
|
||||
getNavBarItems(context).firstOrNull { it.isVisible }?.itemId ?: R.id.homeFragment
|
||||
} else {
|
||||
defaultNavItems.get(pref).itemId
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user