Update landscape functionality

Make some changes that differentiate how Auxio is displayed on phone vs. landscape devices.
This commit is contained in:
OxygenCobalt 2020-12-29 15:18:11 -07:00
parent 8fe0734ca1
commit 8a92108a4a
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
9 changed files with 276 additions and 13 deletions

View file

@ -30,6 +30,7 @@ import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.ui.applyColor
import org.oxycblt.auxio.ui.getLandscapeSpans
import org.oxycblt.auxio.ui.isLandscape
import org.oxycblt.auxio.ui.resolveAttr
import org.oxycblt.auxio.ui.setupAlbumActions
@ -129,12 +130,13 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
setHasFixedSize(true)
if (isLandscape(resources)) {
layoutManager = GridLayoutManager(requireContext(), GridLayoutManager.VERTICAL).apply {
spanCount = 3
val spans = getLandscapeSpans(resources)
layoutManager = GridLayoutManager(requireContext(), spans).apply {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (binding.libraryRecycler.adapter == searchAdapter) {
if (searchAdapter.currentList[position] is Header) 3 else 1
if (searchAdapter.currentList[position] is Header) spans else 1
} else 1
}
}
@ -173,7 +175,11 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
if (it != null) {
libraryModel.updateNavigationStatus(false)
onItemSelection(it)
if (it is Song) {
onItemSelection(it.album)
} else {
onItemSelection(it)
}
}
}

View file

@ -174,8 +174,6 @@ class LibraryViewModel : ViewModel(), SettingsManager.Callback {
DisplayMode.SHOW_ALBUMS -> {
mSortMode.value!!.getSortedAlbumList(musicStore.albums)
}
else -> error("Unsupported Library DisplayMode $mDisplayMode")
}
}
}

View file

@ -241,11 +241,11 @@ class PlaybackStateManager private constructor() {
* @param song The song to play
* @param dontPlay (Optional, defaults to false) whether to not set [isPlaying] to true.
*/
private fun updatePlayback(song: Song, dontPlay: Boolean = false) {
private fun updatePlayback(song: Song) {
mSong = song
mPosition = 0
if (!mIsPlaying && !dontPlay) {
if (!mIsPlaying) {
setPlayingStatus(true)
}
@ -341,8 +341,14 @@ class PlaybackStateManager private constructor() {
mIndex = 0
forceQueueUpdate()
updatePlayback(mQueue[0], dontPlay = true)
// The whole point here is making the playback pause and loop, so duplicate
// the updatePlayback code instead of using it with a useless arg tacked on.
mSong = mQueue[0]
mPosition = 0
setPlayingStatus(false)
mIsInUserQueue = false
}
SettingsManager.EntryValues.AT_END_LOOP -> {

View file

@ -10,7 +10,7 @@ import org.oxycblt.auxio.R
enum class DisplayMode(@DrawableRes val iconRes: Int) {
SHOW_GENRES(R.drawable.ic_genre),
SHOW_ARTISTS(R.drawable.ic_artist),
SHOW_ALBUMS(R.drawable.ic_album),
SHOW_ALBUMS(R.drawable.ic_album);
/**
* Make a slice of all the values that this DisplayMode covers.

View file

@ -22,6 +22,7 @@ import org.oxycblt.auxio.music.MusicStore
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.getLandscapeSpans
import org.oxycblt.auxio.ui.isLandscape
import org.oxycblt.auxio.ui.setupSongActions
import org.oxycblt.auxio.ui.toColor
@ -81,8 +82,10 @@ class SongsFragment : Fragment() {
setHasFixedSize(true)
if (isLandscape(resources)) {
val spans = getLandscapeSpans(resources)
layoutManager = GridLayoutManager(requireContext(), GridLayoutManager.VERTICAL).also {
it.spanCount = 3
it.spanCount = spans
}
}
@ -151,7 +154,7 @@ class SongsFragment : Fragment() {
var isGood = true
if (concatInterval == -1) {
// If the screen size is too small to contain all the entries, truncate entries
// If the scroller size is too small to contain all the entries, truncate entries
// so that the fast scroller entries fit.
val maxEntries = (height / (indicatorTextSize + textPadding))

View file

@ -14,7 +14,6 @@ import android.view.WindowManager
/**
* Check if we are in the "Irregular" landscape mode [e.g landscape, but nav bar is on the sides]
* Used to disable most of edge-to-edge if that's the case, as I cant get it to work on this mode yet.
* TODO: Make edge-to-edge work better in irregular mode
* @return True if we are in the irregular landscape mode, false if not.
*/
fun Activity.isIrregularLandscape(): Boolean {

View file

@ -55,6 +55,14 @@ fun isLandscape(resources: Resources): Boolean {
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
/**
* Get the span count for most RecyclerViews when in landscape mode.
* @return 3 if landscape mode is tablet, 2 if landscape mode is phone
*/
fun getLandscapeSpans(resources: Resources): Int {
return if (resources.configuration.screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE) 3 else 2
}
/**
* Create a [Toast] from a [String]
* @param context [Context] required to create the toast

View file

@ -0,0 +1,242 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".playback.PlaybackFragment">
<data>
<variable
name="song"
type="org.oxycblt.auxio.music.Song" />
<variable
name="playbackModel"
type="org.oxycblt.auxio.playback.PlaybackViewModel" />
<variable
name="detailModel"
type="org.oxycblt.auxio.detail.DetailViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/playback_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/background"
android:fitsSystemWindows="true">
<androidx.appcompat.widget.Toolbar
android:id="@+id/playback_toolbar"
style="@style/Toolbar.Style.Icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:menu="@menu/menu_playback"
app:navigationIcon="@drawable/ic_down"
app:title="@string/label_playback" />
<ImageView
android:id="@+id/playback_cover"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_insane"
android:layout_marginBottom="@dimen/margin_insane"
android:contentDescription="@{@string/description_album_cover(song.name)}"
android:elevation="@dimen/elevation_normal"
android:outlineProvider="bounds"
app:coverArt="@{song}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/playback_toolbar"
tools:src="@drawable/ic_song" />
<!-- TextView is wrapped in a container so that marquee doesn't break -->
<FrameLayout
android:id="@+id/playback_song_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_mid_large"
android:layout_marginEnd="@dimen/margin_mid_large"
app:layout_constraintBottom_toTopOf="@+id/playback_artist"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@+id/playback_cover"
app:layout_constraintTop_toBottomOf="@+id/playback_toolbar"
app:layout_constraintVertical_chainStyle="packed">
<TextView
android:id="@+id/playback_song"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:fontFamily="@font/inter_semibold"
android:marqueeRepeatLimit="marquee_forever"
android:onClick="@{() -> detailModel.navToItem(playbackModel.song)}"
android:singleLine="true"
android:text="@{song.name}"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
tools:text="Song Name" />
</FrameLayout>
<TextView
android:id="@+id/playback_artist"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_mid_large"
android:layout_marginEnd="@dimen/margin_mid_large"
android:ellipsize="end"
android:onClick="@{() -> detailModel.navToItem(playbackModel.song.album.artist)}"
android:singleLine="true"
android:text="@{song.album.artist.name}"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toTopOf="@+id/playback_album"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/playback_cover"
app:layout_constraintTop_toBottomOf="@+id/playback_song_container"
tools:text="Artist Name" />
<TextView
android:id="@+id/playback_album"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_mid_large"
android:layout_marginEnd="@dimen/margin_mid_large"
android:ellipsize="end"
android:onClick="@{() -> detailModel.navToItem(playbackModel.song.album)}"
android:singleLine="true"
android:text="@{song.album.name}"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toTopOf="@+id/playback_seek_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/playback_cover"
app:layout_constraintTop_toBottomOf="@+id/playback_artist"
tools:text="Album Name" />
<SeekBar
android:id="@+id/playback_seek_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:clickable="true"
android:focusable="true"
android:paddingStart="@dimen/margin_mid_large"
android:paddingEnd="@dimen/margin_mid_large"
android:progressBackgroundTint="?android:attr/colorControlNormal"
android:progressTint="?attr/colorPrimary"
android:splitTrack="false"
android:thumbOffset="@dimen/offset_thumb"
android:thumbTint="?attr/colorPrimary"
app:layout_constraintBottom_toTopOf="@+id/playback_duration_current"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/playback_cover"
app:layout_constraintTop_toBottomOf="@+id/playback_album"
tools:progress="70" />
<TextView
android:id="@+id/playback_duration_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_mid_large"
app:layout_constraintBottom_toTopOf="@+id/playback_play_pause"
app:layout_constraintStart_toEndOf="@+id/playback_cover"
app:layout_constraintTop_toBottomOf="@+id/playback_seek_bar"
tools:text="11:38" />
<TextView
android:id="@+id/playback_song_container_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_mid_large"
android:text="@{song.formattedDuration}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/playback_seek_bar"
tools:text="16:16" />
<ImageButton
android:id="@+id/playback_play_pause"
android:layout_width="@dimen/size_play_pause"
android:layout_height="@dimen/size_play_pause"
android:layout_marginStart="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_medium"
android:layout_marginEnd="@dimen/margin_large"
android:background="@drawable/ui_circular_button"
android:backgroundTint="?attr/colorPrimary"
android:contentDescription="@{playbackModel.isPlaying ? @string/description_pause : @string/description_play}"
android:foregroundTint="@color/background"
android:onClick="@{() -> playbackModel.invertPlayingStatus()}"
android:tint="@color/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/playback_skip_next"
app:layout_constraintStart_toEndOf="@+id/playback_skip_prev"
app:layout_constraintTop_toBottomOf="@+id/playback_duration_current"
tools:src="@drawable/ic_play_to_pause" />
<ImageButton
android:id="@+id/playback_skip_next"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/size_play_pause_compact"
android:layout_height="@dimen/size_play_pause_compact"
android:layout_marginEnd="@dimen/margin_large"
android:background="@drawable/ui_unbounded_ripple"
android:contentDescription="@string/description_skip_next"
android:onClick="@{() -> playbackModel.skipNext()}"
android:src="@drawable/ic_skip_next_large"
app:layout_constraintBottom_toBottomOf="@+id/playback_play_pause"
app:layout_constraintEnd_toStartOf="@+id/playback_shuffle"
app:layout_constraintStart_toEndOf="@+id/playback_play_pause"
app:layout_constraintTop_toTopOf="@+id/playback_play_pause" />
<ImageButton
android:id="@+id/playback_skip_prev"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/size_play_pause_compact"
android:layout_height="@dimen/size_play_pause_compact"
android:layout_marginStart="@dimen/margin_large"
android:background="@drawable/ui_unbounded_ripple"
android:contentDescription="@string/description_skip_prev"
android:onClick="@{() -> playbackModel.skipPrev()}"
android:src="@drawable/ic_skip_prev_large"
app:layout_constraintBottom_toBottomOf="@+id/playback_play_pause"
app:layout_constraintEnd_toStartOf="@+id/playback_play_pause"
app:layout_constraintStart_toEndOf="@+id/playback_loop"
app:layout_constraintTop_toTopOf="@+id/playback_play_pause" />
<ImageButton
android:id="@+id/playback_shuffle"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/size_play_pause_compact"
android:layout_height="@dimen/size_play_pause_compact"
android:background="@drawable/ui_unbounded_ripple"
android:contentDescription="@{playbackModel.isShuffling() ? @string/description_shuffle_off : @string/description_shuffle_on"
android:onClick="@{() -> playbackModel.invertShuffleStatus()}"
android:src="@drawable/ic_shuffle_large"
app:layout_constraintBottom_toBottomOf="@+id/playback_skip_next"
app:layout_constraintEnd_toEndOf="@+id/playback_song_container_duration"
app:layout_constraintStart_toEndOf="@+id/playback_skip_next"
app:layout_constraintTop_toTopOf="@+id/playback_skip_next" />
<ImageButton
android:id="@+id/playback_loop"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/size_play_pause_compact"
android:layout_height="@dimen/size_play_pause_compact"
android:background="@drawable/ui_unbounded_ripple"
android:contentDescription="@string/description_change_loop"
android:onClick="@{() -> playbackModel.incrementLoopStatus()}"
android:src="@drawable/ic_loop_large"
app:layout_constraintBottom_toBottomOf="@+id/playback_skip_prev"
app:layout_constraintEnd_toStartOf="@+id/playback_skip_prev"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="@+id/playback_duration_current"
app:layout_constraintTop_toTopOf="@+id/playback_skip_prev" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -11,6 +11,7 @@
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_mid_large">24dp</dimen>
<dimen name="margin_large">32dp</dimen>
<dimen name="margin_insane">128dp</dimen>
<!-- Height Namespace | Height for UI elements -->
<dimen name="height_compact_progress">2dp</dimen>