Some tracks do not have album, this fixes a crash trying to retrieve their album cover. Changed the placeholder album cover to be less aggressive to the eye.

This commit is contained in:
Antoine POPINEAU 2020-07-11 21:01:09 +02:00
parent 9fb9d45e05
commit ba31a4efcf
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
11 changed files with 18 additions and 14 deletions

View File

@ -358,14 +358,14 @@ class MainActivity : AppCompatActivity() {
now_playing_details_toggle.icon = getDrawable(R.drawable.pause)
Picasso.get()
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
.maybeLoad(maybeNormalizeUrl(track.album?.cover?.original))
.fit()
.centerCrop()
.into(now_playing_cover)
now_playing_details_cover?.let { now_playing_details_cover ->
Picasso.get()
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
.maybeLoad(maybeNormalizeUrl(track.album?.cover?.original))
.fit()
.centerCrop()
.transform(RoundedCornersTransformation(16, 0))
@ -379,7 +379,7 @@ class MainActivity : AppCompatActivity() {
}.widthPixels
val backgroundCover = Picasso.get()
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
.maybeLoad(maybeNormalizeUrl(track.album?.cover?.original))
.get()
.run { Bitmap.createScaledBitmap(this, width, width, false).toDrawable(resources) }
.apply {
@ -410,7 +410,7 @@ class MainActivity : AppCompatActivity() {
setOnMenuItemClickListener {
when (it.itemId) {
R.id.track_info_artist -> ArtistsFragment.openAlbums(this@MainActivity, track.artist, art = track.album.cover.original)
R.id.track_info_artist -> ArtistsFragment.openAlbums(this@MainActivity, track.artist, art = track.album?.cover?.original)
R.id.track_info_album -> AlbumsFragment.openTracks(this@MainActivity, track.album)
R.id.track_info_details -> TrackInfoDetailsFragment.new(track).show(supportFragmentManager, "dialog")
}

View File

@ -44,7 +44,7 @@ class FavoritesAdapter(private val context: Context?, private val favoriteListen
val favorite = data[position]
Picasso.get()
.maybeLoad(maybeNormalizeUrl(favorite.album.cover.original))
.maybeLoad(maybeNormalizeUrl(favorite.album?.cover?.original))
.fit()
.placeholder(R.drawable.cover)
.transform(RoundedCornersTransformation(16, 0))

View File

@ -56,7 +56,7 @@ class PlaylistTracksAdapter(private val context: Context?, private val favoriteL
val track = data[position]
Picasso.get()
.maybeLoad(maybeNormalizeUrl(track.track.album.cover.original))
.maybeLoad(maybeNormalizeUrl(track.track.album?.cover?.original))
.fit()
.placeholder(R.drawable.cover)
.transform(RoundedCornersTransformation(16, 0))

View File

@ -52,7 +52,7 @@ class TracksAdapter(private val context: Context?, private val favoriteListener:
val track = data[position]
Picasso.get()
.maybeLoad(maybeNormalizeUrl(track.album.cover.original))
.maybeLoad(maybeNormalizeUrl(track.album?.cover?.original))
.fit()
.transform(RoundedCornersTransformation(8, 0))
.into(holder.cover)

View File

@ -54,7 +54,11 @@ class AlbumsFragment : OtterFragment<Album, AlbumsAdapter>() {
}
}
fun openTracks(context: Context?, album: Album, fragment: Fragment? = null) {
fun openTracks(context: Context?, album: Album?, fragment: Fragment? = null) {
if (album == null) {
return
}
(context as? MainActivity)?.let {
fragment?.let { fragment ->
fragment.onViewPager {

View File

@ -126,7 +126,7 @@ class PlaylistTracksFragment : OtterFragment<PlaylistTrack, PlaylistTracksAdapte
}
override fun onDataFetched(data: List<PlaylistTrack>) {
data.map { it.track.album }.toSet().map { it.cover.original }.take(4).forEachIndexed { index, url ->
data.map { it.track.album }.toSet().map { it?.cover?.original }.take(4).forEachIndexed { index, url ->
val imageView = when (index) {
0 -> cover_top_left
1 -> cover_top_right

View File

@ -22,7 +22,7 @@ class TrackInfoDetailsFragment : DialogFragment() {
return TrackInfoDetailsFragment().apply {
arguments = bundleOf(
"artistName" to track.artist.name,
"albumTitle" to track.album.title,
"albumTitle" to track.album?.title,
"trackTitle" to track.title,
"trackCopyright" to track.copyright,
"trackLicense" to track.license,

View File

@ -41,7 +41,7 @@ class MediaControlsManager(val context: Service, private val scope: CoroutineSco
val openIntent = Intent(context, MainActivity::class.java).apply { action = NOTIFICATION_ACTION_OPEN_QUEUE.toString() }
val openPendingIntent = PendingIntent.getActivity(context, 0, openIntent, 0)
val coverUrl = maybeNormalizeUrl(track.album.cover.original)
val coverUrl = maybeNormalizeUrl(track.album?.cover?.original)
notification = NotificationCompat.Builder(
context,

View File

@ -342,7 +342,7 @@ class PlayerService : Service() {
private fun buildTrackMetadata(track: Track?): MediaMetadataCompat {
track?.let {
val coverUrl = maybeNormalizeUrl(track.album.cover.original)
val coverUrl = maybeNormalizeUrl(track.album?.cover?.original)
return mediaMetadataBuilder.apply {
putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.title)

View File

@ -99,7 +99,7 @@ data class Track(
val id: Int = 0,
val title: String,
val artist: Artist,
val album: Album,
val album: Album?,
val position: Int = 0,
val uploads: List<Upload> = listOf(),
val copyright: String? = null,
@ -143,7 +143,7 @@ data class Track(
}
}
override fun cover() = album.cover.original
override fun cover() = album?.cover?.original
override fun title() = title
override fun subtitle() = artist.name
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB