PlaylistMaker.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace MusicPlayer
  11. {
  12. public partial class PlaylistMaker : Form
  13. {
  14. private PlaylistHandler pl;
  15. private APIHandler api;
  16. private List<Song> allPlaylistSongs;
  17. private List<Song> allsongs;
  18. public PlaylistMaker(PlaylistHandler pl, APIHandler api)
  19. {
  20. this.pl = pl;
  21. this.api = api;
  22. this.allPlaylistSongs = new List<Song>();
  23. this.allsongs = new List<Song>();
  24. InitializeComponent();
  25. Populate();
  26. }
  27. public void PlaylistSelectBox_SelectedIndexChanged(object sender, EventArgs e)
  28. {
  29. if (PlaylistSelectBox.SelectedItem != null)
  30. {
  31. PlaylistSongContainer.Items.Clear();
  32. allPlaylistSongs = pl.GetPlaylistByName(PlaylistSelectBox.SelectedItem.ToString()).GetSongs();
  33. allPlaylistSongs.ForEach(s => PlaylistSongContainer.Items.Add(s.Name));
  34. }
  35. }
  36. public void Repopulate()
  37. {
  38. PlaylistSelectBox.Items.Clear();
  39. pl.GetPlaylists().ForEach(p => PlaylistSelectBox.Items.Add(p.name));
  40. if (PlaylistSelectBox.SelectedItem != null)
  41. {
  42. PlaylistSongContainer.Items.Clear();
  43. allPlaylistSongs = pl.GetPlaylistByName(PlaylistSelectBox.SelectedItem.ToString()).GetSongs();
  44. allPlaylistSongs.ForEach(s => PlaylistSongContainer.Items.Add(s.Name));
  45. }
  46. }
  47. public void Populate()
  48. {
  49. pl.GetPlaylists().ForEach(p => PlaylistSelectBox.Items.Add(p.name));
  50. allsongs = api.GetAllSongs();
  51. allsongs.ForEach(s => PlaylistSongSelector.Items.Add(s.Name));
  52. }
  53. private void PlaylistAddSongsButton_Click(object sender, EventArgs e)
  54. {
  55. if (PlaylistSelectBox.SelectedItem!=null)
  56. {
  57. Playlist currentPlaylist = pl.GetPlaylistByName(PlaylistSelectBox.SelectedItem.ToString());
  58. foreach (string song in PlaylistSongSelector.SelectedItems)
  59. {
  60. foreach (Song s in allsongs) {
  61. if (s.Name == song)
  62. {
  63. currentPlaylist.AddSong(s);
  64. break;
  65. }
  66. }
  67. }
  68. currentPlaylist.WriteToFile();
  69. }
  70. Repopulate();
  71. }
  72. private void PlaylistNewButton_Click(object sender, EventArgs e)
  73. {
  74. pl.MakeNewPlaylistByName(PlaylistNewInputfield.Text);
  75. Repopulate();
  76. }
  77. }
  78. }