store album cover art in the class itself

This commit is contained in:
tibbi 2020-10-05 12:55:38 +02:00
parent 48cf2dcc15
commit 4cd25f9b7f
4 changed files with 8 additions and 9 deletions

View file

@ -41,8 +41,8 @@ class AlbumsActivity : SimpleActivity() {
var tracksSectionLabel = resources.getQuantityString(R.plurals.tracks, tracksToAdd.size, tracksToAdd.size)
tracksSectionLabel += "${trackFullDuration.getFormattedDuration(true)}"
listItems.add(AlbumSection(tracksSectionLabel))
listItems.addAll(tracksToAdd)
runOnUiThread {
AlbumsAdapter(this, listItems, albums_list) {
if (it is Album) {

View file

@ -1,7 +1,5 @@
package com.simplemobiletools.musicplayer.adapters
import android.content.ContentUris
import android.net.Uri
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -94,14 +92,11 @@ class AlbumsAdapter(activity: SimpleActivity, val items: ArrayList<ListItem>, re
album_title.text = album.title
album_title.setTextColor(textColor)
val artworkUri = Uri.parse("content://media/external/audio/albumart")
val albumArtUri = ContentUris.withAppendedId(artworkUri, album.id.toLong())
val options = RequestOptions()
.transform(CenterCrop(), RoundedCorners(16))
Glide.with(activity)
.load(albumArtUri)
.load(album.coverArt)
.apply(options)
.into(findViewById(R.id.album_image))
}

View file

@ -1,8 +1,10 @@
package com.simplemobiletools.musicplayer.extensions
import android.annotation.SuppressLint
import android.content.ContentUris
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.MediaStore.Audio
import android.util.TypedValue
import com.simplemobiletools.commons.extensions.getIntValue
@ -127,6 +129,7 @@ fun Context.getAlbums(artist: Artist, callback: (artists: ArrayList<Album>) -> U
fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
val albums = ArrayList<Album>()
val artworkUri = Uri.parse("content://media/external/audio/albumart")
val uri = Audio.Albums.EXTERNAL_CONTENT_URI
val projection = arrayOf(
Audio.Albums._ID,
@ -149,7 +152,8 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
val id = cursor.getIntValue(Audio.Albums._ID)
val artistName = cursor.getStringValue(Audio.Albums.ARTIST)
val title = cursor.getStringValue(Audio.Albums.ALBUM)
val album = Album(id, artistName, title)
val coverArt = ContentUris.withAppendedId(artworkUri, id.toLong())
val album = Album(id, artistName, title, coverArt.toString())
albums.add(album)
} while (cursor.moveToNext())
}

View file

@ -1,3 +1,3 @@
package com.simplemobiletools.musicplayer.models
data class Album(val id: Int, val artist: String, val title: String): ListItem()
data class Album(val id: Int, val artist: String, val title: String, val coverArt: String): ListItem()