detail: implement dual-pane layout

This commit is contained in:
Alexander Capehart
2026-04-18 18:42:45 -06:00
parent 75499e0ad6
commit 922d44998d
13 changed files with 621 additions and 550 deletions
@@ -158,7 +158,6 @@ class AlbumDetailFragment : DetailFragment<Album, Song>() {
}
binding.detailShuffleButton?.setOnClickListener {
playbackModel.shuffle(album)
playbackModel.shuffle(album)
}
setToolbarPlaybackButtonsEnabled(true)
updatePlayback(
@@ -316,7 +315,7 @@ class AlbumDetailFragment : DetailFragment<Album, Song>() {
val binding = requireBinding()
// RecyclerView will scroll assuming it has the total height of the screen (i.e a
// collapsed appbar), so we need to collapse the appbar if that's the case.
binding.detailAppbar.setExpanded(false)
binding.detailAppbar?.setExpanded(false)
if (!binding.detailRecycler.canScroll()) {
// Don't scroll if the RecyclerView goes off screen. If we go anyway, overscroll
// kicks in and creates a weird bounce effect.
@@ -22,11 +22,14 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.WindowInsets
import androidx.core.view.updatePadding
import androidx.fragment.app.activityViewModels
import androidx.navigation.findNavController
import androidx.recyclerview.widget.GridLayoutManager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.transition.MaterialSharedAxis
import org.oxycblt.auxio.BuildConfig
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@@ -41,6 +44,8 @@ import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.setFullWidthLookup
import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.auxio.util.systemCutoutInsetsCompat
import org.oxycblt.musikr.Music
import org.oxycblt.musikr.MusicParent
@@ -78,7 +83,34 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
super.onBindingCreated(binding, savedInstanceState)
// --- UI SETUP ---
binding.detailAppbar.addOnOffsetChangedListener(this)
binding.detailAppbar?.addOnOffsetChangedListener(this)
val pane = binding.detailPane
if (pane != null) {
// 2-pane layout, re-adjust toolbar and pane to insets but not recycler,
// it applies its own insets
binding.detailToolbar.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(top = insets.systemBarInsetsCompat.top)
insets
}
// prevents duplicate titles
// not needed for buttons since they are not in the dual-pane layout
binding.detailNormalToolbar.titleContainer.alpha = 0f
pane.setOnApplyWindowInsetsListener { view, insets ->
// todo: rtl awareness
view.updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
insets
}
}
val appbar = binding.detailAppbar
if (appbar != null && savedInstanceState != null) {
// single-pane, we need to make sure restore the lost collapsing toolbar state
val panes = savedInstanceState.getBoolean(KEY_DUAL_PANE)
val scrolled = savedInstanceState.getBoolean(KEY_SCROLLED)
if (panes && scrolled) {
appbar.setExpanded(false)
}
}
binding.detailNormalToolbar.apply {
setNavigationOnClickListener { findNavController().navigateUp() }
@@ -88,17 +120,6 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
binding.detailRecycler.apply {
adapter = getDetailListAdapter()
(layoutManager as GridLayoutManager).setFullWidthLookup {
if (it != 0) {
val item =
detailModel.artistSongList.value.getOrElse(it - 1) {
return@setFullWidthLookup false
}
item is PlainDivider || item is PlainHeader
} else {
true
}
}
}
spacingSmall = requireContext().getDimenPixels(R.dimen.spacing_small)
@@ -106,11 +127,18 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
override fun onDestroyBinding(binding: FragmentDetailBinding) {
super.onDestroyBinding(binding)
binding.detailAppbar.removeOnOffsetChangedListener(this)
binding.detailAppbar?.removeOnOffsetChangedListener(this)
binding.detailNormalToolbar.setOnMenuItemClickListener(null)
binding.detailRecycler.adapter = null
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val binding = requireBinding()
outState.putBoolean(KEY_DUAL_PANE, binding.detailPane != null)
outState.putBoolean(KEY_SCROLLED, binding.detailRecycler.computeVerticalScrollOffset() > 0f)
}
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
val binding = requireBinding()
val range = appBarLayout.totalScrollRange
@@ -118,9 +146,11 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
val outRatio = min(ratio * 2, 1f)
val detailHeader = binding.detailHeader
detailHeader.scaleX = 1 - 0.2f * outRatio / (5f / 3f)
detailHeader.scaleY = 1 - 0.2f * outRatio / (5f / 3f)
detailHeader.alpha = 1 - outRatio
if (detailHeader != null) {
detailHeader.scaleX = 1 - 0.2f * outRatio / (5f / 3f)
detailHeader.scaleY = 1 - 0.2f * outRatio / (5f / 3f)
detailHeader.alpha = 1 - outRatio
}
val inRatio = max(ratio - 0.5f, 0f) * 2
animateToolbarView(binding.detailNormalToolbar.titleContainer, inRatio)
@@ -167,8 +197,11 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
}
private fun animateToolbarView(view: View?, ratio: Float) {
view?.alpha = ratio
view?.translationY = spacingSmall * (1 - ratio)
if (view == null) {
return
}
view.alpha = ratio
view.translationY = spacingSmall * (1 - ratio)
}
private fun animateToolbarActionButton(view: View?, ratio: Float) {
@@ -195,4 +228,9 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
protected abstract fun onShuffleParent(parent: P)
abstract fun onOpenParentMenu()
private companion object {
const val KEY_DUAL_PANE = BuildConfig.APPLICATION_ID + ".detail.DUAL_PANE"
const val KEY_SCROLLED = BuildConfig.APPLICATION_ID + ".detail.SCROLLED"
}
}
@@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail.decision
import android.view.View
import android.view.ViewGroup
import org.oxycblt.auxio.databinding.ItemPickerChoiceBinding
import org.oxycblt.auxio.list.ClickableListListener
@@ -77,9 +76,9 @@ private constructor(private val binding: ItemPickerChoiceBinding) :
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
fun from(parent: ViewGroup) =
ArtistNavigationChoiceViewHolder(
ItemPickerChoiceBinding.inflate(parent.context.inflater)
ItemPickerChoiceBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
@@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail.list
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.core.view.isInvisible
@@ -29,6 +28,9 @@ import org.oxycblt.auxio.IntegerTable
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
import org.oxycblt.auxio.databinding.ItemDiscHeaderBinding
import org.oxycblt.auxio.detail.list.AlbumSongViewHolder.Companion.from
import org.oxycblt.auxio.detail.list.DiscDividerViewHolder.Companion.from
import org.oxycblt.auxio.detail.list.DiscHeaderViewHolder.Companion.from
import org.oxycblt.auxio.list.Divider
import org.oxycblt.auxio.list.Header
import org.oxycblt.auxio.list.Item
@@ -140,8 +142,11 @@ private class DiscHeaderViewHolder(private val binding: ItemDiscHeaderBinding) :
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
DiscHeaderViewHolder(ItemDiscHeaderBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
DiscHeaderViewHolder(
// TODO: Get all viewholders to inflate anchored to parent
ItemDiscHeaderBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -177,7 +182,7 @@ class DiscDividerViewHolder private constructor(divider: MaterialDivider) :
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) = DiscDividerViewHolder(MaterialDivider(parent.context))
fun from(parent: ViewGroup) = DiscDividerViewHolder(MaterialDivider(parent.context))
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -263,8 +268,10 @@ private class AlbumSongViewHolder private constructor(private val binding: ItemA
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
AlbumSongViewHolder(ItemAlbumSongBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
AlbumSongViewHolder(
ItemAlbumSongBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail.list
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.IntegerTable
@@ -127,8 +126,8 @@ private class ArtistAlbumViewHolder private constructor(private val binding: Ite
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
ArtistAlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
ArtistAlbumViewHolder(ItemParentBinding.inflate(parent.context.inflater, parent, false))
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -179,8 +178,8 @@ private class ArtistSongViewHolder private constructor(private val binding: Item
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
ArtistSongViewHolder(ItemSongBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
ArtistSongViewHolder(ItemSongBinding.inflate(parent.context.inflater, parent, false))
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail.list
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.appcompat.widget.TooltipCompat
@@ -146,8 +145,10 @@ private class SortHeaderViewHolder(private val binding: ItemSortHeaderBinding) :
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
SortHeaderViewHolder(ItemSortHeaderBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
SortHeaderViewHolder(
ItemSortHeaderBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -21,7 +21,6 @@ package org.oxycblt.auxio.detail.list
import android.annotation.SuppressLint
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.appcompat.widget.TooltipCompat
@@ -203,8 +202,10 @@ private class EditHeaderViewHolder private constructor(private val binding: Item
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
EditHeaderViewHolder(ItemEditHeaderBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
EditHeaderViewHolder(
ItemEditHeaderBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK =
@@ -292,8 +293,10 @@ private constructor(private val binding: ItemEditableSongBinding) :
* @param parent The parent to inflate this instance from.
* @return A new instance.
*/
fun from(parent: View) =
PlaylistSongViewHolder(ItemEditableSongBinding.inflate(parent.context.inflater))
fun from(parent: ViewGroup) =
PlaylistSongViewHolder(
ItemEditableSongBinding.inflate(parent.context.inflater, parent, false)
)
/** A comparator that can be used with DiffUtil. */
val DIFF_CALLBACK = SongViewHolder.DIFF_CALLBACK