Fix landscape issues with MainFragment
Make MainFragment & CompactPlaybackFragment look better in landscape mode.
This commit is contained in:
@@ -21,6 +21,7 @@ import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.utils.accent
|
||||
import org.oxycblt.auxio.utils.getTransparentAccent
|
||||
import org.oxycblt.auxio.utils.isLandscape
|
||||
import org.oxycblt.auxio.utils.toColor
|
||||
import kotlin.IllegalArgumentException
|
||||
|
||||
@@ -155,7 +156,11 @@ class MainFragment : Fragment() {
|
||||
if (song == null) {
|
||||
logD("Hiding CompactPlaybackFragment since no song is being played.")
|
||||
|
||||
binding.compactPlayback.visibility = View.GONE
|
||||
// Dont hide if the mode is landscape.
|
||||
if (!isLandscape(resources)) {
|
||||
binding.compactPlayback.visibility = View.GONE
|
||||
}
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
} else {
|
||||
binding.compactPlayback.visibility = View.VISIBLE
|
||||
|
||||
@@ -37,11 +37,14 @@ class CompactPlaybackFragment : Fragment() {
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
// Put a placeholder song in the binding & hide the playback fragment initially,
|
||||
// just in case.
|
||||
// Put a placeholder song in the binding & hide the playback fragment initially.
|
||||
binding.song = MusicStore.getInstance().songs[0]
|
||||
binding.playbackModel = playbackModel
|
||||
|
||||
if (playbackModel.song.value == null) {
|
||||
hideAll(binding)
|
||||
}
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
findNavController().navigate(
|
||||
MainFragmentDirections.actionGoToPlayback()
|
||||
@@ -59,8 +62,12 @@ class CompactPlaybackFragment : Fragment() {
|
||||
if (it != null) {
|
||||
logD("Updating song display to ${it.name}")
|
||||
|
||||
showAll(binding)
|
||||
|
||||
binding.song = it
|
||||
binding.playbackProgress.max = it.seconds.toInt()
|
||||
} else {
|
||||
hideAll(binding)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,4 +121,34 @@ class CompactPlaybackFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all UI elements, and disable the fragment from being clickable.
|
||||
*/
|
||||
private fun hideAll(binding: FragmentCompactPlaybackBinding) {
|
||||
binding.apply {
|
||||
root.isEnabled = false
|
||||
|
||||
playbackCover.visibility = View.INVISIBLE
|
||||
playbackSong.visibility = View.INVISIBLE
|
||||
playbackInfo.visibility = View.INVISIBLE
|
||||
playbackControls.visibility = View.INVISIBLE
|
||||
playbackProgress.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhide all UI elements, and make the fragment clickable.
|
||||
*/
|
||||
private fun showAll(binding: FragmentCompactPlaybackBinding) {
|
||||
binding.apply {
|
||||
root.isEnabled = true
|
||||
|
||||
playbackCover.visibility = View.VISIBLE
|
||||
playbackSong.visibility = View.VISIBLE
|
||||
playbackInfo.visibility = View.VISIBLE
|
||||
playbackControls.visibility = View.VISIBLE
|
||||
playbackProgress.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
@@ -55,6 +56,13 @@ fun ImageButton.disable(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the device is currently in landscape.
|
||||
*/
|
||||
fun isLandscape(resources: Resources): Boolean {
|
||||
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a [Toast] from a [String]
|
||||
* @param context [Context] required to create the toast
|
||||
|
||||
Reference in New Issue
Block a user