music: handle compilation flag tags
Handle COMPILATION and ITUNESCOMPILATION flags, if present. Just map these to Various Artists and a compilation release type. Resolves #373.
This commit is contained in:
@@ -32,6 +32,7 @@ import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* A [DetailHeaderAdapter] that shows [Album] information.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class AlbumDetailHeaderAdapter(private val listener: Listener) :
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* A [DetailHeaderAdapter] that shows [Artist] information.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class ArtistDetailHeaderAdapter(private val listener: Listener) :
|
||||
|
||||
@@ -35,6 +35,7 @@ abstract class DetailHeaderAdapter<T : MusicParent, VH : RecyclerView.ViewHolder
|
||||
|
||||
/**
|
||||
* Bind the created header [RecyclerView.ViewHolder] with the current [parent].
|
||||
*
|
||||
* @param holder The [RecyclerView.ViewHolder] to bind.
|
||||
* @param parent The current [MusicParent] to bind.
|
||||
*/
|
||||
@@ -42,6 +43,7 @@ abstract class DetailHeaderAdapter<T : MusicParent, VH : RecyclerView.ViewHolder
|
||||
|
||||
/**
|
||||
* Update the [MusicParent] shown in the header.
|
||||
*
|
||||
* @param parent The new [MusicParent] to show.
|
||||
*/
|
||||
fun setParent(parent: T) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* A [DetailHeaderAdapter] that shows [Genre] information.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class GenreDetailHeaderAdapter(private val listener: Listener) :
|
||||
|
||||
@@ -24,7 +24,6 @@ import androidx.recyclerview.widget.*
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import java.util.concurrent.Executor
|
||||
import org.oxycblt.auxio.util.logD
|
||||
|
||||
/**
|
||||
* A variant of ListDiffer with more flexible updates.
|
||||
@@ -35,8 +34,7 @@ import org.oxycblt.auxio.util.logD
|
||||
abstract class FlexibleListAdapter<T, VH : RecyclerView.ViewHolder>(
|
||||
diffCallback: DiffUtil.ItemCallback<T>
|
||||
) : RecyclerView.Adapter<VH>() {
|
||||
@Suppress("LeakingThis")
|
||||
private val differ = FlexibleListDiffer(this, diffCallback)
|
||||
@Suppress("LeakingThis") private val differ = FlexibleListDiffer(this, diffCallback)
|
||||
final override fun getItemCount() = differ.currentList.size
|
||||
/** The current list stored by the adapter's differ instance. */
|
||||
val currentList: List<T>
|
||||
@@ -55,8 +53,7 @@ abstract class FlexibleListAdapter<T, VH : RecyclerView.ViewHolder>(
|
||||
newData: List<T>,
|
||||
instructions: UpdateInstructions?,
|
||||
callback: (() -> Unit)? = null
|
||||
) =
|
||||
differ.update(newData, instructions, callback)
|
||||
) = differ.update(newData, instructions, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -157,6 +157,12 @@ private constructor(private val rawSong: RawSong, private val future: Future<Tra
|
||||
|
||||
// Genre
|
||||
textFrames["TCON"]?.let { rawSong.genreNames = it }
|
||||
|
||||
// Compilation Flag
|
||||
(textFrames["TXXX:compilation"] ?: textFrames["TXXX:itunescompilation"])?.let {
|
||||
rawSong.albumArtistNames = rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
|
||||
rawSong.releaseTypes = rawSong.releaseTypes.ifEmpty { COMPILATION_RELEASE_TYPES }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,6 +263,12 @@ private constructor(private val rawSong: RawSong, private val future: Future<Tra
|
||||
|
||||
// Genre
|
||||
comments["genre"]?.let { rawSong.genreNames = it }
|
||||
|
||||
// Compilation Flag
|
||||
(comments["compilation"] ?: comments["itunescompilation"])?.let {
|
||||
rawSong.albumArtistNames = rawSong.albumArtistNames.ifEmpty { COMPILATION_ALBUM_ARTISTS }
|
||||
rawSong.releaseTypes = rawSong.releaseTypes.ifEmpty { COMPILATION_RELEASE_TYPES }
|
||||
}
|
||||
}
|
||||
|
||||
class Factory @Inject constructor(private val mediaSourceFactory: MediaSource.Factory) :
|
||||
@@ -273,4 +285,9 @@ private constructor(private val rawSong: RawSong, private val future: Future<Tra
|
||||
requireNotNull(rawSong.mediaStoreId) { "Invalid raw: No id" }
|
||||
.toAudioUri())))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val COMPILATION_ALBUM_ARTISTS = listOf("Various Artists")
|
||||
val COMPILATION_RELEASE_TYPES = listOf("compilation")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user