Update landscape functionality
Make some changes that differentiate how Auxio is displayed on phone vs. landscape devices.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,8 +174,6 @@ class LibraryViewModel : ViewModel(), SettingsManager.Callback {
|
||||
DisplayMode.SHOW_ALBUMS -> {
|
||||
mSortMode.value!!.getSortedAlbumList(musicStore.albums)
|
||||
}
|
||||
|
||||
else -> error("Unsupported Library DisplayMode $mDisplayMode")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 -> {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user