|
|
@ -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,7 +204,8 @@ 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) |
|
|
|
|
|
|
|
|
|
|
@ -235,8 +235,12 @@ class SearchAdapter( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
@ -269,7 +273,10 @@ class SearchAdapter( |
|
|
|
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 |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -288,7 +295,9 @@ class SearchAdapter( |
|
|
|
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( |
|
|
|
|
|
|
|
Command.AddToPlaylist(listOf(track)) |
|
|
|
|
|
|
|
) |
|
|
|
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) |
|
|
|
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|