Browse Source

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.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
ba31a4efcf
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 8
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  2. 2
      app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt
  3. 2
      app/src/main/java/com/github/apognu/otter/adapters/PlaylistTracksAdapter.kt
  4. 2
      app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt
  5. 6
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt
  6. 2
      app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt
  7. 2
      app/src/main/java/com/github/apognu/otter/fragments/TrackInfoDetailsFragment.kt
  8. 2
      app/src/main/java/com/github/apognu/otter/playback/MediaControlsManager.kt
  9. 2
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  10. 4
      app/src/main/java/com/github/apognu/otter/utils/Models.kt
  11. BIN
      app/src/main/res/drawable/cover.png

8
app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt

@ -358,14 +358,14 @@ class MainActivity : AppCompatActivity() { @@ -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() { @@ -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() { @@ -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")
}

2
app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt

@ -44,7 +44,7 @@ class FavoritesAdapter(private val context: Context?, private val favoriteListen @@ -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))

2
app/src/main/java/com/github/apognu/otter/adapters/PlaylistTracksAdapter.kt

@ -56,7 +56,7 @@ class PlaylistTracksAdapter(private val context: Context?, private val favoriteL @@ -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))

2
app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt

@ -52,7 +52,7 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: @@ -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)

6
app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt

@ -54,7 +54,11 @@ class AlbumsFragment : OtterFragment<Album, AlbumsAdapter>() { @@ -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 {

2
app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt

@ -126,7 +126,7 @@ class PlaylistTracksFragment : OtterFragment<PlaylistTrack, PlaylistTracksAdapte @@ -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

2
app/src/main/java/com/github/apognu/otter/fragments/TrackInfoDetailsFragment.kt

@ -22,7 +22,7 @@ class TrackInfoDetailsFragment : DialogFragment() { @@ -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,

2
app/src/main/java/com/github/apognu/otter/playback/MediaControlsManager.kt

@ -41,7 +41,7 @@ class MediaControlsManager(val context: Service, private val scope: CoroutineSco @@ -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,

2
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -342,7 +342,7 @@ class PlayerService : Service() { @@ -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)

4
app/src/main/java/com/github/apognu/otter/utils/Models.kt

@ -99,7 +99,7 @@ data class Track( @@ -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( @@ -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
}

BIN
app/src/main/res/drawable/cover.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save