fetch track count at Albums too
This commit is contained in:
parent
d2ab429a90
commit
8991b31f29
3 changed files with 37 additions and 15 deletions
|
@ -16,7 +16,7 @@ import com.simplemobiletools.musicplayer.models.*
|
|||
import com.simplemobiletools.musicplayer.objects.MyExecutor
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
@Database(entities = [Track::class, Playlist::class, QueueItem::class, Artist::class, Album::class], version = 8)
|
||||
@Database(entities = [Track::class, Playlist::class, QueueItem::class, Artist::class, Album::class], version = 9)
|
||||
abstract class SongsDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun SongsDao(): SongsDao
|
||||
|
@ -53,6 +53,7 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
.addMigrations(MIGRATION_5_6)
|
||||
.addMigrations(MIGRATION_6_7)
|
||||
.addMigrations(MIGRATION_7_8)
|
||||
.addMigrations(MIGRATION_8_9)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -76,11 +77,15 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
private val MIGRATION_1_2 = object : Migration(1, 2) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("CREATE TABLE songs_new (media_store_id INTEGER NOT NULL, title TEXT NOT NULL, artist TEXT NOT NULL, path TEXT NOT NULL, duration INTEGER NOT NULL, " +
|
||||
"album TEXT NOT NULL, playlist_id INTEGER NOT NULL, PRIMARY KEY(path, playlist_id))")
|
||||
execSQL(
|
||||
"CREATE TABLE songs_new (media_store_id INTEGER NOT NULL, title TEXT NOT NULL, artist TEXT NOT NULL, path TEXT NOT NULL, duration INTEGER NOT NULL, " +
|
||||
"album TEXT NOT NULL, playlist_id INTEGER NOT NULL, PRIMARY KEY(path, playlist_id))"
|
||||
)
|
||||
|
||||
execSQL("INSERT INTO songs_new (media_store_id, title, artist, path, duration, album, playlist_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, playlist_id FROM songs")
|
||||
execSQL(
|
||||
"INSERT INTO songs_new (media_store_id, title, artist, path, duration, album, playlist_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, playlist_id FROM songs"
|
||||
)
|
||||
|
||||
execSQL("DROP TABLE songs")
|
||||
execSQL("ALTER TABLE songs_new RENAME TO songs")
|
||||
|
@ -107,11 +112,15 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
private val MIGRATION_4_5 = object : Migration(4, 5) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("CREATE TABLE songs_new (media_store_id INTEGER NOT NULL, title TEXT NOT NULL, artist TEXT NOT NULL, path TEXT NOT NULL, duration INTEGER NOT NULL, " +
|
||||
"album TEXT NOT NULL, cover_art TEXT default '' NOT NULL, playlist_id INTEGER NOT NULL, track_id INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(media_store_id, playlist_id))")
|
||||
execSQL(
|
||||
"CREATE TABLE songs_new (media_store_id INTEGER NOT NULL, title TEXT NOT NULL, artist TEXT NOT NULL, path TEXT NOT NULL, duration INTEGER NOT NULL, " +
|
||||
"album TEXT NOT NULL, cover_art TEXT default '' NOT NULL, playlist_id INTEGER NOT NULL, track_id INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(media_store_id, playlist_id))"
|
||||
)
|
||||
|
||||
execSQL("INSERT OR IGNORE INTO songs_new (media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id FROM songs")
|
||||
execSQL(
|
||||
"INSERT OR IGNORE INTO songs_new (media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id FROM songs"
|
||||
)
|
||||
|
||||
execSQL("DROP TABLE songs")
|
||||
execSQL("ALTER TABLE songs_new RENAME TO tracks")
|
||||
|
@ -123,11 +132,15 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
private val MIGRATION_5_6 = object : Migration(5, 6) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.apply {
|
||||
execSQL("CREATE TABLE tracks_new (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `media_store_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `artist` TEXT NOT NULL, `path` TEXT NOT NULL, `duration` INTEGER NOT NULL, " +
|
||||
"`album` TEXT NOT NULL, `cover_art` TEXT default '' NOT NULL, `playlist_id` INTEGER NOT NULL, `track_id` INTEGER NOT NULL DEFAULT 0)")
|
||||
execSQL(
|
||||
"CREATE TABLE tracks_new (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `media_store_id` INTEGER NOT NULL, `title` TEXT NOT NULL, `artist` TEXT NOT NULL, `path` TEXT NOT NULL, `duration` INTEGER NOT NULL, " +
|
||||
"`album` TEXT NOT NULL, `cover_art` TEXT default '' NOT NULL, `playlist_id` INTEGER NOT NULL, `track_id` INTEGER NOT NULL DEFAULT 0)"
|
||||
)
|
||||
|
||||
execSQL("INSERT OR IGNORE INTO tracks_new (media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id FROM tracks")
|
||||
execSQL(
|
||||
"INSERT OR IGNORE INTO tracks_new (media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id) " +
|
||||
"SELECT media_store_id, title, artist, path, duration, album, cover_art, playlist_id, track_id FROM tracks"
|
||||
)
|
||||
|
||||
execSQL("DROP TABLE tracks")
|
||||
execSQL("ALTER TABLE tracks_new RENAME TO tracks")
|
||||
|
@ -154,5 +167,11 @@ abstract class SongsDatabase : RoomDatabase() {
|
|||
database.execSQL("ALTER TABLE tracks ADD COLUMN folder_name TEXT default '' NOT NULL")
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_8_9 = object : Migration(8, 9) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE albums ADD COLUMN track_cnt INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,8 @@ fun Context.getAlbumsSync(artist: Artist): ArrayList<Album> {
|
|||
val title = cursor.getStringValue(Audio.Albums.ALBUM)
|
||||
val coverArt = ContentUris.withAppendedId(artworkUri, id).toString()
|
||||
val year = cursor.getIntValue(Audio.Albums.FIRST_YEAR)
|
||||
val album = Album(id, artistName, title, coverArt, year)
|
||||
val trackCnt = getAlbumTracksCount(id)
|
||||
val album = Album(id, artistName, title, coverArt, year, trackCnt)
|
||||
albums.add(album)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@ data class Album(
|
|||
@ColumnInfo(name = "artist") val artist: String,
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "cover_art") val coverArt: String,
|
||||
@ColumnInfo(name = "year") val year: Int) : ListItem(), Comparable<Album> {
|
||||
@ColumnInfo(name = "year") val year: Int,
|
||||
@ColumnInfo(name = "track_cnt") var trackCnt: Int
|
||||
) : ListItem(), Comparable<Album> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue