Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: add album and track numbers for artists
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Oct 28, 2023
1 parent 2fa74e3 commit d5d77ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ data class Artist(
val id: String,
val artistsText: String,
val thumbnailUri: Uri? = null,
val description: String? = null
val description: String? = null,
val numberOfTracks: Int? = null,
val numberOfAlbums: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import android.text.format.DateUtils
import android.util.Log
import androidx.core.net.toUri
import app.suhasdissa.vibeyou.backend.data.Album
import app.suhasdissa.vibeyou.backend.data.Artist
Expand Down Expand Up @@ -47,7 +46,7 @@ class LocalMusicRepository(
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.DATE_MODIFIED,
MediaStore.Audio.Media.DATE_ADDED,
MediaStore.Audio.Media.DATE_ADDED
)

val sortOrder = "${MediaStore.Audio.Media.TITLE} ASC"
Expand All @@ -69,7 +68,9 @@ class LocalMusicRepository(
val artistColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)
val albumColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)
val artistIdColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID)
val creationDateColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_MODIFIED)
val creationDateColumn = cursor.getColumnIndexOrThrow(
MediaStore.Audio.Media.DATE_MODIFIED
)
val dateAddedColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATE_ADDED)

while (cursor.moveToNext()) {
Expand Down Expand Up @@ -180,7 +181,7 @@ class LocalMusicRepository(
val artists = mutableListOf<Artist>()

val collection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Audio.Albums.getContentUri(
MediaStore.Audio.Artists.getContentUri(
MediaStore.VOLUME_EXTERNAL
)
} else {
Expand All @@ -190,10 +191,11 @@ class LocalMusicRepository(
val projection = arrayOf(
MediaStore.Audio.Artists._ID,
MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.Artists.Albums.ALBUM_ID
MediaStore.Audio.Artists.NUMBER_OF_ALBUMS,
MediaStore.Audio.Artists.NUMBER_OF_TRACKS
)

val sortOrder = "${MediaStore.Audio.Albums.ALBUM} ASC"
val sortOrder = "${MediaStore.Audio.Artists.ARTIST} ASC"

val query = contentResolver.query(
collection,
Expand All @@ -205,8 +207,10 @@ class LocalMusicRepository(
query?.use { cursor ->
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID)
val artistColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST)
val albumIdColumn =
cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.Albums.ALBUM_ID)
val noOfAlbums =
cursor.getColumnIndexOrThrow(MediaStore.Audio.ArtistColumns.NUMBER_OF_ALBUMS)
val noOfTracks =
cursor.getColumnIndexOrThrow(MediaStore.Audio.ArtistColumns.NUMBER_OF_TRACKS)

while (cursor.moveToNext()) {
val id = cursor.getLong(idColumn)
Expand All @@ -215,7 +219,9 @@ class LocalMusicRepository(
Artist(
id = id.toString(),
artistsText = cursor.getString(artistColumn),
thumbnailUri = getAlbumArt(cursor.getLong(albumIdColumn))
thumbnailUri = null,
numberOfAlbums = cursor.getInt(noOfAlbums),
numberOfTracks = cursor.getInt(noOfTracks)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.suhasdissa.vibeyou.ui.components
import android.view.SoundEffectConstants
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
Expand Down Expand Up @@ -74,6 +75,20 @@ fun ArtistCard(
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
artist.numberOfAlbums?.let {
Text(
text = "${stringResource(id = R.string.albums)} $it",
style = MaterialTheme.typography.bodyMedium
)
}
artist.numberOfTracks?.let {
Text(
text = "${stringResource(id = R.string.songs)} $it",
style = MaterialTheme.typography.bodyMedium
)
}
}
}
}
}

0 comments on commit d5d77ae

Please sign in to comment.