Fix queue edge-to-edge issue

Fix a problem where the last queue item would display behind the navigation bar when edge to edge is on.
This commit is contained in:
OxygenCobalt 2021-03-07 08:26:15 -07:00
parent 391ca70822
commit a750100aff
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 52 additions and 30 deletions

View file

@ -36,7 +36,7 @@ class MainActivity : AppCompatActivity() {
setTheme(newAccent.theme)
if (isEdgeOn()) {
doEdgeToEdgeSetup(binding)
setupEdgeToEdge(binding)
}
}
@ -70,7 +70,7 @@ class MainActivity : AppCompatActivity() {
}
}
private fun doEdgeToEdgeSetup(binding: ActivityMainBinding) {
private fun setupEdgeToEdge(binding: ActivityMainBinding) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Do modern edge to edge, which happens to be around twice the size of the
// old way of doing things. Thanks android, very cool!

View file

@ -53,7 +53,8 @@ private val ID3_GENRES = arrayOf(
/**
* Convert legacy int-based ID3 genres to their human-readable genre
* @return The named genre for this legacy genre, null if there is no need to parse it or if the genre is invalid.
* @return The named genre for this legacy genre, null if there is no need to parse it
* or if the genre is invalid.
*/
fun String.getGenreNameCompat(): String? {
if (isDigitsOnly()) {

View file

@ -43,28 +43,8 @@ class QueueFragment : Fragment() {
// --- UI SETUP ---
binding.queueToolbar.apply {
setNavigationOnClickListener {
findNavController().navigateUp()
}
if (!requireActivity().isIrregularLandscape() && isEdgeOn()) {
setOnApplyWindowInsetsListener { _, insets ->
val top = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
insets.getInsets(WindowInsets.Type.systemBars()).top
} else {
@Suppress("DEPRECATION")
insets.systemWindowInsetTop
}
(parent as View).updatePadding(top = top)
insets
}
} else {
// Dont even bother w/edge-to-edge if the navigation bar is on the side
binding.root.fitsSystemWindows = true
}
binding.queueToolbar.setNavigationOnClickListener {
findNavController().navigateUp()
}
binding.queueRecycler.apply {
@ -73,6 +53,8 @@ class QueueFragment : Fragment() {
helper.attachToRecyclerView(this)
}
setupEdgeForQueue(binding)
// --- VIEWMODEL SETUP ----
playbackModel.userQueue.observe(viewLifecycleOwner) { userQueue ->
@ -104,6 +86,46 @@ class QueueFragment : Fragment() {
return binding.root
}
private fun setupEdgeForQueue(binding: FragmentQueueBinding) {
if (isEdgeOn() && !requireActivity().isIrregularLandscape()) {
binding.queueToolbar.setOnApplyWindowInsetsListener { v, insets ->
val top = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
insets.getInsets(WindowInsets.Type.systemBars()).top
} else {
@Suppress("DEPRECATION")
insets.systemWindowInsetTop
}
(v.parent as View).updatePadding(top = top)
insets
}
binding.queueRecycler.setOnApplyWindowInsetsListener { v, insets ->
val bottom = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
insets.getInsets(WindowInsets.Type.systemBars()).bottom
} else {
@Suppress("DEPRECATION")
insets.systemWindowInsetBottom
}
// Apply bottom padding to make sure that the last queue item isnt incorrectly lost,
// but also make sure that the added padding wont clip the child views entirely.
(v as ViewGroup).apply {
clipToPadding = false
updatePadding(bottom = bottom)
}
insets
}
} else {
// Don't even bother if we are in phone landscape or if edge-to-edge is off.
binding.root.fitsSystemWindows = true
}
}
// --- QUEUE DATA ---
/**
* Create the queue data that should be displayed
* @return The list of headers/songs that should be displayed.

View file

@ -48,14 +48,14 @@ class SettingsListFragment : PreferenceFragmentCompat() {
/**
* Recursively call [handlePreference] on a preference.
*/
private fun recursivelyHandleChildren(pref: Preference) {
if (pref is PreferenceCategory) {
private fun recursivelyHandleChildren(preference: Preference) {
if (preference is PreferenceCategory) {
// If this preference is a category of its own, handle its own children
pref.children.forEach { pref ->
preference.children.forEach { pref ->
recursivelyHandleChildren(pref)
}
} else {
handlePreference(pref)
handlePreference(preference)
}
}

View file

@ -42,7 +42,6 @@ org.oxycblt.auxio # Main UI's and logging utilities
├──.library # Library UI
├──.loading # Loading UI
├──.music # Music storage and loading
│ └──.processing # Systems for music loading and organization
├──.playback # Playback UI and systems
│ ├──.queue # Queue user interface
│ ├──.state # Backend/Modes for the playback state