From bbd1853e78011d544672a8dace7c82d55acce99a Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 13 Sep 2020 21:42:12 -0400 Subject: [PATCH 1/6] Minimum working prototype --- .../java/code/name/monkey/retromusic/Constants.kt | 1 + .../monkey/retromusic/fragments/LibraryViewModel.kt | 11 +++++++++-- .../monkey/retromusic/repository/ArtistRepository.kt | 5 ++++- .../name/monkey/retromusic/util/PreferenceUtil.kt | 9 ++++++++- app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/pref_ui.xml | 7 +++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/Constants.kt b/app/src/main/java/code/name/monkey/retromusic/Constants.kt index 4e3a7a24..f0ce5dbd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/Constants.kt +++ b/app/src/main/java/code/name/monkey/retromusic/Constants.kt @@ -123,6 +123,7 @@ const val AUTO_DOWNLOAD_IMAGES_POLICY = "auto_download_images_policy" const val START_DIRECTORY = "start_directory" const val RECENTLY_PLAYED_CUTOFF = "recently_played_interval" const val LOCK_SCREEN = "lock_screen" +const val ALBUM_ARTISTS_ONLY = "album_artists_only" const val ALBUM_DETAIL_SONG_SORT_ORDER = "album_detail_song_sort_order" const val LYRICS_OPTIONS = "lyrics_tab_position" const val CHOOSE_EQUALIZER = "choose_equalizer" diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt index 3999ee70..ffccd49c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt @@ -12,6 +12,7 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.util.PreferenceUtil import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -91,8 +92,14 @@ class LibraryViewModel( } private fun fetchArtists() { - viewModelScope.launch(IO) { - artists.postValue(repository.fetchArtists()) + if (PreferenceUtil.albumArtistsOnly) { + viewModelScope.launch(IO) { + artists.postValue(repository.albumArtists()) + } + } else { + viewModelScope.launch(IO) { + artists.postValue(repository.fetchArtists()) + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt index 9a309b2a..bf1b41e3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt @@ -69,7 +69,10 @@ class RealArtistRepository( getSongLoaderSortOrder() ) ) - return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)) + + val sortString = if (PreferenceUtil.artistSortOrder.contains("DESC")) String.CASE_INSENSITIVE_ORDER.reversed() else String.CASE_INSENSITIVE_ORDER + + return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)).sortedWith(compareBy(sortString) { it.name }) } private fun splitIntoAlbumArtists(albums: List): List { diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt index 88333684..22221639 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt @@ -122,6 +122,13 @@ object PreferenceUtil { "only_wifi" ) + var albumArtistsOnly + get() = sharedPreferences.getBoolean( + ALBUM_ARTISTS_ONLY, + false + ) + set(value) = sharedPreferences.edit { putBoolean(ALBUM_ARTISTS_ONLY, value) } + var albumDetailSongSortOrder get() = sharedPreferences.getStringOrDefault( ALBUM_DETAIL_SONG_SORT_ORDER, @@ -150,7 +157,7 @@ object PreferenceUtil { var artistSortOrder get() = sharedPreferences.getStringOrDefault( ARTIST_SORT_ORDER, - AlbumSortOrder.ALBUM_A_Z + ArtistSortOrder.ARTIST_A_Z ) set(value) = sharedPreferences.edit { putString(ARTIST_SORT_ORDER, value) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 018bdc9f..be213e12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -69,6 +69,8 @@ Sort order + Album artists only + Tag editor Toggle favorite @@ -517,6 +519,7 @@ Snow fall effect + Show Album Artists in the Artist category Use the currently playing song album cover as the lockscreen wallpaper Lower the volume when a system sound is played or a notification is received The content of blacklisted folders is hidden from your library. @@ -546,6 +549,7 @@ Shuffle mode will turn off when playing a new list of songs If enough space is available, show volume controls in the now playing screen + Navigate by Album Artist Show album cover Album cover theme Album cover skip diff --git a/app/src/main/res/xml/pref_ui.xml b/app/src/main/res/xml/pref_ui.xml index 36475624..50c1e7d2 100644 --- a/app/src/main/res/xml/pref_ui.xml +++ b/app/src/main/res/xml/pref_ui.xml @@ -45,6 +45,13 @@ android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_tab_text_mode" /> + + Date: Sun, 13 Sep 2020 21:42:12 -0400 Subject: [PATCH 2/6] Minimum working prototype --- .../java/code/name/monkey/retromusic/Constants.kt | 1 + .../monkey/retromusic/fragments/LibraryViewModel.kt | 11 +++++++++-- .../monkey/retromusic/repository/ArtistRepository.kt | 5 ++++- .../name/monkey/retromusic/util/PreferenceUtil.kt | 9 ++++++++- app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/pref_ui.xml | 7 +++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/Constants.kt b/app/src/main/java/code/name/monkey/retromusic/Constants.kt index 4e3a7a24..f0ce5dbd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/Constants.kt +++ b/app/src/main/java/code/name/monkey/retromusic/Constants.kt @@ -123,6 +123,7 @@ const val AUTO_DOWNLOAD_IMAGES_POLICY = "auto_download_images_policy" const val START_DIRECTORY = "start_directory" const val RECENTLY_PLAYED_CUTOFF = "recently_played_interval" const val LOCK_SCREEN = "lock_screen" +const val ALBUM_ARTISTS_ONLY = "album_artists_only" const val ALBUM_DETAIL_SONG_SORT_ORDER = "album_detail_song_sort_order" const val LYRICS_OPTIONS = "lyrics_tab_position" const val CHOOSE_EQUALIZER = "choose_equalizer" diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt index a44cd7bb..f3b609b4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt @@ -13,6 +13,7 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.repository.RealRepository +import code.name.monkey.retromusic.util.PreferenceUtil import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -91,8 +92,14 @@ class LibraryViewModel( } private fun fetchArtists() { - viewModelScope.launch(IO) { - artists.postValue(repository.fetchArtists()) + if (PreferenceUtil.albumArtistsOnly) { + viewModelScope.launch(IO) { + artists.postValue(repository.albumArtists()) + } + } else { + viewModelScope.launch(IO) { + artists.postValue(repository.fetchArtists()) + } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt index 6ecf6509..314d1331 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt @@ -67,7 +67,10 @@ class RealArtistRepository( getSongLoaderSortOrder() ) ) - return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)) + + val sortString = if (PreferenceUtil.artistSortOrder.contains("DESC")) String.CASE_INSENSITIVE_ORDER.reversed() else String.CASE_INSENSITIVE_ORDER + + return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)).sortedWith(compareBy(sortString) { it.name }) } override fun artists(query: String): List { diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt index 88333684..22221639 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.kt @@ -122,6 +122,13 @@ object PreferenceUtil { "only_wifi" ) + var albumArtistsOnly + get() = sharedPreferences.getBoolean( + ALBUM_ARTISTS_ONLY, + false + ) + set(value) = sharedPreferences.edit { putBoolean(ALBUM_ARTISTS_ONLY, value) } + var albumDetailSongSortOrder get() = sharedPreferences.getStringOrDefault( ALBUM_DETAIL_SONG_SORT_ORDER, @@ -150,7 +157,7 @@ object PreferenceUtil { var artistSortOrder get() = sharedPreferences.getStringOrDefault( ARTIST_SORT_ORDER, - AlbumSortOrder.ALBUM_A_Z + ArtistSortOrder.ARTIST_A_Z ) set(value) = sharedPreferences.edit { putString(ARTIST_SORT_ORDER, value) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 018bdc9f..be213e12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -69,6 +69,8 @@ Sort order + Album artists only + Tag editor Toggle favorite @@ -517,6 +519,7 @@ Snow fall effect + Show Album Artists in the Artist category Use the currently playing song album cover as the lockscreen wallpaper Lower the volume when a system sound is played or a notification is received The content of blacklisted folders is hidden from your library. @@ -546,6 +549,7 @@ Shuffle mode will turn off when playing a new list of songs If enough space is available, show volume controls in the now playing screen + Navigate by Album Artist Show album cover Album cover theme Album cover skip diff --git a/app/src/main/res/xml/pref_ui.xml b/app/src/main/res/xml/pref_ui.xml index 36475624..50c1e7d2 100644 --- a/app/src/main/res/xml/pref_ui.xml +++ b/app/src/main/res/xml/pref_ui.xml @@ -45,6 +45,13 @@ android:negativeButtonText="@null" android:positiveButtonText="@null" android:title="@string/pref_title_tab_text_mode" /> + + Date: Sun, 20 Sep 2020 17:23:32 -0400 Subject: [PATCH 3/6] Fix incorrect loading from #895 --- .../code/name/monkey/retromusic/repository/ArtistRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt index 314d1331..907bf49c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt @@ -90,7 +90,7 @@ class RealArtistRepository( .map { val currentAlbums = it.value if (albums.isNotEmpty()) { - Artist(currentAlbums[0].id, currentAlbums) + Artist(currentAlbums[0].artistId, currentAlbums) } else { Artist.empty } From 6747af076fd29a3b01bc1e7ecd4f2d2a46f98237 Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 21 Sep 2020 00:17:53 -0400 Subject: [PATCH 4/6] Various artists is working --- .../name/monkey/retromusic/model/Artist.kt | 4 +++ .../retromusic/repository/ArtistRepository.kt | 25 +++++++++++++++---- .../name/monkey/retromusic/util/MusicUtil.kt | 7 ++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt b/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt index 98fe4209..fbfde54c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt @@ -27,6 +27,8 @@ data class Artist( val name = safeGetFirstAlbum().safeGetFirstSong().albumArtist return if (MusicUtil.isArtistNameUnknown(name)) { UNKNOWN_ARTIST_DISPLAY_NAME + } else if (MusicUtil.isVariousArtists(name)) { + VARIOUS_ARTISTS_DISPLAY_NAME } else safeGetFirstAlbum().safeGetFirstSong().artistName } @@ -51,6 +53,8 @@ data class Artist( companion object { const val UNKNOWN_ARTIST_DISPLAY_NAME = "Unknown Artist" + const val VARIOUS_ARTISTS_DISPLAY_NAME = "Various Artists" + const val VARIOUS_ARTISTS_ID : Long = -2 val empty = Artist(-1, emptyList()) } diff --git a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt index 907bf49c..d78df6d1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt +++ b/app/src/main/java/code/name/monkey/retromusic/repository/ArtistRepository.kt @@ -40,6 +40,19 @@ class RealArtistRepository( PreferenceUtil.artistSongSortOrder } override fun artist(artistId: Long): Artist { + if (artistId == Artist.VARIOUS_ARTISTS_ID) { + // Get Various Artists + val songs = songRepository.songs( + songRepository.makeSongCursor( + null, + null, + getSongLoaderSortOrder() + ) + ) + val albums = albumRepository.splitIntoAlbums(songs).filter { it.albumArtist == Artist.VARIOUS_ARTISTS_DISPLAY_NAME } + return Artist(Artist.VARIOUS_ARTISTS_ID, albums) + } + val songs = songRepository.songs( songRepository.makeSongCursor( AudioColumns.ARTIST_ID + "=?", @@ -68,9 +81,7 @@ class RealArtistRepository( ) ) - val sortString = if (PreferenceUtil.artistSortOrder.contains("DESC")) String.CASE_INSENSITIVE_ORDER.reversed() else String.CASE_INSENSITIVE_ORDER - - return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)).sortedWith(compareBy(sortString) { it.name }) + return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)) } override fun artists(query: String): List { @@ -89,8 +100,12 @@ class RealArtistRepository( return albums.groupBy { it.albumArtist } .map { val currentAlbums = it.value - if (albums.isNotEmpty()) { - Artist(currentAlbums[0].artistId, currentAlbums) + if (currentAlbums.isNotEmpty()) { + if (currentAlbums[0].albumArtist == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) { + Artist(Artist.VARIOUS_ARTISTS_ID, currentAlbums) + } else { + Artist(currentAlbums[0].artistId, currentAlbums) + } } else { Artist.empty } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt index 0af7cb91..e267966a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt @@ -299,6 +299,13 @@ object MusicUtil : KoinComponent { return tempName == "unknown" || tempName == "" } + fun isVariousArtists(artistName: String): Boolean { + if (artistName == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) { + return true + } + return false + } + fun isFavorite(context: Context, song: Song): Boolean { return PlaylistsUtil .doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id) From 991c4ee36e5449b5d5c200799631241c129b0e5c Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 21 Sep 2020 00:31:53 -0400 Subject: [PATCH 5/6] Got code cleanup happy... all fixed --- .../main/java/code/name/monkey/retromusic/util/MusicUtil.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt index e267966a..645b8843 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/MusicUtil.kt @@ -299,7 +299,10 @@ object MusicUtil : KoinComponent { return tempName == "unknown" || tempName == "" } - fun isVariousArtists(artistName: String): Boolean { + fun isVariousArtists(artistName: String?): Boolean { + if (TextUtils.isEmpty(artistName)) { + return false + } if (artistName == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) { return true } From 5d1a75bc1384ee32d296b0d076753733d503f6b2 Mon Sep 17 00:00:00 2001 From: thomas Date: Mon, 21 Sep 2020 00:39:26 -0400 Subject: [PATCH 6/6] Fixing bug when preference is not set --- .../main/java/code/name/monkey/retromusic/model/Artist.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt b/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt index fbfde54c..bb4fd0b1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/Artist.kt @@ -15,6 +15,7 @@ package code.name.monkey.retromusic.model import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil import java.util.* data class Artist( @@ -25,10 +26,11 @@ data class Artist( val name: String get() { val name = safeGetFirstAlbum().safeGetFirstSong().albumArtist + if (PreferenceUtil.albumArtistsOnly && MusicUtil.isVariousArtists(name)) { + return VARIOUS_ARTISTS_DISPLAY_NAME + } return if (MusicUtil.isArtistNameUnknown(name)) { UNKNOWN_ARTIST_DISPLAY_NAME - } else if (MusicUtil.isVariousArtists(name)) { - VARIOUS_ARTISTS_DISPLAY_NAME } else safeGetFirstAlbum().safeGetFirstSong().artistName }