Properly handle show filename config
This commit is contained in:
parent
72316119ec
commit
51321e33ca
2 changed files with 15 additions and 16 deletions
|
@ -10,7 +10,6 @@ import kotlin.time.Duration.Companion.milliseconds
|
|||
class AudioHelper(private val context: Context) {
|
||||
|
||||
private val config = context.config
|
||||
private val showFilename = config.showFilename
|
||||
|
||||
fun insertTracks(tracks: List<Track>) {
|
||||
context.tracksDAO.insertAll(tracks)
|
||||
|
@ -22,7 +21,7 @@ class AudioHelper(private val context: Context) {
|
|||
|
||||
fun getAllTracks(): ArrayList<Track> {
|
||||
val tracks = context.tracksDAO.getAll()
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" } as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
|
||||
tracks.sortSafely(config.trackSorting)
|
||||
return tracks
|
||||
|
@ -49,10 +48,7 @@ class AudioHelper(private val context: Context) {
|
|||
|
||||
fun getFolderTracks(folder: String): ArrayList<Track> {
|
||||
val tracks = context.tracksDAO.getTracksFromFolder(folder)
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" }
|
||||
.onEach {
|
||||
it.title = it.getProperTitle(showFilename)
|
||||
} as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
|
||||
tracks.sortSafely(config.getProperFolderSorting(folder))
|
||||
return tracks
|
||||
|
@ -91,7 +87,8 @@ class AudioHelper(private val context: Context) {
|
|||
}
|
||||
|
||||
fun getArtistTracks(artistId: Long): ArrayList<Track> {
|
||||
return context.tracksDAO.getTracksFromArtist(artistId) as ArrayList<Track>
|
||||
return context.tracksDAO.getTracksFromArtist(artistId)
|
||||
.applyProperFilenames(config.showFilename)
|
||||
}
|
||||
|
||||
fun getArtistTracks(artists: List<Artist>): ArrayList<Track> {
|
||||
|
@ -126,14 +123,14 @@ class AudioHelper(private val context: Context) {
|
|||
|
||||
fun getAlbumTracks(albumId: Long): ArrayList<Track> {
|
||||
val tracks = context.tracksDAO.getTracksFromAlbum(albumId)
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" } as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
tracks.sortWith(compareBy({ it.trackId }, { it.title.lowercase() }))
|
||||
return tracks
|
||||
}
|
||||
|
||||
fun getAlbumTracks(albums: List<Album>): ArrayList<Track> {
|
||||
return albums.flatMap { getAlbumTracks(it.id) }
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" } as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
}
|
||||
|
||||
private fun deleteAlbum(id: Long) {
|
||||
|
@ -166,7 +163,7 @@ class AudioHelper(private val context: Context) {
|
|||
|
||||
fun getGenreTracks(genreId: Long): ArrayList<Track> {
|
||||
val tracks = context.tracksDAO.getGenreTracks(genreId)
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" } as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
|
||||
tracks.sortSafely(config.trackSorting)
|
||||
return tracks
|
||||
|
@ -174,7 +171,7 @@ class AudioHelper(private val context: Context) {
|
|||
|
||||
fun getGenreTracks(genres: List<Genre>): ArrayList<Track> {
|
||||
val tracks = genres.flatMap { context.tracksDAO.getGenreTracks(it.id) }
|
||||
.distinctBy { "${it.path}/${it.mediaStoreId}" } as ArrayList<Track>
|
||||
.applyProperFilenames(config.showFilename)
|
||||
|
||||
tracks.sortSafely(config.trackSorting)
|
||||
return tracks
|
||||
|
@ -197,9 +194,8 @@ class AudioHelper(private val context: Context) {
|
|||
}
|
||||
|
||||
fun getPlaylistTracks(playlistId: Int): ArrayList<Track> {
|
||||
val tracks = context.tracksDAO.getTracksFromPlaylist(playlistId).onEach {
|
||||
it.title = it.getProperTitle(showFilename)
|
||||
} as ArrayList<Track>
|
||||
val tracks = context.tracksDAO.getTracksFromPlaylist(playlistId)
|
||||
.applyProperFilenames(config.showFilename)
|
||||
|
||||
tracks.sortSafely(config.getProperPlaylistSorting(playlistId))
|
||||
return tracks
|
||||
|
@ -275,3 +271,8 @@ class AudioHelper(private val context: Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Collection<Track>.applyProperFilenames(showFilename: Int): ArrayList<Track> {
|
||||
return distinctBy { "${it.path}/${it.mediaStoreId}" }
|
||||
.onEach { it.title = it.getProperTitle(showFilename) } as ArrayList<Track>
|
||||
}
|
||||
|
|
|
@ -227,7 +227,6 @@ class SimpleMediaScanner(private val context: Application) {
|
|||
projection.add(Audio.Media.GENRE_ID)
|
||||
}
|
||||
|
||||
val showFilename = config.showFilename
|
||||
context.queryCursor(uri, projection.toTypedArray(), showErrors = true) { cursor ->
|
||||
val id = cursor.getLongValue(Audio.Media._ID)
|
||||
val title = cursor.getStringValue(Audio.Media.TITLE)
|
||||
|
@ -265,7 +264,6 @@ class SimpleMediaScanner(private val context: Application) {
|
|||
coverArt = coverArt, playListId = 0, trackId = trackId, folderName = folderName, albumId = albumId, artistId = artistId, genreId = genreId,
|
||||
year = year, dateAdded = dateAdded, orderInPlaylist = 0
|
||||
)
|
||||
track.title = track.getProperTitle(showFilename)
|
||||
tracks.add(track)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue