Merge branch 'dev' into state

main
Hemanth S 2020-09-22 12:44:47 +05:30 committed by GitHub
commit 03c0b2f68b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 6 deletions

View File

@ -123,6 +123,7 @@ const val AUTO_DOWNLOAD_IMAGES_POLICY = "auto_download_images_policy"
const val START_DIRECTORY = "start_directory" const val START_DIRECTORY = "start_directory"
const val RECENTLY_PLAYED_CUTOFF = "recently_played_interval" const val RECENTLY_PLAYED_CUTOFF = "recently_played_interval"
const val LOCK_SCREEN = "lock_screen" 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 ALBUM_DETAIL_SONG_SORT_ORDER = "album_detail_song_sort_order"
const val LYRICS_OPTIONS = "lyrics_tab_position" const val LYRICS_OPTIONS = "lyrics_tab_position"
const val CHOOSE_EQUALIZER = "choose_equalizer" const val CHOOSE_EQUALIZER = "choose_equalizer"

View File

@ -11,7 +11,11 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.repository.RealRepository import code.name.monkey.retromusic.repository.RealRepository
import code.name.monkey.retromusic.state.NowPlayingPanelState import code.name.monkey.retromusic.state.NowPlayingPanelState
import code.name.monkey.retromusic.util.PreferenceUtil
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -95,8 +99,14 @@ class LibraryViewModel(
} }
private fun fetchArtists() { private fun fetchArtists() {
viewModelScope.launch(IO) { if (PreferenceUtil.albumArtistsOnly) {
artists.postValue(repository.fetchArtists()) viewModelScope.launch(IO) {
artists.postValue(repository.albumArtists())
}
} else {
viewModelScope.launch(IO) {
artists.postValue(repository.fetchArtists())
}
} }
} }

View File

@ -15,6 +15,7 @@
package code.name.monkey.retromusic.model package code.name.monkey.retromusic.model
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtil
import java.util.* import java.util.*
data class Artist( data class Artist(
@ -25,6 +26,9 @@ data class Artist(
val name: String val name: String
get() { get() {
val name = safeGetFirstAlbum().safeGetFirstSong().albumArtist val name = safeGetFirstAlbum().safeGetFirstSong().albumArtist
if (PreferenceUtil.albumArtistsOnly && MusicUtil.isVariousArtists(name)) {
return VARIOUS_ARTISTS_DISPLAY_NAME
}
return if (MusicUtil.isArtistNameUnknown(name)) { return if (MusicUtil.isArtistNameUnknown(name)) {
UNKNOWN_ARTIST_DISPLAY_NAME UNKNOWN_ARTIST_DISPLAY_NAME
} else safeGetFirstAlbum().safeGetFirstSong().artistName } else safeGetFirstAlbum().safeGetFirstSong().artistName
@ -51,6 +55,8 @@ data class Artist(
companion object { companion object {
const val UNKNOWN_ARTIST_DISPLAY_NAME = "Unknown Artist" 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()) val empty = Artist(-1, emptyList())
} }

View File

@ -40,6 +40,19 @@ class RealArtistRepository(
PreferenceUtil.artistSongSortOrder PreferenceUtil.artistSongSortOrder
} }
override fun artist(artistId: Long): Artist { 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( val songs = songRepository.songs(
songRepository.makeSongCursor( songRepository.makeSongCursor(
AudioColumns.ARTIST_ID + "=?", AudioColumns.ARTIST_ID + "=?",
@ -67,6 +80,7 @@ class RealArtistRepository(
getSongLoaderSortOrder() getSongLoaderSortOrder()
) )
) )
return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs)) return splitIntoAlbumArtists(albumRepository.splitIntoAlbums(songs))
} }
@ -86,8 +100,12 @@ class RealArtistRepository(
return albums.groupBy { it.albumArtist } return albums.groupBy { it.albumArtist }
.map { .map {
val currentAlbums = it.value val currentAlbums = it.value
if (albums.isNotEmpty()) { if (currentAlbums.isNotEmpty()) {
Artist(currentAlbums[0].id, currentAlbums) if (currentAlbums[0].albumArtist == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) {
Artist(Artist.VARIOUS_ARTISTS_ID, currentAlbums)
} else {
Artist(currentAlbums[0].artistId, currentAlbums)
}
} else { } else {
Artist.empty Artist.empty
} }

View File

@ -299,6 +299,16 @@ object MusicUtil : KoinComponent {
return tempName == "unknown" || tempName == "<unknown>" return tempName == "unknown" || tempName == "<unknown>"
} }
fun isVariousArtists(artistName: String?): Boolean {
if (TextUtils.isEmpty(artistName)) {
return false
}
if (artistName == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) {
return true
}
return false
}
fun isFavorite(context: Context, song: Song): Boolean { fun isFavorite(context: Context, song: Song): Boolean {
return PlaylistsUtil return PlaylistsUtil
.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id) .doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id)

View File

@ -122,6 +122,13 @@ object PreferenceUtil {
"only_wifi" "only_wifi"
) )
var albumArtistsOnly
get() = sharedPreferences.getBoolean(
ALBUM_ARTISTS_ONLY,
false
)
set(value) = sharedPreferences.edit { putBoolean(ALBUM_ARTISTS_ONLY, value) }
var albumDetailSongSortOrder var albumDetailSongSortOrder
get() = sharedPreferences.getStringOrDefault( get() = sharedPreferences.getStringOrDefault(
ALBUM_DETAIL_SONG_SORT_ORDER, ALBUM_DETAIL_SONG_SORT_ORDER,
@ -150,7 +157,7 @@ object PreferenceUtil {
var artistSortOrder var artistSortOrder
get() = sharedPreferences.getStringOrDefault( get() = sharedPreferences.getStringOrDefault(
ARTIST_SORT_ORDER, ARTIST_SORT_ORDER,
AlbumSortOrder.ALBUM_A_Z ArtistSortOrder.ARTIST_A_Z
) )
set(value) = sharedPreferences.edit { set(value) = sharedPreferences.edit {
putString(ARTIST_SORT_ORDER, value) putString(ARTIST_SORT_ORDER, value)

View File

@ -69,6 +69,8 @@
<string name="action_sort_order">Sort order</string> <string name="action_sort_order">Sort order</string>
<string name="action_album_artists_only">Album artists only</string>
<string name="action_tag_editor">Tag editor</string> <string name="action_tag_editor">Tag editor</string>
<string name="action_toggle_favorite">Toggle favorite</string> <string name="action_toggle_favorite">Toggle favorite</string>
@ -517,6 +519,7 @@
<string name="pref_snow_fall_title">Snow fall effect</string> <string name="pref_snow_fall_title">Snow fall effect</string>
<string name="pref_summary_album_artists_only">Show Album Artists in the Artist category</string>
<string name="pref_summary_album_art_on_lockscreen">Use the currently playing song album cover as the lockscreen wallpaper</string> <string name="pref_summary_album_art_on_lockscreen">Use the currently playing song album cover as the lockscreen wallpaper</string>
<string name="pref_summary_audio_ducking">Lower the volume when a system sound is played or a notification is received</string> <string name="pref_summary_audio_ducking">Lower the volume when a system sound is played or a notification is received</string>
<string name="pref_summary_blacklist">The content of blacklisted folders is hidden from your library.</string> <string name="pref_summary_blacklist">The content of blacklisted folders is hidden from your library.</string>
@ -546,6 +549,7 @@
<string name="pref_summary_toggle_shuffle">Shuffle mode will turn off when playing a new list of songs</string> <string name="pref_summary_toggle_shuffle">Shuffle mode will turn off when playing a new list of songs</string>
<string name="pref_summary_toggle_volume">If enough space is available, show volume controls in the now playing screen</string> <string name="pref_summary_toggle_volume">If enough space is available, show volume controls in the now playing screen</string>
<string name="pref_title_album_artists_only">Navigate by Album Artist</string>
<string name="pref_title_album_art_on_lockscreen">Show album cover</string> <string name="pref_title_album_art_on_lockscreen">Show album cover</string>
<string name="pref_title_album_cover_style">Album cover theme</string> <string name="pref_title_album_cover_style">Album cover theme</string>
<string name="pref_title_album_cover_transform">Album cover skip</string> <string name="pref_title_album_cover_transform">Album cover skip</string>

View File

@ -45,6 +45,13 @@
android:negativeButtonText="@null" android:negativeButtonText="@null"
android:positiveButtonText="@null" android:positiveButtonText="@null"
android:title="@string/pref_title_tab_text_mode" /> android:title="@string/pref_title_tab_text_mode" />
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="false"
android:key="album_artists_only"
android:layout="@layout/list_item_view_switch"
android:summary="@string/pref_summary_album_artists_only"
android:title="@string/pref_title_album_artists_only" />
</code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory> </code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
<code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory