Code Cleanup

This commit is contained in:
Prathamesh More 2022-03-11 08:44:30 +05:30
parent 7f3b2b3d91
commit 8a050e114b
2 changed files with 15 additions and 30 deletions

View file

@ -35,7 +35,7 @@ import kotlinx.coroutines.withContext
import java.io.File
class LibraryViewModel(
private val repository: RealRepository
private val repository: RealRepository,
) : ViewModel(), IMusicServiceEventListener {
private val _paletteColor = MutableLiveData<Int>()
@ -380,6 +380,14 @@ class LibraryViewModel(
createPlaylist(PlaylistEntity(playlistName = playlistName))
insertSongs(songs.map { it.toSongEntity(playlistId) })
forceReload(Playlists)
withContext(Main) {
Toast.makeText(
App.getContext(),
App.getContext()
.getString(R.string.playlist_created_sucessfully, playlistName),
Toast.LENGTH_SHORT
).show()
}
} else {
val playlist = playlists.firstOrNull()
if (playlist != null) {
@ -389,34 +397,11 @@ class LibraryViewModel(
}
}
withContext(Main) {
when {
playlists.isEmpty() -> {
Toast.makeText(
App.getContext(),
App.getContext()
.getString(R.string.playlist_created_sucessfully, playlistName),
Toast.LENGTH_SHORT
).show()
}
checkPlaylistExists(playlistName).isNotEmpty() -> {
Toast.makeText(
App.getContext(),
App.getContext().getString(R.string.playList_already_exits),
Toast.LENGTH_SHORT
).show()
}
playlists.isNotEmpty() -> {
Toast.makeText(
App.getContext(),
App.getContext().getString(
R.string.added_song_count_to_playlist,
songs.size,
playlistName
),
Toast.LENGTH_SHORT
).show()
}
}
Toast.makeText(App.getContext(), App.getContext().getString(
R.string.added_song_count_to_playlist,
songs.size,
playlistName
), Toast.LENGTH_SHORT).show()
}
}
}