Add landscape support to list fragments
Add a landscape mode for LibraryFragment & SongsFragment.
This commit is contained in:
@@ -12,6 +12,7 @@ import androidx.core.view.forEach
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.transition.Fade
|
||||
import androidx.transition.TransitionManager
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -23,10 +24,12 @@ import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.utils.applyColor
|
||||
import org.oxycblt.auxio.utils.isLandscape
|
||||
import org.oxycblt.auxio.utils.resolveAttr
|
||||
import org.oxycblt.auxio.utils.setupAlbumActions
|
||||
import org.oxycblt.auxio.utils.setupArtistActions
|
||||
@@ -92,7 +95,6 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
searchView.maxWidth = Int.MAX_VALUE
|
||||
searchView.setOnQueryTextListener(this@LibraryFragment)
|
||||
searchView.setOnQueryTextFocusChangeListener { _, hasFocus ->
|
||||
libraryModel.updateSearchFocusStatus(hasFocus)
|
||||
item.isVisible = !hasFocus
|
||||
}
|
||||
|
||||
@@ -100,6 +102,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
|
||||
binding.libraryRecycler.adapter = searchAdapter
|
||||
setGroupVisible(R.id.group_sorting, false)
|
||||
|
||||
libraryModel.resetQuery()
|
||||
|
||||
return true
|
||||
@@ -108,6 +111,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
|
||||
binding.libraryRecycler.adapter = libraryAdapter
|
||||
setGroupVisible(R.id.group_sorting, true)
|
||||
|
||||
libraryModel.resetQuery()
|
||||
|
||||
return true
|
||||
@@ -119,6 +123,19 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
binding.libraryRecycler.apply {
|
||||
adapter = libraryAdapter
|
||||
setHasFixedSize(true)
|
||||
|
||||
if (isLandscape(resources)) {
|
||||
layoutManager = GridLayoutManager(requireContext(), GridLayoutManager.VERTICAL).apply {
|
||||
spanCount = 3
|
||||
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
|
||||
} else 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
@@ -128,7 +145,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
|
||||
libraryModel.searchResults.observe(viewLifecycleOwner) {
|
||||
if (libraryModel.searchHasFocus) {
|
||||
if (binding.libraryRecycler.adapter == searchAdapter) {
|
||||
searchAdapter.submitList(it) {
|
||||
binding.libraryRecycler.scrollToPosition(0)
|
||||
}
|
||||
|
||||
@@ -34,10 +34,6 @@ class LibraryViewModel : ViewModel(), SettingsManager.Callback {
|
||||
|
||||
private var mIsNavigating = false
|
||||
val isNavigating: Boolean get() = mIsNavigating
|
||||
|
||||
private var mSearchHasFocus = false
|
||||
val searchHasFocus: Boolean get() = mSearchHasFocus
|
||||
|
||||
private val settingsManager = SettingsManager.getInstance()
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
|
||||
@@ -111,10 +107,6 @@ class LibraryViewModel : ViewModel(), SettingsManager.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSearchFocusStatus(value: Boolean) {
|
||||
mSearchHasFocus = value
|
||||
}
|
||||
|
||||
fun resetQuery() {
|
||||
mSearchResults.value = listOf()
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class MusicStore private constructor() {
|
||||
*/
|
||||
suspend fun load(app: Application): MusicLoaderResponse {
|
||||
return withContext(Dispatchers.IO) {
|
||||
logD("Starting initial music load...")
|
||||
this@MusicStore.logD("Starting initial music load...")
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
@@ -83,7 +83,7 @@ class MusicStore private constructor() {
|
||||
|
||||
val elapsed = System.currentTimeMillis() - start
|
||||
|
||||
logD("Music load completed successfully in ${elapsed}ms.")
|
||||
this@MusicStore.logD("Music load completed successfully in ${elapsed}ms.")
|
||||
|
||||
loaded = true
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ class MusicLoader(
|
||||
}.toMutableList()
|
||||
|
||||
// Then try to associate any genres with their respective artists.
|
||||
// TODO: This is already querying all genre songs, just move it.
|
||||
for (genre in genres) {
|
||||
val artistGenreCursor = resolver.query(
|
||||
Genres.Members.getContentUri("external", genre.id),
|
||||
@@ -155,7 +156,6 @@ class MusicLoader(
|
||||
|
||||
artistGenreCursor?.let { cursor ->
|
||||
val idIndex = cursor.getColumnIndexOrThrow(Genres.Members.ARTIST_ID)
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
||||
import com.reddit.indicatorfastscroll.FastScrollerView
|
||||
@@ -17,6 +18,7 @@ import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.utils.isLandscape
|
||||
import org.oxycblt.auxio.utils.setupSongActions
|
||||
import kotlin.math.ceil
|
||||
|
||||
@@ -70,6 +72,12 @@ class SongsFragment : Fragment() {
|
||||
adapter = songAdapter
|
||||
setHasFixedSize(true)
|
||||
|
||||
if (isLandscape(resources)) {
|
||||
layoutManager = GridLayoutManager(requireContext(), GridLayoutManager.VERTICAL).also {
|
||||
it.spanCount = 3
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
if (computeVerticalScrollRange() < height) {
|
||||
binding.songFastScroll.visibility = View.GONE
|
||||
|
||||
Reference in New Issue
Block a user