Minor nullability/Logging changes
Remove nullables from all the music models, just so that theyre easier to work with, also update Logging at places.
This commit is contained in:
parent
b1be2802cf
commit
ef9d097dc3
6 changed files with 19 additions and 18 deletions
|
@ -28,11 +28,11 @@ val ID3_GENRES = arrayOf<String>(
|
|||
|
||||
const val PAREN_FILTER = "()"
|
||||
|
||||
fun intToNamedGenre(genre: String): String? {
|
||||
fun intToNamedGenre(genre: String): String {
|
||||
// Strip the genres of any parentheses, and convert it to an int
|
||||
val intGenre = genre.filterNot {
|
||||
PAREN_FILTER.indexOf(it) > -1
|
||||
}.toInt()
|
||||
|
||||
return ID3_GENRES.getOrNull(intGenre)
|
||||
return ID3_GENRES.getOrNull(intGenre) ?: ""
|
||||
}
|
||||
|
|
|
@ -75,11 +75,12 @@ class MusicLoader(private val app: Application) {
|
|||
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
var name = cursor.getString(nameIndex)
|
||||
var name = cursor.getString(nameIndex) ?: ""
|
||||
|
||||
// If a genre is still in an old int-based format [Android formats it as "(INT)"],
|
||||
// convert that to the corresponding ID3 genre.
|
||||
if (name.contains("[0-9][()]")) {
|
||||
// convert that to the corresponding ID3 genre. Really hope anyone doesn't have
|
||||
// a genre that contains parentheses.
|
||||
if (name.contains(Regex("[()]"))) {
|
||||
name = intToNamedGenre(name)
|
||||
}
|
||||
|
||||
|
@ -128,7 +129,7 @@ class MusicLoader(private val app: Application) {
|
|||
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
val name = cursor.getString(nameIndex)
|
||||
val name = cursor.getString(nameIndex) ?: ""
|
||||
|
||||
// If an artist has already been added [Which is very likely due to how genres
|
||||
// are processed], add the genre to the existing artist instead of creating a
|
||||
|
@ -191,8 +192,8 @@ class MusicLoader(private val app: Application) {
|
|||
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
val name = cursor.getString(nameIndex)
|
||||
val artist = cursor.getString(artistIndex)
|
||||
val name = cursor.getString(nameIndex) ?: ""
|
||||
val artist = cursor.getString(artistIndex) ?: ""
|
||||
val year = cursor.getInt(yearIndex)
|
||||
val numSongs = cursor.getInt(numIndex)
|
||||
|
||||
|
@ -248,7 +249,7 @@ class MusicLoader(private val app: Application) {
|
|||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(idIndex)
|
||||
val title = cursor.getString(titleIndex) ?: cursor.getString(fileIndex)
|
||||
val album = cursor.getString(albumIndex)
|
||||
val album = cursor.getString(albumIndex) ?: ""
|
||||
val track = cursor.getInt(trackIndex)
|
||||
val duration = cursor.getLong(durationIndex)
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ class MusicSorter(
|
|||
// Any remaining songs will be added to an unknown album
|
||||
if (unknownSongs.size > 0) {
|
||||
|
||||
// Reuse an existing unknown albumif one is found
|
||||
val unknownAlbum = albums.find { it.title == null } ?: Album()
|
||||
// Reuse an existing unknown album if one is found
|
||||
val unknownAlbum = albums.find { it.title == "" } ?: Album()
|
||||
|
||||
unknownAlbum.songs.addAll(unknownSongs)
|
||||
unknownAlbum.numSongs = unknownAlbum.songs.size
|
||||
|
@ -72,7 +72,7 @@ class MusicSorter(
|
|||
if (unknownAlbums.size > 0) {
|
||||
|
||||
// Reuse an existing unknown artist if one is found
|
||||
val unknownArtist = artists.find { it.name == null } ?: Artist()
|
||||
val unknownArtist = artists.find { it.name == "" } ?: Artist()
|
||||
|
||||
unknownArtist.albums.addAll(unknownAlbums)
|
||||
unknownArtist.numAlbums = albums.size
|
||||
|
@ -85,7 +85,7 @@ class MusicSorter(
|
|||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Placed " + unknownAlbums.size.toString() + " albums into an unknown album"
|
||||
"Placed " + unknownAlbums.size.toString() + " albums into an unknown artist"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package org.oxycblt.auxio.music.models
|
|||
// Abstraction for Song
|
||||
data class Album(
|
||||
val id: Long = 0L,
|
||||
val title: String? = null,
|
||||
val artistName: String? = null,
|
||||
val title: String = "",
|
||||
val artistName: String = "",
|
||||
val year: Int = 0,
|
||||
var numSongs: Int = 0
|
||||
) {
|
||||
|
|
|
@ -3,8 +3,8 @@ package org.oxycblt.auxio.music.models
|
|||
// Abstraction for mAlbums
|
||||
data class Artist(
|
||||
val id: Long = 0,
|
||||
val name: String? = null,
|
||||
val genres: MutableList<String?> = mutableListOf(null)
|
||||
val name: String = "",
|
||||
val genres: MutableList<String> = mutableListOf("")
|
||||
) {
|
||||
val albums = mutableListOf<Album>()
|
||||
var numAlbums = 0
|
||||
|
|
|
@ -2,5 +2,5 @@ package org.oxycblt.auxio.music.models
|
|||
|
||||
data class Genre(
|
||||
val id: Long,
|
||||
val name: String?
|
||||
val name: String
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue