From 1cf1451aef971489e1256bd2997f041300536b24 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Thu, 20 Oct 2022 18:35:56 -0600 Subject: [PATCH] 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. --- CHANGELOG.md | 1 + .../org/oxycblt/auxio/home/HomeViewModel.kt | 14 ++++++++++++- .../java/org/oxycblt/auxio/music/Music.kt | 7 +++++++ .../main/java/org/oxycblt/auxio/music/Tags.kt | 4 ++++ .../org/oxycblt/auxio/settings/Settings.kt | 10 ++++++--- app/src/main/res/values/settings.xml | 21 ++++++++++--------- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/prefs_main.xml | 18 ++++++++++------ 8 files changed, 57 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e24501159..00c2bfb19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Added support for multiple artists - Added support for multiple genres - Artists and album artists are now both given UI entires + - Added setting to hide "collaborator" artists - Upgraded music ID management: - Added support for MusicBrainz IDs (MBIDs) - Use the more unique MD5 hash of metadata when MBIDs can't be used diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt index 2cd9d8adf..82cc24c75 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeViewModel.kt @@ -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() { diff --git a/app/src/main/java/org/oxycblt/auxio/music/Music.kt b/app/src/main/java/org/oxycblt/auxio/music/Music.kt index 530e5509e..456a32c33 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/Music.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/Music.kt @@ -590,6 +590,9 @@ constructor(raw: Raw, songAlbums: List) : MusicParent() { /** The albums of this artist. This will never be empty. */ val albums: List + /** Whether this artist is not credited on any albums. */ + val isCollaborator: Boolean + private lateinit var genres: List /** @@ -616,6 +619,8 @@ constructor(raw: Raw, songAlbums: List) : MusicParent() { init { val distinctSongs = mutableSetOf() val distinctAlbums = mutableSetOf() + + var noAlbums = true for (music in songAlbums) { when (music) { @@ -628,6 +633,7 @@ constructor(raw: Raw, songAlbums: List) : 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) : MusicParent() { songs = distinctSongs.toList() albums = distinctAlbums.toList() + isCollaborator = noAlbums durationMs = songs.sumOf { it.durationMs }.nonZeroOrNull() } diff --git a/app/src/main/java/org/oxycblt/auxio/music/Tags.kt b/app/src/main/java/org/oxycblt/auxio/music/Tags.kt index 96bc9cb2f..f2d3309ac 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/Tags.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/Tags.kt @@ -105,6 +105,10 @@ class Date private constructor(private val tokens: List) : Comparable 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 { diff --git a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt index 9ec104e64..d9e9072b2 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt @@ -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) diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index d23f770f6..ddf4e68da 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -5,11 +5,13 @@ KEY_BLACK_THEME auxio_accent2 - auxio_lib_tabs + auxio_reindex + auxio_observing + auxio_music_dirs auxio_cover_mode - auxio_round_covers - auxio_bar_action - auxio_notif_action + auxio_include_dirs + auxio_exclude_non_music + auxio_separators auxio_headset_autoplay auxio_replay_gain @@ -26,12 +28,11 @@ auxio_wipe_state auxio_restore_state - auxio_reindex - auxio_observing - auxio_music_dirs - auxio_include_dirs - auxio_exclude_non_music - auxio_separators + auxio_lib_tabs + auxio_hide_collaborators + auxio_round_covers + auxio_bar_action + auxio_notif_action KEY_SEARCH_FILTER diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 46c755bbf..1522e1720 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,6 +169,8 @@ Display Library tabs Change visibility and order of library tabs + Hide collaborators + Only show artists that appear in the \'album artist\' tags in your library Album covers Off Fast diff --git a/app/src/main/res/xml/prefs_main.xml b/app/src/main/res/xml/prefs_main.xml index aff0caadc..2f615cc2c 100644 --- a/app/src/main/res/xml/prefs_main.xml +++ b/app/src/main/res/xml/prefs_main.xml @@ -31,12 +31,11 @@ app:summary="@string/set_lib_tabs_desc" app:title="@string/set_lib_tabs" /> - + + +