Merge branch 'feature/138-track-cover' into 'develop'
Use track cover over album cover if present Closes #138 See merge request funkwhale/funkwhale-android!296
This commit is contained in:
commit
a83cd24185
|
@ -434,7 +434,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
.setListener(null)
|
.setListener(null)
|
||||||
.start()
|
.start()
|
||||||
|
|
||||||
(binding.navHostFragment?.layoutParams as? ViewGroup.MarginLayoutParams)?.let {
|
(binding.navHostFragment.layoutParams as? ViewGroup.MarginLayoutParams)?.let {
|
||||||
it.bottomMargin = it.bottomMargin * 2
|
it.bottomMargin = it.bottomMargin * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,13 +453,13 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
val lic = this.layoutInflater.context
|
val lic = this.layoutInflater.context
|
||||||
|
|
||||||
CoverArt.withContext(lic, maybeNormalizeUrl(track.album?.cover?.urls?.original))
|
CoverArt.withContext(lic, maybeNormalizeUrl(track.cover()))
|
||||||
.fit()
|
.fit()
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(binding.nowPlayingContainer?.nowPlayingCover)
|
.into(binding.nowPlayingContainer?.nowPlayingCover)
|
||||||
|
|
||||||
binding.nowPlayingContainer?.nowPlayingDetailsCover?.let { nowPlayingDetailsCover ->
|
binding.nowPlayingContainer?.nowPlayingDetailsCover?.let { nowPlayingDetailsCover ->
|
||||||
CoverArt.withContext(lic, maybeNormalizeUrl(track.album?.cover()))
|
CoverArt.withContext(lic, maybeNormalizeUrl(track.cover()))
|
||||||
.fit()
|
.fit()
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.transform(RoundedCornersTransformation(16, 0))
|
.transform(RoundedCornersTransformation(16, 0))
|
||||||
|
@ -472,7 +472,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
windowManager.defaultDisplay.getMetrics(this)
|
windowManager.defaultDisplay.getMetrics(this)
|
||||||
}.widthPixels
|
}.widthPixels
|
||||||
|
|
||||||
val backgroundCover = CoverArt.withContext(lic, maybeNormalizeUrl(track.album?.cover()))
|
val backgroundCover = CoverArt.withContext(lic, maybeNormalizeUrl(track.cover()))
|
||||||
.get()
|
.get()
|
||||||
.run { Bitmap.createScaledBitmap(this, width, width, false).toDrawable(resources) }
|
.run { Bitmap.createScaledBitmap(this, width, width, false).toDrawable(resources) }
|
||||||
.apply {
|
.apply {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class FavoritesAdapter(
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val favorite = data[position]
|
val favorite = data[position]
|
||||||
|
|
||||||
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(favorite.album?.cover()))
|
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(favorite.cover()))
|
||||||
.fit()
|
.fit()
|
||||||
.placeholder(R.drawable.cover)
|
.placeholder(R.drawable.cover)
|
||||||
.transform(RoundedCornersTransformation(16, 0))
|
.transform(RoundedCornersTransformation(16, 0))
|
||||||
|
|
|
@ -69,38 +69,38 @@ class PlaylistTracksAdapter(
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val track = data[position]
|
val playlistTrack = data[position]
|
||||||
|
|
||||||
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(track.track.album?.cover()))
|
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(playlistTrack.track.cover()))
|
||||||
.fit()
|
.fit()
|
||||||
.placeholder(R.drawable.cover)
|
.placeholder(R.drawable.cover)
|
||||||
.transform(RoundedCornersTransformation(16, 0))
|
.transform(RoundedCornersTransformation(16, 0))
|
||||||
.into(holder.cover)
|
.into(holder.cover)
|
||||||
|
|
||||||
holder.title.text = track.track.title
|
holder.title.text = playlistTrack.track.title
|
||||||
holder.artist.text = track.track.artist.name
|
holder.artist.text = playlistTrack.track.artist.name
|
||||||
|
|
||||||
context?.let {
|
context?.let {
|
||||||
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.ripple)
|
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.ripple)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (track.track == currentTrack || track.track.current) {
|
if (playlistTrack.track == currentTrack || playlistTrack.track.current) {
|
||||||
context?.let {
|
context?.let {
|
||||||
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.current)
|
holder.itemView.background = ContextCompat.getDrawable(context, R.drawable.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context?.let {
|
context?.let {
|
||||||
when (track.track.favorite) {
|
when (playlistTrack.track.favorite) {
|
||||||
true -> holder.favorite.setColorFilter(context.getColor(R.color.colorFavorite))
|
true -> holder.favorite.setColorFilter(context.getColor(R.color.colorFavorite))
|
||||||
false -> holder.favorite.setColorFilter(context.getColor(R.color.colorSelected))
|
false -> holder.favorite.setColorFilter(context.getColor(R.color.colorSelected))
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.favorite.setOnClickListener {
|
holder.favorite.setOnClickListener {
|
||||||
favoriteListener.let {
|
favoriteListener.let {
|
||||||
favoriteListener.onToggleFavorite(track.track.id, !track.track.favorite)
|
favoriteListener.onToggleFavorite(playlistTrack.track.id, !playlistTrack.track.favorite)
|
||||||
|
|
||||||
track.track.favorite = !track.track.favorite
|
playlistTrack.track.favorite = !playlistTrack.track.favorite
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,11 +115,11 @@ class PlaylistTracksAdapter(
|
||||||
|
|
||||||
setOnMenuItemClickListener {
|
setOnMenuItemClickListener {
|
||||||
when (it.itemId) {
|
when (it.itemId) {
|
||||||
R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(track.track)))
|
R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(playlistTrack.track)))
|
||||||
R.id.track_play_next -> CommandBus.send(Command.PlayNext(track.track))
|
R.id.track_play_next -> CommandBus.send(Command.PlayNext(playlistTrack.track))
|
||||||
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track.track))
|
R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(playlistTrack.track))
|
||||||
R.id.track_remove_from_playlist -> playlistListener.onRemoveTrackFromPlaylist(
|
R.id.track_remove_from_playlist -> playlistListener.onRemoveTrackFromPlaylist(
|
||||||
track.track,
|
playlistTrack.track,
|
||||||
position
|
position
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ class TracksAdapter(
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val track = data[position]
|
val track = data[position]
|
||||||
|
|
||||||
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(track.album?.cover()))
|
CoverArt.withContext(layoutInflater.context, maybeNormalizeUrl(track.cover()))
|
||||||
.fit()
|
.fit()
|
||||||
.transform(RoundedCornersTransformation(8, 0))
|
.transform(RoundedCornersTransformation(8, 0))
|
||||||
.into(holder.cover)
|
.into(holder.cover)
|
||||||
|
|
|
@ -145,7 +145,11 @@ class PlaylistTracksFragment : FFAFragment<PlaylistTrack, PlaylistTracksAdapter>
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDataFetched(data: List<PlaylistTrack>) {
|
override fun onDataFetched(data: List<PlaylistTrack>) {
|
||||||
data.map { it.track.album }.toSet().map { it?.cover() }.take(4).forEachIndexed { index, url ->
|
data.map { it.track.album }
|
||||||
|
.toSet()
|
||||||
|
.map { it?.cover() }
|
||||||
|
.take(4)
|
||||||
|
.forEachIndexed { index, url ->
|
||||||
val imageView = when (index) {
|
val imageView = when (index) {
|
||||||
0 -> binding.coverTopLeft
|
0 -> binding.coverTopLeft
|
||||||
1 -> binding.coverTopRight
|
1 -> binding.coverTopRight
|
||||||
|
|
|
@ -8,7 +8,7 @@ data class Album(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val artist: Artist,
|
val artist: Artist,
|
||||||
val title: String,
|
val title: String,
|
||||||
val cover: Covers?,
|
private val cover: Covers?,
|
||||||
val release_date: String?
|
val release_date: String?
|
||||||
) : SearchResult, Parcelable {
|
) : SearchResult, Parcelable {
|
||||||
@Parcelize
|
@Parcelize
|
||||||
|
|
|
@ -10,6 +10,7 @@ import kotlinx.parcelize.Parcelize
|
||||||
data class Track(
|
data class Track(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
val title: String,
|
val title: String,
|
||||||
|
private val cover: Covers? ,
|
||||||
val artist: Artist,
|
val artist: Artist,
|
||||||
val album: Album?,
|
val album: Album?,
|
||||||
val disc_number: Int = 0,
|
val disc_number: Int = 0,
|
||||||
|
@ -18,6 +19,7 @@ data class Track(
|
||||||
val copyright: String? = null,
|
val copyright: String? = null,
|
||||||
val license: String? = null
|
val license: String? = null
|
||||||
) : SearchResult, Parcelable {
|
) : SearchResult, Parcelable {
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
var current: Boolean = false
|
var current: Boolean = false
|
||||||
|
|
||||||
|
@ -35,6 +37,7 @@ data class Track(
|
||||||
fun fromDownload(download: DownloadInfo): Track = Track(
|
fun fromDownload(download: DownloadInfo): Track = Track(
|
||||||
id = download.id,
|
id = download.id,
|
||||||
title = download.title,
|
title = download.title,
|
||||||
|
cover = Covers(CoverUrls("")),
|
||||||
artist = Artist(0, download.artist, listOf()),
|
artist = Artist(0, download.artist, listOf()),
|
||||||
album = Album(0, Album.Artist(""), "", Covers(CoverUrls("")), ""),
|
album = Album(0, Album.Artist(""), "", Covers(CoverUrls("")), ""),
|
||||||
uploads = listOf(Upload(download.contentId, 0, 0))
|
uploads = listOf(Upload(download.contentId, 0, 0))
|
||||||
|
@ -71,7 +74,14 @@ data class Track(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cover() = album?.cover?.urls?.original
|
override fun cover(): String? {
|
||||||
|
return if (cover?.urls?.original != null) {
|
||||||
|
cover.urls.original
|
||||||
|
} else {
|
||||||
|
album?.cover()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun title() = title
|
override fun title() = title
|
||||||
override fun subtitle() = artist.name
|
override fun subtitle() = artist.name
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package audio.funkwhale.ffa.model
|
||||||
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import strikt.api.expectThat
|
import strikt.api.expectThat
|
||||||
|
import strikt.assertions.isEqualTo
|
||||||
import strikt.assertions.isFalse
|
import strikt.assertions.isFalse
|
||||||
import strikt.assertions.isTrue
|
import strikt.assertions.isTrue
|
||||||
|
|
||||||
|
@ -42,13 +43,33 @@ class TrackTest {
|
||||||
expectThat(createTrackObject(albumTitle = null).matchesFilter("album")).isFalse()
|
expectThat(createTrackObject(albumTitle = null).matchesFilter("album")).isFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun coverReturnsAlbumCoverIfNoTrackCoverExists() {
|
||||||
|
expectThat(
|
||||||
|
createTrackObject(
|
||||||
|
trackCover = null,
|
||||||
|
albumCover = Covers(CoverUrls("albumCover"))
|
||||||
|
).cover()
|
||||||
|
).isEqualTo("albumCover")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun coverReturnsTrackCoverIfTrackCoverExists() {
|
||||||
|
expectThat(
|
||||||
|
createTrackObject(trackCover = Covers(CoverUrls("trackCover"))).cover()
|
||||||
|
).isEqualTo("trackCover")
|
||||||
|
}
|
||||||
|
|
||||||
private fun createTrackObject(
|
private fun createTrackObject(
|
||||||
trackTitle: String = "trackTitle",
|
trackTitle: String = "trackTitle",
|
||||||
artistName: String = "artistName",
|
artistName: String = "artistName",
|
||||||
albumTitle: String? = "albumTitle"
|
albumTitle: String? = "albumTitle",
|
||||||
|
trackCover: Covers? = Covers(urls = CoverUrls(original = "trackCover")),
|
||||||
|
albumCover: Covers? = Covers(urls = CoverUrls(original = "albumCover"))
|
||||||
) = Track(
|
) = Track(
|
||||||
id = 0,
|
id = 0,
|
||||||
title = trackTitle,
|
title = trackTitle,
|
||||||
|
cover = trackCover,
|
||||||
artist = Artist(id = 0, name = artistName, albums = listOf()),
|
artist = Artist(id = 0, name = artistName, albums = listOf()),
|
||||||
album =
|
album =
|
||||||
if (albumTitle == null)
|
if (albumTitle == null)
|
||||||
|
@ -57,7 +78,7 @@ class TrackTest {
|
||||||
id = 0,
|
id = 0,
|
||||||
title = albumTitle,
|
title = albumTitle,
|
||||||
artist = Album.Artist("albumArtist"),
|
artist = Album.Artist("albumArtist"),
|
||||||
cover = null,
|
cover = albumCover,
|
||||||
release_date = null
|
release_date = null
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Use the track cover in an album track list if one is available
|
Loading…
Reference in New Issue