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.
|
* 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() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private val playbackModel: PlaybackViewModel by viewModels()
|
private val playbackModel: PlaybackViewModel by viewModels()
|
||||||
|
|
|
@ -22,6 +22,7 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updatePadding
|
import androidx.core.view.updatePadding
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
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.music.Song
|
||||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||||
import org.oxycblt.auxio.util.applyEdge
|
import org.oxycblt.auxio.util.applyEdge
|
||||||
import org.oxycblt.auxio.util.isLandscape
|
|
||||||
import org.oxycblt.auxio.util.logD
|
import org.oxycblt.auxio.util.logD
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,7 @@ class MainFragment : Fragment() {
|
||||||
binding.lifecycleOwner = viewLifecycleOwner
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
binding.applyEdge { bars ->
|
binding.applyEdge { bars ->
|
||||||
binding.root.updatePadding(bottom = bars.bottom)
|
binding.root.updatePadding(bottom = bars.bottom, left = bars.left, right = bars.right)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- VIEWMODEL SETUP ---
|
||||||
|
@ -75,16 +75,6 @@ class MainFragment : Fragment() {
|
||||||
* Handle the visibility of CompactPlaybackFragment. Done here so that there's a nice animation.
|
* Handle the visibility of CompactPlaybackFragment. Done here so that there's a nice animation.
|
||||||
*/
|
*/
|
||||||
private fun handleCompactPlaybackVisibility(binding: FragmentMainBinding, song: Song?) {
|
private fun handleCompactPlaybackVisibility(binding: FragmentMainBinding, song: Song?) {
|
||||||
if (song == null) {
|
binding.mainPlayback.isVisible = 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ class QueueFragment : Fragment() {
|
||||||
binding.lifecycleOwner = viewLifecycleOwner
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
binding.applyEdge { bars ->
|
binding.applyEdge { bars ->
|
||||||
|
binding.root.updatePadding(left = bars.left, right = bars.right)
|
||||||
binding.queueAppbar.updatePadding(top = bars.top)
|
binding.queueAppbar.updatePadding(top = bars.top)
|
||||||
binding.queueRecycler.updatePadding(bottom = bars.bottom)
|
binding.queueRecycler.updatePadding(bottom = bars.bottom)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,15 @@ class SettingsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.applyEdge { bars ->
|
binding.applyEdge { bars ->
|
||||||
|
binding.root.updatePadding(left = bars.left, right = bars.right)
|
||||||
binding.settingsAppbar.updatePadding(top = bars.top)
|
binding.settingsAppbar.updatePadding(top = bars.top)
|
||||||
|
|
||||||
// The padding + clipToPadding method does not seem to work with a
|
// The padding + clipToPadding method does not seem to work with a
|
||||||
// FragmentContainerView. Do it directly in SettingsListFragment instead.
|
// FragmentContainerView. Do it directly in SettingsListFragment instead.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.settingsAppbar.liftOnScrollTargetViewId = androidx.preference.R.id.recycler_view
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,15 +32,16 @@ import androidx.annotation.AttrRes
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
import androidx.annotation.ColorRes
|
import androidx.annotation.ColorRes
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.updatePadding
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.google.android.material.appbar.AppBarLayout
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
import org.oxycblt.auxio.R
|
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].
|
* 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].
|
* Apply edge-to-edge tweaks to the root of a [ViewBinding].
|
||||||
* @param onApply What to do when the system bar insets are provided
|
* @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) {
|
fun View.applyEdge(onApply: (Rect) -> Unit) {
|
||||||
when {
|
when {
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||||
setOnApplyWindowInsetsListener { v, insets ->
|
setOnApplyWindowInsetsListener { _, insets ->
|
||||||
val bars = insets.getInsets(WindowInsets.Type.systemBars()).run {
|
val bars = insets.getInsets(WindowInsets.Type.systemBars()).run {
|
||||||
Rect(left, top, right, bottom)
|
Rect(left, top, right, bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePadding(
|
|
||||||
left = bars.left,
|
|
||||||
right = bars.right
|
|
||||||
)
|
|
||||||
|
|
||||||
onApply(bars)
|
onApply(bars)
|
||||||
|
|
||||||
insets
|
insets
|
||||||
|
@ -201,19 +183,13 @@ fun View.applyEdge(onApply: (Rect) -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> {
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -> {
|
||||||
setOnApplyWindowInsetsListener { v, insets ->
|
setOnApplyWindowInsetsListener { _, insets ->
|
||||||
val bars = insets.run {
|
@Suppress("DEPRECATION")
|
||||||
Rect(
|
val bars = Rect(
|
||||||
systemWindowInsetLeft,
|
insets.systemWindowInsetLeft,
|
||||||
systemWindowInsetTop,
|
insets.systemWindowInsetTop,
|
||||||
systemWindowInsetRight,
|
insets.systemWindowInsetRight,
|
||||||
systemWindowInsetBottom
|
insets.systemWindowInsetBottom
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePadding(
|
|
||||||
left = bars.left,
|
|
||||||
right = bars.right
|
|
||||||
)
|
)
|
||||||
|
|
||||||
onApply(bars)
|
onApply(bars)
|
||||||
|
|
Loading…
Reference in a new issue