Updated references to context_menu_track to correctly identify events

Additionally updated event handler to correctly play, queue, pin and
download songs now that events are triggering correctly.
This commit is contained in:
Cem Eren 2022-03-05 00:10:20 +01:00
parent 7dd479c0d2
commit eb0fa67431
No known key found for this signature in database
GPG Key ID: 8110307C31E795FF
1 changed files with 67 additions and 32 deletions

View File

@ -46,6 +46,7 @@ import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.EntryByDiscAndTrackComparator import org.moire.ultrasonic.util.EntryByDiscAndTrackComparator
import org.moire.ultrasonic.util.Settings import org.moire.ultrasonic.util.Settings
import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util
import org.moire.ultrasonic.util.Util.toast
/** /**
* Displays a group of tracks, eg. the songs of an album, of a playlist etc. * Displays a group of tracks, eg. the songs of an album, of a playlist etc.
@ -619,56 +620,80 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
menuItem: MenuItem, menuItem: MenuItem,
item: MusicDirectory.Child item: MusicDirectory.Child
): Boolean { ): Boolean {
val entryId = item.id val songs = getClickedSong(item)
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.menu_play_now -> { R.id.song_menu_play_now -> {
downloadHandler.downloadRecursively( downloadHandler.download(
this, entryId, save = false, append = false, fragment = this,
autoPlay = true, shuffle = false, background = false, append = false,
playNext = false, unpin = false, isArtist = false save = false,
autoPlay = true,
playNext = false,
shuffle = false,
songs = songs
) )
} }
R.id.menu_play_next -> { R.id.song_menu_play_next -> {
downloadHandler.downloadRecursively( downloadHandler.download(
this, entryId, save = false, append = false, fragment = this,
autoPlay = false, shuffle = false, background = false, append = true,
playNext = true, unpin = false, isArtist = false save = false,
autoPlay = false,
playNext = true,
shuffle = false,
songs = songs
) )
} }
R.id.menu_play_last -> { R.id.song_menu_play_last -> {
downloadHandler.downloadRecursively( downloadHandler.download(
this, entryId, save = false, append = true, fragment = this,
autoPlay = false, shuffle = false, background = false, append = true,
playNext = false, unpin = false, isArtist = false save = false,
autoPlay = false,
playNext = false,
shuffle = false,
songs = songs
) )
} }
R.id.menu_pin -> { R.id.song_menu_pin -> {
downloadHandler.downloadRecursively( toast(
this, entryId, save = true, append = true, context,
autoPlay = false, shuffle = false, background = false, resources.getQuantityString(
playNext = false, unpin = false, isArtist = false R.plurals.select_album_n_songs_pinned,
songs.size,
songs.size
)
) )
downloadBackground(true, songs)
} }
R.id.menu_unpin -> { R.id.song_menu_unpin -> {
downloadHandler.downloadRecursively( toast(
this, entryId, save = false, append = false, context,
autoPlay = false, shuffle = false, background = false, resources.getQuantityString(
playNext = false, unpin = true, isArtist = false R.plurals.select_album_n_songs_unpinned,
songs.size,
songs.size
)
) )
mediaPlayerController.unpin(songs)
} }
R.id.menu_download -> { R.id.song_menu_download -> {
downloadHandler.downloadRecursively( toast(
this, entryId, save = false, append = false, context,
autoPlay = false, shuffle = false, background = true, resources.getQuantityString(
playNext = false, unpin = false, isArtist = false R.plurals.select_album_n_songs_downloaded,
songs.size,
songs.size
)
) )
downloadBackground(false, songs)
} }
R.id.select_album_play_all -> { R.id.select_album_play_all -> {
// TODO: Why is this being handled here?! // TODO: Why is this being handled here?!
playAll() playAll()
} }
R.id.menu_item_share -> { R.id.song_menu_share -> {
if (item is MusicDirectory.Entry) { if (item is MusicDirectory.Entry) {
shareHandler.createShare( shareHandler.createShare(
this, listOf(item), refreshListView, this, listOf(item), refreshListView,
@ -683,6 +708,16 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
return true return true
} }
internal fun getClickedSong(item: MusicDirectory.Child): List<MusicDirectory.Entry> {
//This can probably be done better
return viewAdapter.getCurrentList().mapNotNull {
if (it is MusicDirectory.Entry && (it.id == item.id))
it
else
null
}
}
override fun onItemClick(item: MusicDirectory.Child) { override fun onItemClick(item: MusicDirectory.Child) {
when { when {
item.isDirectory -> { item.isDirectory -> {