main: band-aid split screen mode layouts

Split screen layouts in android are completely borked. You can
resize Auxio down to the point where the UI is completely
unusable, and there is NO WAY TO SET A MINIMUM HEIGHT. This is
also not to mention that smallestScreenWidthDp is completely
busted too and still uses the size of the whole screen! Just
band-aid the first issue so that when the layout becomes so
small as to result in a messed up UI, just show a splash that
says that the app can't work at the specific window size.
This commit is contained in:
OxygenCobalt
2021-12-17 17:00:19 -07:00
parent bae997018d
commit 2d3fc47d7c
7 changed files with 77 additions and 16 deletions
@@ -28,6 +28,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.updatePadding
import androidx.databinding.DataBindingUtil
import androidx.viewbinding.ViewBinding
import org.oxycblt.auxio.accent.Accent
import org.oxycblt.auxio.databinding.ActivityMainBinding
import org.oxycblt.auxio.playback.PlaybackViewModel
@@ -114,7 +115,7 @@ class MainActivity : AppCompatActivity() {
}
}
private fun applyEdgeToEdgeWindow(binding: ActivityMainBinding) {
private fun applyEdgeToEdgeWindow(binding: ViewBinding) {
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!
@@ -147,7 +148,7 @@ class MainActivity : AppCompatActivity() {
}
}
private fun WindowInsets.applyLeftRightInsets(binding: ActivityMainBinding): WindowInsets {
private fun WindowInsets.applyLeftRightInsets(binding: ViewBinding): WindowInsets {
val bars = systemBarsCompat
binding.root.updatePadding(
@@ -19,6 +19,7 @@
package org.oxycblt.auxio
import android.Manifest
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -73,6 +74,22 @@ class MainFragment : Fragment() {
}
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// Auxio's layout completely breaks down when it's window is resized too small,
// but for some insane reason google decided to cripple the window APIs one could use
// to limit it's size. So, we just have our own special layout that is shown whenever
// the screen is too small because nothing works the way it should and everything
// is broken.
if (requireActivity().isInMultiWindowMode) {
val config = resources.configuration
if (config.screenHeightDp < 250 || config.screenWidthDp < 250) {
binding.layoutTooSmall.visibility = View.VISIBLE
}
}
}
// --- VIEWMODEL SETUP ---
// We have to control the bar view from here since using a Fragment in PlaybackLayout
@@ -164,9 +164,15 @@ class PlaybackLayout @JvmOverloads constructor(
// Make sure we add our fragment to this view. This is actually a replace operation
// since we don't want to stack fragments but we can't ensure that this view doesn't
// already have a fragment attached.
(context as AppCompatActivity).supportFragmentManager.beginTransaction()
.replace(R.id.playback_panel, playbackFragment)
.commit()
try {
(context as AppCompatActivity).supportFragmentManager.beginTransaction()
.replace(R.id.playback_panel, playbackFragment)
.commit()
} catch (e: Exception) {
// Band-aid to stop the app crashing if we have to swap out the content view
// without warning (which we have to do sometimes because android is the worst
// thing ever
}
}
}