music: add setting to hide collaborators

Add a setting to hide "collaborators", that is artists that do not show
up on any album artist tags.

This is mostly for my own use since I don't get use from useless
collaborator entries.
This commit is contained in:
Alexander Capehart
2022-10-20 18:36:51 -06:00
parent daf1cf8590
commit 1cf1451aef
8 changed files with 57 additions and 20 deletions
@@ -141,7 +141,15 @@ class HomeViewModel(application: Application) :
logD("Library changed, refreshing library")
_songs.value = settings.libSongSort.songs(library.songs)
_albums.value = settings.libAlbumSort.albums(library.albums)
_artists.value = settings.libArtistSort.artists(library.artists)
_artists.value = settings.libArtistSort.artists(
if (settings.shouldHideCollaborators) {
library.artists.filter { !it.isCollaborator }
} else {
library.artists
}
)
_genres.value = settings.libGenreSort.genres(library.genres)
}
}
@@ -151,6 +159,10 @@ class HomeViewModel(application: Application) :
tabs = visibleTabs
_shouldRecreateTabs.value = true
}
if (key == application.getString(R.string.set_key_hide_collaborators)) {
onLibraryChanged(musicStore.library)
}
}
override fun onCleared() {
@@ -590,6 +590,9 @@ constructor(raw: Raw, songAlbums: List<Music>) : MusicParent() {
/** The albums of this artist. This will never be empty. */
val albums: List<Album>
/** Whether this artist is not credited on any albums. */
val isCollaborator: Boolean
private lateinit var genres: List<Genre>
/**
@@ -616,6 +619,8 @@ constructor(raw: Raw, songAlbums: List<Music>) : MusicParent() {
init {
val distinctSongs = mutableSetOf<Song>()
val distinctAlbums = mutableSetOf<Album>()
var noAlbums = true
for (music in songAlbums) {
when (music) {
@@ -628,6 +633,7 @@ constructor(raw: Raw, songAlbums: List<Music>) : MusicParent() {
is Album -> {
music._link(this)
distinctAlbums.add(music)
noAlbums = false
}
else -> error("Unexpected input music ${music::class.simpleName}")
@@ -636,6 +642,7 @@ constructor(raw: Raw, songAlbums: List<Music>) : MusicParent() {
songs = distinctSongs.toList()
albums = distinctAlbums.toList()
isCollaborator = noAlbums
durationMs = songs.sumOf { it.durationMs }.nonZeroOrNull()
}
@@ -105,6 +105,10 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
TemporalQueries.localDate()
)
// When it comes to songs, we only want to show the month and year. This
// cannot be done with DateUtils due to it's dynamic nature, so instead
// it's done with the built-in date formatter. Since the legacy date API
// is awful, we only use instant and limit it to Android 8 onwards.
temporal.atStartOfDay(ZoneId.systemDefault())
.format(DateTimeFormatter.ofPattern("MMM yyyy", Locale.getDefault()))
} else {
@@ -204,9 +204,9 @@ class Settings(private val context: Context, private val callback: Callback? = n
}
}
/** The strategy used when loading images. */
val coverMode: CoverMode
get() = CoverMode.fromIntCode(inner.getInt(context.getString(R.string.set_key_cover_mode), Int.MIN_VALUE)) ?: CoverMode.MEDIA_STORE
/** Whether to hide collaborator artists or not. */
val shouldHideCollaborators: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_hide_collaborators), false)
/** Whether to round additional UI elements (including album covers) */
val roundMode: Boolean
@@ -296,6 +296,10 @@ class Settings(private val context: Context, private val callback: Callback? = n
val shouldBeObserving: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_observing), false)
/** The strategy used when loading images. */
val coverMode: CoverMode
get() = CoverMode.fromIntCode(inner.getInt(context.getString(R.string.set_key_cover_mode), Int.MIN_VALUE)) ?: CoverMode.MEDIA_STORE
/** Whether to load all audio files, even ones not considered music. */
val excludeNonMusic: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_exclude_non_music), true)