ui: fix landscape problems
Once again fix annoying issues that arise from the quirks of phone landscape mode. A lot of these fixes can be re-rolled back into the edge-to-edge code eventually, but it requires fitsSystemWindows to be phased out entirely.
This commit is contained in:
parent
a4d2a8d48c
commit
047b885dca
5 changed files with 21 additions and 49 deletions
|
@ -37,7 +37,9 @@ import org.oxycblt.auxio.util.logD
|
|||
|
||||
/**
|
||||
* The single [AppCompatActivity] for Auxio.
|
||||
* TODO: Improve edge-to-edge everywhere
|
||||
* TODO: Improve edge-to-edge everywhere and phase out fitsSystemWindows.
|
||||
* If you do this, then it will become trivial to merge a lot of the code [l/r padding],
|
||||
* fitsSystemWindow management into this activity.
|
||||
*/
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private val playbackModel: PlaybackViewModel by viewModels()
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
|
@ -29,7 +30,6 @@ import org.oxycblt.auxio.databinding.FragmentMainBinding
|
|||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.util.applyEdge
|
||||
import org.oxycblt.auxio.util.isLandscape
|
||||
import org.oxycblt.auxio.util.logD
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ class MainFragment : Fragment() {
|
|||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.applyEdge { bars ->
|
||||
binding.root.updatePadding(bottom = bars.bottom)
|
||||
binding.root.updatePadding(bottom = bars.bottom, left = bars.left, right = bars.right)
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
@ -75,16 +75,6 @@ class MainFragment : Fragment() {
|
|||
* Handle the visibility of CompactPlaybackFragment. Done here so that there's a nice animation.
|
||||
*/
|
||||
private fun handleCompactPlaybackVisibility(binding: FragmentMainBinding, song: Song?) {
|
||||
if (song == null) {
|
||||
logD("Hiding CompactPlaybackFragment since no song is being played.")
|
||||
|
||||
binding.mainPlayback.visibility = if (requireContext().isLandscape()) {
|
||||
View.INVISIBLE
|
||||
} else {
|
||||
View.GONE
|
||||
}
|
||||
} else {
|
||||
binding.mainPlayback.visibility = View.VISIBLE
|
||||
}
|
||||
binding.mainPlayback.isVisible = song != null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ class QueueFragment : Fragment() {
|
|||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.applyEdge { bars ->
|
||||
binding.root.updatePadding(left = bars.left, right = bars.right)
|
||||
binding.queueAppbar.updatePadding(top = bars.top)
|
||||
binding.queueRecycler.updatePadding(bottom = bars.bottom)
|
||||
}
|
||||
|
|
|
@ -55,12 +55,15 @@ class SettingsFragment : Fragment() {
|
|||
}
|
||||
|
||||
binding.applyEdge { bars ->
|
||||
binding.root.updatePadding(left = bars.left, right = bars.right)
|
||||
binding.settingsAppbar.updatePadding(top = bars.top)
|
||||
|
||||
// The padding + clipToPadding method does not seem to work with a
|
||||
// FragmentContainerView. Do it directly in SettingsListFragment instead.
|
||||
}
|
||||
|
||||
binding.settingsAppbar.liftOnScrollTargetViewId = androidx.preference.R.id.recycler_view
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,16 @@ import androidx.annotation.AttrRes
|
|||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import org.oxycblt.auxio.R
|
||||
|
||||
// TODO: Make a helper AppBarLayout of some kind that auto-updates the lifted state. I know
|
||||
// what to do, it's just hard to make it work correctly.
|
||||
|
||||
/**
|
||||
* Apply the recommended spans for a [RecyclerView].
|
||||
*
|
||||
|
@ -155,20 +156,6 @@ fun AppBarLayout.makeScrollingViewFade(view: View) {
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-update this [AppBarLayout]'s lifted state. This is useful when the dataset changes
|
||||
* and the lifted state must be updated.
|
||||
*/
|
||||
fun AppBarLayout.updateLiftedState(recycler: RecyclerView) {
|
||||
post {
|
||||
val coordinator = (parent as CoordinatorLayout)
|
||||
|
||||
(layoutParams as CoordinatorLayout.LayoutParams).behavior?.onNestedPreScroll(
|
||||
coordinator, this, recycler, 0, 0, IntArray(2), 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply edge-to-edge tweaks to the root of a [ViewBinding].
|
||||
* @param onApply What to do when the system bar insets are provided
|
||||
|
@ -184,16 +171,11 @@ fun ViewBinding.applyEdge(onApply: (Rect) -> Unit) {
|
|||
fun View.applyEdge(onApply: (Rect) -> Unit) {
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
setOnApplyWindowInsetsListener { v, insets ->
|
||||
setOnApplyWindowInsetsListener { _, insets ->
|
||||
val bars = insets.getInsets(WindowInsets.Type.systemBars()).run {
|
||||
Rect(left, top, right, bottom)
|
||||
}
|
||||
|
||||
updatePadding(
|
||||
left = bars.left,
|
||||
right = bars.right
|
||||
)
|
||||
|
||||
onApply(bars)
|
||||
|
||||
insets
|
||||
|
@ -201,19 +183,13 @@ fun View.applyEdge(onApply: (Rect) -> Unit) {
|
|||
}
|
||||
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> {
|
||||
setOnApplyWindowInsetsListener { v, insets ->
|
||||
val bars = insets.run {
|
||||
Rect(
|
||||
systemWindowInsetLeft,
|
||||
systemWindowInsetTop,
|
||||
systemWindowInsetRight,
|
||||
systemWindowInsetBottom
|
||||
)
|
||||
}
|
||||
|
||||
updatePadding(
|
||||
left = bars.left,
|
||||
right = bars.right
|
||||
setOnApplyWindowInsetsListener { _, insets ->
|
||||
@Suppress("DEPRECATION")
|
||||
val bars = Rect(
|
||||
insets.systemWindowInsetLeft,
|
||||
insets.systemWindowInsetTop,
|
||||
insets.systemWindowInsetRight,
|
||||
insets.systemWindowInsetBottom
|
||||
)
|
||||
|
||||
onApply(bars)
|
||||
|
|
Loading…
Reference in a new issue