-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaylist.cs
169 lines (151 loc) · 6.76 KB
/
Playlist.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
namespace NHMPh_music_player
{
internal class Playlist
{
MainWindow mainWindow;
SongsManager songsManager;
public Playlist(MainWindow mainWindow, SongsManager songsManager)
{
this.mainWindow = mainWindow;
this.songsManager = songsManager;
this.songsManager.OnVideoQueueChange += CreatePlaylistCards;
}
private void CreatePlaylistCards(object sender, EventArgs e)
{
mainWindow.combobox.SelectionChanged -= Combobox_SelectionChanged;
mainWindow.combobox.Items.Clear();
if (songsManager.TotalSongInQueue() > 0)
{
//Add videoQueue 1st
int j = 0;
for (int i = 0; i < songsManager.VideoInfosQueue.Count; i++)
{
StackPanel stackPanel = CreatePlaylistSelection(songsManager.VideoInfosQueue.ElementAt(i).Thumbnail, songsManager.VideoInfosQueue.ElementAt(i).Title, j);
mainWindow.combobox.Items.Add(new ComboBoxItem()
{
Content = stackPanel,
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF282B30")),
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00F9FF")),
BorderThickness = new Thickness(0),
});
j++;
}
for (int i = 0; i < songsManager.VideoInfosAutoPlayQueue.Count; i++)
{
StackPanel stackPanel = CreatePlaylistSelection(songsManager.VideoInfosAutoPlayQueue.ElementAt(i).Thumbnail, songsManager.VideoInfosAutoPlayQueue.ElementAt(i).Title, j);
mainWindow.combobox.Items.Add(new ComboBoxItem()
{
Content = stackPanel,
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF282B30")),
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00F9FF")),
BorderThickness = new Thickness(0),
});
j++;
}
mainWindow.combobox.SelectionChanged += Combobox_SelectionChanged;
}
else
{
mainWindow.combobox.Items.Add(new ComboBoxItem()
{
Content = "Your list is empty. Either queue your song manually or press autoplay button (lower-left) for endless queue.",
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF282B30")),
Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF00F9FF")),
BorderThickness = new Thickness(0),
});
}
}
private void Combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var text = ((sender as ComboBox).SelectedItem as ComboBoxItem).Content as StackPanel;
if (text != null)
MoveTrackManager((text.Children[1] as TextBlock).Text);
}
private void MoveTrackManager(string track)
{
int id = StringUtilitiy.ExtractTrackId(track);
Console.WriteLine(id);
if (id < songsManager.VideoInfosQueue.Count)
{
var videoTemp = songsManager.VideoInfosQueue.ElementAt(id);
songsManager.VideoInfosQueue = new Queue<VideoInfo>(songsManager.VideoInfosQueue.Reverse());
songsManager.VideoInfosQueue.Enqueue(videoTemp);
songsManager.VideoInfosQueue = new Queue<VideoInfo>(songsManager.VideoInfosQueue.Reverse());
songsManager.RemoveSong(id+1);
}
else
{
songsManager.VideoInfosQueue = new Queue<VideoInfo>(songsManager.VideoInfosQueue.Reverse());
songsManager.VideoInfosQueue.Enqueue(songsManager.VideoInfosAutoPlayQueue.ElementAt(id - songsManager.VideoInfosQueue.Count));
songsManager.VideoInfosQueue = new Queue<VideoInfo>(songsManager.VideoInfosQueue.Reverse());
songsManager.RemoveSongAutoPlay(id - songsManager.VideoInfosQueue.Count + 1);
}
CreatePlaylistCards(this,null);
}
private StackPanel CreatePlaylistSelection(string thumbnail, string title, int id)
{
StackPanel stackPanel = new StackPanel()
{
Orientation = Orientation.Horizontal,
};
Border border = new Border()
{
Height = 30,
Width = 43,
CornerRadius = new CornerRadius(2),
Margin = new Thickness(5, 1, 5, 1),
Background = new ImageBrush()
{
Stretch = Stretch.Fill,
ImageSource = new BitmapImage(new Uri(thumbnail))
},
BorderThickness = new Thickness(0)
};
TextBlock textBlock = new TextBlock()
{
VerticalAlignment = System.Windows.VerticalAlignment.Center,
Text = id + ". " + title,
Width = 400
};
Button button = new Button
{
Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF282B30")),
BorderThickness = new Thickness(0),
Width = 50,
Margin = new Thickness(7, 0, 0, 0),
Content = "Remove",
Foreground = Brushes.White,
FontSize = 12,
VerticalAlignment = System.Windows.VerticalAlignment.Center,
Height = 20
};
button.Click += Delete_Btn_Click;
button.CommandParameter = id;
stackPanel.Children.Add(border);
stackPanel.Children.Add(textBlock);
stackPanel.Children.Add(button);
return stackPanel;
}
private void Delete_Btn_Click(object sender, RoutedEventArgs e)
{
int id = int.Parse((sender as Button).CommandParameter.ToString());
if (id < songsManager.VideoInfosQueue.Count)
{
songsManager.RemoveSong(id);
}
else
{
songsManager.RemoveSongAutoPlay(id - songsManager.VideoInfosQueue.Count);
}
}
}
}