Add option to play song from genre
Add the option to play a song from a genre.
This commit is contained in:
@@ -41,9 +41,8 @@ import org.oxycblt.auxio.ui.setupSongActions
|
||||
/**
|
||||
* A [Fragment] that shows a custom list of [Genre], [Artist], or [Album] data. Also allows for
|
||||
* search functionality.
|
||||
* TODO: Move search to separate tab?
|
||||
* FIXME: Leak when navving from search
|
||||
* FIXME: Leak on older versions
|
||||
* FIXME: Heisenleak when navving from search
|
||||
* FIXME: Heisen on older versions
|
||||
*/
|
||||
class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
|
||||
@@ -59,13 +58,13 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
val binding = FragmentLibraryBinding.inflate(inflater)
|
||||
|
||||
val libraryAdapter = LibraryAdapter(
|
||||
doOnClick = { onItemSelection(it) },
|
||||
doOnLongClick = { data, view -> showActionsForItem(data, view) }
|
||||
doOnClick = this::onItemSelection,
|
||||
doOnLongClick = this::showActionsForItem
|
||||
)
|
||||
|
||||
val searchAdapter = SearchAdapter(
|
||||
doOnClick = { onItemSelection(it) },
|
||||
doOnLongClick = { data, view -> showActionsForItem(data, view) }
|
||||
doOnClick = this::onItemSelection,
|
||||
doOnLongClick = this::showActionsForItem
|
||||
)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentQueueBinding
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
@@ -106,13 +107,7 @@ class QueueFragment : Fragment() {
|
||||
val queue = mutableListOf<BaseModel>()
|
||||
|
||||
if (playbackModel.userQueue.value!!.isNotEmpty()) {
|
||||
queue.add(
|
||||
Header(
|
||||
id = 0,
|
||||
name = getString(R.string.label_next_user_queue),
|
||||
isAction = true
|
||||
)
|
||||
)
|
||||
queue.add(Header(id = 0, name = getString(R.string.label_next_user_queue), isAction = true))
|
||||
queue.addAll(playbackModel.userQueue.value!!)
|
||||
}
|
||||
|
||||
@@ -120,13 +115,7 @@ class QueueFragment : Fragment() {
|
||||
queue.add(
|
||||
Header(
|
||||
id = 1,
|
||||
name = getString(
|
||||
R.string.format_next_from,
|
||||
if (playbackModel.mode.value == PlaybackMode.ALL_SONGS)
|
||||
getString(R.string.label_all_songs)
|
||||
else
|
||||
playbackModel.parent.value!!.name
|
||||
),
|
||||
name = getString(R.string.format_next_from, getParentName()),
|
||||
isAction = false
|
||||
)
|
||||
)
|
||||
@@ -135,4 +124,17 @@ class QueueFragment : Fragment() {
|
||||
|
||||
return queue
|
||||
}
|
||||
|
||||
private fun getParentName(): String {
|
||||
return if (playbackModel.mode.value == PlaybackMode.ALL_SONGS) {
|
||||
getString(R.string.label_all_songs)
|
||||
} else {
|
||||
if (playbackModel.parent.value is Genre) {
|
||||
// Since t
|
||||
(playbackModel.parent.value as Genre).displayName
|
||||
} else {
|
||||
playbackModel.parent.value!!.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ class SongsAdapter(
|
||||
private val doOnLongClick: (data: Song, view: View) -> Unit
|
||||
) : RecyclerView.Adapter<SongsAdapter.SongViewHolder>() {
|
||||
|
||||
private var currentSong: Song? = null
|
||||
private var lastHolder: Highlightable? = null
|
||||
/* private var currentSong: Song? = null
|
||||
private var lastHolder: Highlightable? = null*/
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
@@ -37,7 +37,7 @@ class SongsAdapter(
|
||||
override fun onBindViewHolder(holder: SongViewHolder, position: Int) {
|
||||
holder.bind(data[position])
|
||||
|
||||
if (currentSong != null) {
|
||||
/* if (currentSong != null) {
|
||||
if (data[position].id == currentSong?.id) {
|
||||
// Reset the last ViewHolder before assigning the new, correct one to be highlighted
|
||||
lastHolder?.setHighlighted(false)
|
||||
@@ -46,17 +46,17 @@ class SongsAdapter(
|
||||
} else {
|
||||
holder.setHighlighted(false)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
fun setCurrentSong(song: Song?) {
|
||||
/* fun setCurrentSong(song: Song?) {
|
||||
// Clear out the last ViewHolder as a song update usually signifies that this current
|
||||
// ViewHolder is likely invalid.
|
||||
lastHolder?.setHighlighted(false)
|
||||
lastHolder = null
|
||||
|
||||
currentSong = song
|
||||
}
|
||||
}*/
|
||||
|
||||
inner class SongViewHolder(
|
||||
private val binding: ItemSongBinding
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.recycler.Highlightable
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
@@ -33,6 +32,8 @@ import kotlin.math.ceil
|
||||
/**
|
||||
* A [Fragment] that shows a list of all songs on the device. Contains options to search/shuffle
|
||||
* them.
|
||||
* TODO: Search
|
||||
* TODO: Sorting
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class SongsFragment : Fragment() {
|
||||
@@ -105,9 +106,11 @@ class SongsFragment : Fragment() {
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
/*
|
||||
Unused, not needed for SongsFragment
|
||||
TODO: Move this code over to AlbumDetailFragment
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (playbackModel.mode.value == PlaybackMode.ALL_SONGS) {
|
||||
logD(playbackModel.isInUserQueue.toString())
|
||||
songAdapter.setCurrentSong(song)
|
||||
|
||||
lastHolder?.setHighlighted(false)
|
||||
@@ -126,16 +129,24 @@ class SongsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Clear the viewholders if the mode isnt ALL_SONGS
|
||||
songAdapter.setCurrentSong(null)
|
||||
|
||||
lastHolder?.setHighlighted(false)
|
||||
lastHolder = null
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.isInUserQueue.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
// Remove any highlighted ViewHolders if the playback is in the user queue.
|
||||
songAdapter.setCurrentSong(null)
|
||||
lastHolder?.setHighlighted(false)
|
||||
lastHolder = null
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
setupFastScroller(binding)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user