|
|
@ -17,9 +17,9 @@ import audio.funkwhale.ffa.databinding.RowSearchHeaderBinding |
|
|
|
import audio.funkwhale.ffa.databinding.RowTrackBinding |
|
|
|
import audio.funkwhale.ffa.databinding.RowTrackBinding |
|
|
|
import audio.funkwhale.ffa.model.Album |
|
|
|
import audio.funkwhale.ffa.model.Album |
|
|
|
import audio.funkwhale.ffa.model.Artist |
|
|
|
import audio.funkwhale.ffa.model.Artist |
|
|
|
|
|
|
|
import audio.funkwhale.ffa.model.Track |
|
|
|
import audio.funkwhale.ffa.utils.Command |
|
|
|
import audio.funkwhale.ffa.utils.Command |
|
|
|
import audio.funkwhale.ffa.utils.CommandBus |
|
|
|
import audio.funkwhale.ffa.utils.CommandBus |
|
|
|
import audio.funkwhale.ffa.model.Track |
|
|
|
|
|
|
|
import audio.funkwhale.ffa.utils.maybeLoad |
|
|
|
import audio.funkwhale.ffa.utils.maybeLoad |
|
|
|
import audio.funkwhale.ffa.utils.maybeNormalizeUrl |
|
|
|
import audio.funkwhale.ffa.utils.maybeNormalizeUrl |
|
|
|
import audio.funkwhale.ffa.utils.onApi |
|
|
|
import audio.funkwhale.ffa.utils.onApi |
|
|
@ -73,20 +73,19 @@ class SearchAdapter( |
|
|
|
|
|
|
|
|
|
|
|
ResultType.Artist.ordinal -> artists[position].id.toLong() |
|
|
|
ResultType.Artist.ordinal -> artists[position].id.toLong() |
|
|
|
ResultType.Artist.ordinal -> albums[position - artists.size - 2].id.toLong() |
|
|
|
ResultType.Artist.ordinal -> albums[position - artists.size - 2].id.toLong() |
|
|
|
ResultType.Track.ordinal -> tracks[position - artists.size - albums.size - sectionCount].id.toLong() |
|
|
|
ResultType.Track.ordinal -> |
|
|
|
|
|
|
|
tracks[position - artists.size - albums.size - sectionCount].id.toLong() |
|
|
|
else -> 0 |
|
|
|
else -> 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int { |
|
|
|
override fun getItemViewType(position: Int): Int = when { |
|
|
|
if (position == 0) return ResultType.Header.ordinal // Artists header |
|
|
|
position == 0 || |
|
|
|
if (position == (artists.size + 1)) return ResultType.Header.ordinal // Albums header |
|
|
|
position == (artists.size + 1) || |
|
|
|
if (position == (artists.size + albums.size + 2)) return ResultType.Header.ordinal // Tracks header |
|
|
|
position == (artists.size + albums.size + 2) -> ResultType.Header.ordinal |
|
|
|
|
|
|
|
position <= artists.size -> ResultType.Artist.ordinal |
|
|
|
if (position <= artists.size) return ResultType.Artist.ordinal |
|
|
|
position <= artists.size + albums.size + 2 -> ResultType.Album.ordinal |
|
|
|
if (position <= artists.size + albums.size + 2) return ResultType.Album.ordinal |
|
|
|
else -> ResultType.Track.ordinal |
|
|
|
|
|
|
|
|
|
|
|
return ResultType.Track.ordinal |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { |
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { |
|
|
@ -205,102 +204,112 @@ class SearchAdapter( |
|
|
|
Typeface.create(searchHeaderViewHolder?.title?.typeface, Typeface.NORMAL) |
|
|
|
Typeface.create(searchHeaderViewHolder?.title?.typeface, Typeface.NORMAL) |
|
|
|
rowTrackViewHolder?.artist?.typeface = |
|
|
|
rowTrackViewHolder?.artist?.typeface = |
|
|
|
Typeface.create(rowTrackViewHolder?.artist?.typeface, Typeface.NORMAL) |
|
|
|
Typeface.create(rowTrackViewHolder?.artist?.typeface, Typeface.NORMAL) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
searchHeaderViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) |
|
|
|
searchHeaderViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0) |
|
|
|
|
|
|
|
|
|
|
|
when (resultType) { |
|
|
|
when (resultType) { |
|
|
|
ResultType.Artist.ordinal -> { |
|
|
|
ResultType.Artist.ordinal -> { |
|
|
|
rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
0, 0, 0, 0 |
|
|
|
0, 0, 0, 0 |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
ResultType.Album.ordinal -> { |
|
|
|
ResultType.Album.ordinal -> { |
|
|
|
rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
0, 0, 0, 0 |
|
|
|
0, 0, 0, 0 |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
ResultType.Track.ordinal -> { |
|
|
|
ResultType.Track.ordinal -> { |
|
|
|
(item as? Track)?.let { track -> |
|
|
|
(item as? Track)?.let { track -> |
|
|
|
context?.let { context -> |
|
|
|
context?.let { context -> |
|
|
|
if (track == currentTrack || track.current) { |
|
|
|
if (track == currentTrack || track.current) { |
|
|
|
searchHeaderViewHolder?.title?.setTypeface( |
|
|
|
searchHeaderViewHolder?.title?.setTypeface( |
|
|
|
searchHeaderViewHolder.title.typeface, |
|
|
|
searchHeaderViewHolder.title.typeface, |
|
|
|
Typeface.BOLD |
|
|
|
Typeface.BOLD |
|
|
|
) |
|
|
|
) |
|
|
|
rowTrackViewHolder?.artist?.setTypeface( |
|
|
|
rowTrackViewHolder?.artist?.setTypeface( |
|
|
|
rowTrackViewHolder.artist.typeface, |
|
|
|
rowTrackViewHolder.artist.typeface, |
|
|
|
Typeface.BOLD |
|
|
|
Typeface.BOLD |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
when (track.favorite) { |
|
|
|
when (track.favorite) { |
|
|
|
true -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorFavorite)) |
|
|
|
true -> rowTrackViewHolder?.favorite?.setColorFilter( |
|
|
|
false -> rowTrackViewHolder?.favorite?.setColorFilter(context.getColor(R.color.colorSelected)) |
|
|
|
context.getColor(R.color.colorFavorite) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
false -> rowTrackViewHolder?.favorite?.setColorFilter( |
|
|
|
|
|
|
|
context.getColor(R.color.colorSelected) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rowTrackViewHolder?.favorite?.setOnClickListener { |
|
|
|
rowTrackViewHolder?.favorite?.setOnClickListener { |
|
|
|
favoriteListener?.let { |
|
|
|
favoriteListener?.let { |
|
|
|
favoriteListener.onToggleFavorite(track.id, !track.favorite) |
|
|
|
favoriteListener.onToggleFavorite(track.id, !track.favorite) |
|
|
|
|
|
|
|
|
|
|
|
tracks[position - artists.size - albums.size - sectionCount].favorite = |
|
|
|
tracks[position - artists.size - albums.size - sectionCount].favorite = |
|
|
|
!track.favorite |
|
|
|
!track.favorite |
|
|
|
|
|
|
|
|
|
|
|
notifyItemChanged(position) |
|
|
|
notifyItemChanged(position) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
when (track.cached || track.downloaded) { |
|
|
|
when (track.cached || track.downloaded) { |
|
|
|
true -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
true -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
R.drawable.downloaded, 0, 0, 0 |
|
|
|
R.drawable.downloaded, 0, 0, 0 |
|
|
|
) |
|
|
|
) |
|
|
|
false -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
false -> rowTrackViewHolder?.title?.setCompoundDrawablesWithIntrinsicBounds( |
|
|
|
0, 0, 0, 0 |
|
|
|
0, 0, 0, 0 |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (track.cached && !track.downloaded) { |
|
|
|
if (track.cached && !track.downloaded) { |
|
|
|
rowTrackViewHolder?.title?.compoundDrawables?.forEach { |
|
|
|
rowTrackViewHolder?.title?.compoundDrawables?.forEach { |
|
|
|
it?.colorFilter = |
|
|
|
it?.colorFilter = |
|
|
|
PorterDuffColorFilter(context.getColor(R.color.cached), PorterDuff.Mode.SRC_IN) |
|
|
|
PorterDuffColorFilter(context.getColor(R.color.cached), PorterDuff.Mode.SRC_IN) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (track.downloaded) { |
|
|
|
if (track.downloaded) { |
|
|
|
rowTrackViewHolder?.title?.compoundDrawables?.forEach { |
|
|
|
rowTrackViewHolder?.title?.compoundDrawables?.forEach { |
|
|
|
it?.colorFilter = |
|
|
|
it?.colorFilter = |
|
|
|
PorterDuffColorFilter(context.getColor(R.color.downloaded), PorterDuff.Mode.SRC_IN) |
|
|
|
PorterDuffColorFilter( |
|
|
|
} |
|
|
|
context.getColor(R.color.downloaded), |
|
|
|
|
|
|
|
PorterDuff.Mode.SRC_IN |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rowTrackViewHolder?.actions?.setOnClickListener { |
|
|
|
rowTrackViewHolder?.actions?.setOnClickListener { |
|
|
|
PopupMenu( |
|
|
|
PopupMenu( |
|
|
|
context, |
|
|
|
context, |
|
|
|
rowTrackViewHolder.actions, |
|
|
|
rowTrackViewHolder.actions, |
|
|
|
Gravity.START, |
|
|
|
Gravity.START, |
|
|
|
R.attr.actionOverflowMenuStyle, |
|
|
|
R.attr.actionOverflowMenuStyle, |
|
|
|
0 |
|
|
|
0 |
|
|
|
).apply { |
|
|
|
).apply { |
|
|
|
inflate(R.menu.row_track) |
|
|
|
inflate(R.menu.row_track) |
|
|
|
|
|
|
|
|
|
|
|
setOnMenuItemClickListener { |
|
|
|
setOnMenuItemClickListener { |
|
|
|
when (it.itemId) { |
|
|
|
when (it.itemId) { |
|
|
|
R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(track))) |
|
|
|
R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(track))) |
|
|
|
R.id.track_play_next -> CommandBus.send(Command.PlayNext(track)) |
|
|
|
R.id.track_play_next -> CommandBus.send(Command.PlayNext(track)) |
|
|
|
R.id.track_pin -> CommandBus.send(Command.PinTrack(track)) |
|
|
|
R.id.track_pin -> CommandBus.send(Command.PinTrack(track)) |
|
|
|
R.id.track_add_to_playlist -> CommandBus.send(Command.AddToPlaylist(listOf(track))) |
|
|
|
R.id.track_add_to_playlist -> CommandBus.send( |
|
|
|
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) |
|
|
|
Command.AddToPlaylist(listOf(track)) |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) |
|
|
|
true |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
show() |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|