fetch Artist and Album IDs as longs, not just ints
This commit is contained in:
parent
3c3edd941c
commit
5b4099a8c9
6 changed files with 18 additions and 15 deletions
|
@ -64,9 +64,9 @@ class AlbumsAdapter(activity: SimpleActivity, var albums: ArrayList<Album>, recy
|
|||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = albums.getOrNull(position)?.id
|
||||
override fun getItemSelectionKey(position: Int) = albums.getOrNull(position)?.hashCode()
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = albums.indexOfFirst { it.id == key }
|
||||
override fun getItemKeyPosition(key: Int) = albums.indexOfFirst { it.hashCode() == key }
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
|
@ -117,7 +117,7 @@ class AlbumsAdapter(activity: SimpleActivity, var albums: ArrayList<Album>, recy
|
|||
|
||||
private fun setupView(view: View, album: Album) {
|
||||
view.apply {
|
||||
album_frame?.isSelected = selectedKeys.contains(album.id)
|
||||
album_frame?.isSelected = selectedKeys.contains(album.hashCode())
|
||||
album_title.text = if (textToHighlight.isEmpty()) album.title else album.title.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
album_title.setTextColor(textColor)
|
||||
|
||||
|
|
|
@ -67,9 +67,9 @@ class ArtistsAdapter(activity: SimpleActivity, var artists: ArrayList<Artist>, r
|
|||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = artists.getOrNull(position)?.id
|
||||
override fun getItemSelectionKey(position: Int) = artists.getOrNull(position)?.hashCode()
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = artists.indexOfFirst { it.id == key }
|
||||
override fun getItemKeyPosition(key: Int) = artists.indexOfFirst { it.hashCode() == key }
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class ArtistsAdapter(activity: SimpleActivity, var artists: ArrayList<Artist>, r
|
|||
|
||||
private fun setupView(view: View, artist: Artist) {
|
||||
view.apply {
|
||||
artist_frame?.isSelected = selectedKeys.contains(artist.id)
|
||||
artist_frame?.isSelected = selectedKeys.contains(artist.hashCode())
|
||||
artist_title.text = if (textToHighlight.isEmpty()) artist.title else artist.title.highlightTextPart(textToHighlight, adjustedPrimaryColor)
|
||||
artist_title.setTextColor(textColor)
|
||||
|
||||
|
|
|
@ -7,7 +7,10 @@ import androidx.room.RoomDatabase
|
|||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.*
|
||||
import com.simplemobiletools.musicplayer.extensions.getAlbumTracksSync
|
||||
import com.simplemobiletools.musicplayer.extensions.getAlbumsSync
|
||||
import com.simplemobiletools.musicplayer.extensions.getArtistsSync
|
||||
import com.simplemobiletools.musicplayer.extensions.playlistDAO
|
||||
import com.simplemobiletools.musicplayer.helpers.ALL_TRACKS_PLAYLIST_ID
|
||||
import com.simplemobiletools.musicplayer.helpers.RoomHelper
|
||||
import com.simplemobiletools.musicplayer.interfaces.PlaylistsDao
|
||||
|
|
|
@ -141,7 +141,7 @@ fun Context.getArtistsSync(): ArrayList<Artist> {
|
|||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getIntValue(Audio.Artists._ID)
|
||||
val id = cursor.getLongValue(Audio.Artists._ID)
|
||||
val title = cursor.getStringValue(Audio.Artists.ARTIST)
|
||||
var artist = Artist(id, title, 0, 0, 0)
|
||||
artist = fillArtistExtras(this, artist)
|
||||
|
@ -188,7 +188,7 @@ private fun fillArtistExtras(context: Context, artist: Artist): Artist {
|
|||
artist.albumArtId = albumId
|
||||
}
|
||||
|
||||
artist.trackCnt += context.getAlbumTracksSync(albumId.toInt()).size
|
||||
artist.trackCnt += context.getAlbumTracksSync(albumId).size
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
|
|||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
val id = cursor.getIntValue(Audio.Albums._ID)
|
||||
val id = cursor.getLongValue(Audio.Albums._ID)
|
||||
val artistName = cursor.getStringValue(Audio.Albums.ARTIST)
|
||||
val title = cursor.getStringValue(Audio.Albums.ALBUM)
|
||||
val coverArt = ContentUris.withAppendedId(artworkUri, id.toLong()).toString()
|
||||
|
@ -245,14 +245,14 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
|
|||
return albums
|
||||
}
|
||||
|
||||
fun Context.getAlbumTracks(albumId: Int, callback: (tracks: ArrayList<Track>) -> Unit) {
|
||||
fun Context.getAlbumTracks(albumId: Long, callback: (tracks: ArrayList<Track>) -> Unit) {
|
||||
ensureBackgroundThread {
|
||||
val tracks = getAlbumTracksSync(albumId)
|
||||
callback(tracks)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getAlbumTracksSync(albumId: Int): ArrayList<Track> {
|
||||
fun Context.getAlbumTracksSync(albumId: Long): ArrayList<Track> {
|
||||
val tracks = ArrayList<Track>()
|
||||
val uri = Audio.Media.EXTERNAL_CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
|
@ -266,7 +266,7 @@ fun Context.getAlbumTracksSync(albumId: Int): ArrayList<Track> {
|
|||
|
||||
val selection = "${Audio.Albums.ALBUM_ID} = ?"
|
||||
val selectionArgs = arrayOf(albumId.toString())
|
||||
val coverUri = ContentUris.withAppendedId(artworkUri, albumId.toLong())
|
||||
val coverUri = ContentUris.withAppendedId(artworkUri, albumId)
|
||||
var coverArt = ""
|
||||
|
||||
// check if the album art file exists at all
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package com.simplemobiletools.musicplayer.models
|
||||
|
||||
data class Album(val id: Int, val artist: String, val title: String, val coverArt: String, val year: Int): ListItem()
|
||||
data class Album(val id: Long, val artist: String, val title: String, val coverArt: String, val year: Int): ListItem()
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package com.simplemobiletools.musicplayer.models
|
||||
|
||||
data class Artist(val id: Int, val title: String, var albumCnt: Int, var trackCnt: Int, var albumArtId: Long)
|
||||
data class Artist(val id: Long, val title: String, var albumCnt: Int, var trackCnt: Int, var albumArtId: Long)
|
||||
|
|
Loading…
Reference in a new issue