Code refactor
This commit is contained in:
parent
34b5d01e8d
commit
9da8cb99ce
2 changed files with 20 additions and 29 deletions
|
@ -197,23 +197,25 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
|
|||
|
||||
fun updateIsFavorite() {
|
||||
lifecycleScope.launch(IO) {
|
||||
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist().first()
|
||||
val song = MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)
|
||||
val isFavorite = libraryViewModel.isFavoriteSong(song).isNotEmpty()
|
||||
withContext(Main) {
|
||||
val icon =
|
||||
if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border
|
||||
val drawable =
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
requireContext(),
|
||||
icon,
|
||||
toolbarIconColor()
|
||||
)
|
||||
if (playerToolbar() != null) {
|
||||
playerToolbar()?.menu?.findItem(R.id.action_toggle_favorite)
|
||||
?.setIcon(drawable)?.title =
|
||||
if (isFavorite) getString(R.string.action_remove_from_favorites)
|
||||
else getString(R.string.action_add_to_favorites)
|
||||
val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist().firstOrNull()
|
||||
if (playlist != null) {
|
||||
val song = MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)
|
||||
val isFavorite = libraryViewModel.isFavoriteSong(song).isNotEmpty()
|
||||
withContext(Main) {
|
||||
val icon =
|
||||
if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border
|
||||
val drawable =
|
||||
RetroUtil.getTintedVectorDrawable(
|
||||
requireContext(),
|
||||
icon,
|
||||
toolbarIconColor()
|
||||
)
|
||||
if (playerToolbar() != null) {
|
||||
playerToolbar()?.menu?.findItem(R.id.action_toggle_favorite)
|
||||
?.setIcon(drawable)?.title =
|
||||
if (isFavorite) getString(R.string.action_remove_from_favorites)
|
||||
else getString(R.string.action_add_to_favorites)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
android:id="@+id/retro_graph"
|
||||
app:startDestination="@id/libraryFragment">
|
||||
|
||||
<include app:graph="@navigation/settings_graph" />
|
||||
|
||||
<include app:graph="@navigation/library_graph" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/genreDetailsFragment"
|
||||
android:name="code.name.monkey.retromusic.fragments.genres.GenreDetailsFragment"
|
||||
|
@ -53,14 +49,7 @@
|
|||
android:id="@+id/libraryFragment"
|
||||
android:name="code.name.monkey.retromusic.fragments.library.LibraryFragment"
|
||||
android:label=""
|
||||
tools:layout="@layout/fragment_library">
|
||||
<action
|
||||
android:id="@+id/action_main_to_library"
|
||||
app:destination="@id/library_graph" />
|
||||
<action
|
||||
android:id="@+id/action_main_to_settings"
|
||||
app:destination="@id/settings_graph" />
|
||||
</fragment>
|
||||
tools:layout="@layout/fragment_library" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/detailListFragment"
|
||||
|
|
Loading…
Reference in a new issue