Code refactor

This commit is contained in:
Hemanth S 2020-09-02 20:50:38 +05:30
parent 34b5d01e8d
commit 9da8cb99ce
2 changed files with 20 additions and 29 deletions

View file

@ -197,23 +197,25 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
fun updateIsFavorite() { fun updateIsFavorite() {
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist().first() val playlist: PlaylistEntity? = libraryViewModel.favoritePlaylist().firstOrNull()
val song = MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId) if (playlist != null) {
val isFavorite = libraryViewModel.isFavoriteSong(song).isNotEmpty() val song = MusicPlayerRemote.currentSong.toSongEntity(playlist.playListId)
withContext(Main) { val isFavorite = libraryViewModel.isFavoriteSong(song).isNotEmpty()
val icon = withContext(Main) {
if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border val icon =
val drawable = if (isFavorite) R.drawable.ic_favorite else R.drawable.ic_favorite_border
RetroUtil.getTintedVectorDrawable( val drawable =
requireContext(), RetroUtil.getTintedVectorDrawable(
icon, requireContext(),
toolbarIconColor() icon,
) toolbarIconColor()
if (playerToolbar() != null) { )
playerToolbar()?.menu?.findItem(R.id.action_toggle_favorite) if (playerToolbar() != null) {
?.setIcon(drawable)?.title = playerToolbar()?.menu?.findItem(R.id.action_toggle_favorite)
if (isFavorite) getString(R.string.action_remove_from_favorites) ?.setIcon(drawable)?.title =
else getString(R.string.action_add_to_favorites) if (isFavorite) getString(R.string.action_remove_from_favorites)
else getString(R.string.action_add_to_favorites)
}
} }
} }
} }

View file

@ -5,10 +5,6 @@
android:id="@+id/retro_graph" android:id="@+id/retro_graph"
app:startDestination="@id/libraryFragment"> app:startDestination="@id/libraryFragment">
<include app:graph="@navigation/settings_graph" />
<include app:graph="@navigation/library_graph" />
<fragment <fragment
android:id="@+id/genreDetailsFragment" android:id="@+id/genreDetailsFragment"
android:name="code.name.monkey.retromusic.fragments.genres.GenreDetailsFragment" android:name="code.name.monkey.retromusic.fragments.genres.GenreDetailsFragment"
@ -53,14 +49,7 @@
android:id="@+id/libraryFragment" android:id="@+id/libraryFragment"
android:name="code.name.monkey.retromusic.fragments.library.LibraryFragment" android:name="code.name.monkey.retromusic.fragments.library.LibraryFragment"
android:label="" android:label=""
tools:layout="@layout/fragment_library"> 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>
<fragment <fragment
android:id="@+id/detailListFragment" android:id="@+id/detailListFragment"