--- /dev/null
+using System.Collections.Generic;
+using Tizen.Content.MediaContent;
+using MusicPlayer.ViewModels;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI;
+using Tizen.NUI.Binding;
+using MusicPlayer.Common;
+using MusicPlayer.Models;
+using MusicPlayer.Core;
+
+namespace MusicPlayer.Views
+{
+ class PlaylistSelectorView : View
+ {
+ private View selectPlaylistContentArea;
+ private View createPlaylistContentArea;
+ private View searchBox;
+ private Button createNewPlaylistButton;
+ private TextLabel noListText;
+ private TextLabel underText;
+ private CollectionView collectionView;
+ private Button selectPlaylistCancelButton;
+ private Button createPlaylistCancelButton;
+ private Button createPlaylistCreateButton;
+ private AlertDialog selectPlaylistDialog;
+ private AlertDialog createPlaylistDialog;
+ private TextField textField;
+ private Button crossButton;
+ private PlaylistSelectorViewModel viewModel;
+
+ public PlaylistSelectorView(PlaylistSelectorViewModel viewModel)
+ {
+ this.viewModel = viewModel;
+ AddSelectPlaylistContentArea();
+ AddSelectPlaylistCancelButton();
+ selectPlaylistDialog = new AlertDialog()
+ {
+ Size2D = new Size2D(1184, 660),
+ Title = "Add to playlist",
+ Content = selectPlaylistContentArea,
+ Actions = new List<View> { selectPlaylistCancelButton},
+ Padding = new Extents(0, 0, 0, 0),
+ Margin = new Extents(0, 0, 0, 0),
+ };
+ TextLabel textLabel = (TextLabel)selectPlaylistDialog.TitleContent;
+ textLabel.FontStyle = UIFontStyles.AllNormal;
+ Window.Instance.Add(selectPlaylistDialog);
+ }
+
+ private void AddSelectPlaylistContentArea()
+ {
+ selectPlaylistContentArea = new View()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 340,
+ BackgroundColor = Color.Transparent,
+ Layout = new FlexLayout()
+ {
+ Direction = FlexLayout.FlexDirection.Column,
+ ItemsAlignment = FlexLayout.AlignmentType.FlexStart,
+ Justification = FlexLayout.FlexJustification.FlexStart,
+ },
+ };
+ AddCreatePlayListButton();
+ if (viewModel.ListViewModel.Count == 0)
+ {
+ AddNoListText();
+ }
+ AddCollectionView();
+ }
+
+ private void AddCreatePlayListButton()
+ {
+ ButtonStyle buttonStyle = new ButtonStyle()
+ {
+ Text = new TextLabelStyle()
+ {
+ Text = "+ Create new playlist",
+ PixelSize = 32,
+ FontFamily = "BreezeSans",
+ TextColor = UIColors.HEX001447,
+ HorizontalAlignment = HorizontalAlignment.Begin,
+ VerticalAlignment = VerticalAlignment.Center,
+ },
+ IsSelectable = false,
+ };
+
+ createNewPlaylistButton = new Button(buttonStyle)
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 108,
+ TextAlignment = HorizontalAlignment.Begin,
+ Padding = new Extents(64, 64, 0, 0),
+ IsEnabled = true,
+ IsSelectable = false,
+ ItemAlignment = LinearLayout.Alignment.CenterVertical,
+ };
+ selectPlaylistContentArea.Add(createNewPlaylistButton);
+ View itemSeperator = new View()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 1,
+ BackgroundColor = UIColors.ItemSeperator,
+ Margin = new Extents(44, 44, 0, 0),
+ };
+ selectPlaylistContentArea.Add(itemSeperator);
+ createNewPlaylistButton.Clicked += CreateNewPlaylistButtonClicked;
+ }
+
+ private void CreateNewPlaylistButtonClicked(object sender, ClickedEventArgs e)
+ {
+ RemoveTheSelectPopup();
+ AddCreatePlaylistContentArea();
+ AddCreatePlaylistButtons();
+ createPlaylistDialog = new AlertDialog()
+ {
+ Size2D = new Size2D(1184, 465),
+ Title = "Create playlist",
+ Content = createPlaylistContentArea,
+ Actions = new List<View> { createPlaylistCancelButton , createPlaylistCreateButton },
+ Padding = new Extents(0, 0, 0, 0),
+ Margin = new Extents(0, 0, 0, 0),
+ };
+ TextLabel textLabel = (TextLabel)selectPlaylistDialog.TitleContent;
+ textLabel.FontStyle = UIFontStyles.AllNormal;
+ Window.Instance.Add(createPlaylistDialog);
+ }
+
+ private void AddCollectionView()
+ {
+ collectionView = new CollectionView()
+ {
+ Size2D = new Size2D(1184, 108),
+ ItemsLayouter = new LinearLayouter(),
+ ScrollingDirection = ScrollableBase.Direction.Vertical,
+ HeightSpecification = LayoutParamPolicies.WrapContent,
+ SelectionMode = ItemSelectionMode.Single,
+ };
+ selectPlaylistContentArea.Add(collectionView);
+ FlexLayout.SetFlexGrow(collectionView, 1);
+ FlexLayout.SetFlexShrink(collectionView, 1);
+ collectionView.ItemTemplate = new DataTemplate(() =>
+ {
+ DefaultLinearItem layout = new DefaultLinearItem();
+ layout.Label.SetBinding(TextLabel.TextProperty, "PlaylistName");
+ layout.Padding = new Extents(0, 0, 0, 0);
+ layout.Margin = new Extents(0, 0, 0, 0);
+ return layout;
+ });
+ collectionView.ItemsSource = viewModel.ListViewModel;
+ }
+
+ private void AddNoListText()
+ {
+ noListText = new TextLabel("ItemLabel")
+ {
+ ThemeChangeSensitive = true,
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 108,
+ PixelSize = 32,
+ Text = "No playlists available",
+ HorizontalAlignment = HorizontalAlignment.Begin,
+ VerticalAlignment = VerticalAlignment.Center,
+ FontFamily = "BreezeSans",
+ FontStyle = UIFontStyles.NormalLight,
+ Padding = new Extents(64, 64, 0, 0),
+ };
+ selectPlaylistContentArea.Add(noListText);
+ }
+ private void AddSelectPlaylistCancelButton()
+ {
+ selectPlaylistCancelButton = new Button()
+ {
+ Text = "Cancel",
+ };
+ selectPlaylistCancelButton.TextLabel.FontStyle = UIFontStyles.AllNormal;
+ selectPlaylistCancelButton.IsSelectable = true;
+ selectPlaylistCancelButton.Clicked += SelectPlaylistCancelButtonClicked;
+ }
+
+ private void SelectPlaylistCancelButtonClicked(object sender, ClickedEventArgs e)
+ {
+ RemoveTheSelectPopup();
+ }
+
+ private void AddCreatePlaylistContentArea()
+ {
+ createPlaylistContentArea = new View()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 169,
+ BackgroundColor = Color.Transparent,
+ Layout = new FlexLayout()
+ {
+ Direction = FlexLayout.FlexDirection.Column,
+ ItemsAlignment = FlexLayout.AlignmentType.FlexStart,
+ Justification = FlexLayout.FlexJustification.FlexStart,
+ Padding = new Extents(64, 64, 0, 0),
+ },
+ };
+ TextLabel textLabel = new TextLabel("TitleText")
+ {
+ ThemeChangeSensitive = true,
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 40,
+ PixelSize = 32,
+ Text = "Add playlist name.",
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Center,
+ FontFamily = "BreezeSans",
+ FontStyle = UIFontStyles.NormalLight,
+ Margin = new Extents(0, 0, 0, 24),
+ };
+ createPlaylistContentArea.Add(textLabel);
+ AddSearchBox();
+ View itemSeperator = new View()
+ {
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 1,
+ BackgroundColor = UIColors.HEX001447,
+ };
+ createPlaylistContentArea.Add(itemSeperator);
+ underText = new TextLabel("ItemLabel")
+ {
+ ThemeChangeSensitive = true,
+ WidthSpecification = LayoutParamPolicies.MatchParent,
+ HeightSpecification = 32,
+ PixelSize = 24,
+ Text = "Can't enter more than 64 characters.",
+ HorizontalAlignment = HorizontalAlignment.Begin,
+ VerticalAlignment = VerticalAlignment.Center,
+ FontFamily = "BreezeSans",
+ FontStyle = UIFontStyles.AllNormal,
+ };
+ createPlaylistContentArea.Add(underText);
+ }
+
+ private void AddSearchBox()
+ {
+ searchBox = new View()
+ {
+ Size2D = new Size2D(1024, 48),
+ Layout = new FlexLayout()
+ {
+ Direction = FlexLayout.FlexDirection.Row,
+ ItemsAlignment = FlexLayout.AlignmentType.Center,
+ Justification = FlexLayout.FlexJustification.FlexStart,
+ },
+ };
+ textField = new TextField()
+ {
+ Size2D = new Size2D(928, 48),
+ BackgroundColor = Color.White,
+ Position2D = new Position2D(0, 0),
+ Margin = new Extents(0, 48, 0, 0),
+ TextColor = UIColors.HEX001447,
+ FontStyle = UIFontStyles.NormalLight,
+ MaxLength = 65,
+ };
+ textField.Text = viewModel.NewPlayListName;
+ textField.TextChanged += TextFieldTextChanged;
+
+ ButtonStyle crossButtonStyle = new ButtonStyle()
+ {
+ Icon = new ImageViewStyle()
+ {
+ ResourceUrl = Resources.GetImagePath() + "cross_button.png",
+ },
+ IsSelectable = true,
+ IsEnabled = true,
+ };
+
+ crossButton = new Button(crossButtonStyle)
+ {
+ Size2D = new Size2D(48, 48),
+ Position2D = new Position2D(976, 6),
+ };
+ crossButton.Clicked += CrossButtonClicked;
+
+ searchBox.Add(textField);
+ searchBox.Add(crossButton);
+ createPlaylistContentArea.Add(searchBox);
+ }
+
+ private void TextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
+ {
+ string searchText = e.TextField.Text;
+ if (string.IsNullOrEmpty(searchText))
+ {
+ crossButton.Hide();
+ crossButton.IsSelectable = false;
+ createPlaylistCreateButton.IsSelectable = false;
+ createPlaylistCreateButton.IsEnabled = false;
+ }
+ else
+ {
+ crossButton.Show();
+ crossButton.IsSelectable = true;
+ createPlaylistCreateButton.IsSelectable = true;
+ createPlaylistCreateButton.IsEnabled = true;
+ }
+ if(searchText.Length > 64)
+ {
+ Notification.MakeToast("Maximum number of characters reached.", Notification.ToastCenter).Post(Notification.ToastShort);
+ underText.Text = "Can't enter more than 64 characters.";
+ textField.Text = searchText.Substring(0, 63);
+ }
+ }
+
+ private void CrossButtonClicked(object sender, ClickedEventArgs e)
+ {
+ textField.Text = "";
+ }
+
+ private void AddCreatePlaylistButtons()
+ {
+ createPlaylistCancelButton = new Button("CancelButton")
+ {
+ ThemeChangeSensitive = true,
+ };
+ createPlaylistCancelButton.TextLabel.FontStyle = UIFontStyles.AllNormal;
+ createPlaylistCancelButton.IsSelectable = true;
+ createPlaylistCancelButton.Clicked += CreatePlaylistCancelButtonClicked;
+
+ createPlaylistCreateButton = new Button()
+ {
+ Text = "Create",
+ };
+ createPlaylistCreateButton.TextLabel.FontStyle = UIFontStyles.AllNormal;
+ createPlaylistCreateButton.IsSelectable = true;
+ createPlaylistCreateButton.Clicked += CreatePlaylistCreateButtonClicked;
+ }
+
+ private void CreatePlaylistCancelButtonClicked(object sender, ClickedEventArgs e)
+ {
+ RemoveTheCreatePopup();
+ }
+
+ private void CreatePlaylistCreateButtonClicked(object sender, ClickedEventArgs e)
+ {
+ if (viewModel.CheckPlayListName(textField.Text))
+ {
+ RemoveTheCreatePopup();
+ Window.Instance.Add(selectPlaylistDialog);
+ Playlist playlist = PlaylistManager.Instance.AddPlaylist(textField.Text);
+ PlaylistModel playlistModel = new PlaylistModel(new PlaylistData(playlist.Id,playlist.Name, viewModel.GetTrackCountForPlaylist(playlist.Id), playlist.ThumbnailPath));
+ collectionView.SelectedItem = playlistModel;
+ }
+ else
+ {
+ Notification.MakeToast("Playlist name already in use.", Notification.ToastCenter).Post(Notification.ToastShort);
+ underText.Text = "Playlist name already in use.";
+ }
+ }
+
+ protected override void Dispose(DisposeTypes type)
+ {
+ if (Disposed)
+ {
+ return;
+ }
+ if (type == DisposeTypes.Explicit)
+ {
+ selectPlaylistDialog?.Dispose();
+ selectPlaylistDialog = null;
+ createPlaylistDialog?.Dispose();
+ createPlaylistDialog = null;
+
+ searchBox?.Remove(textField);
+ textField?.Dispose();
+ textField = null;
+ searchBox?.Remove(crossButton);
+ crossButton?.Dispose();
+ crossButton = null;
+
+ if(selectPlaylistContentArea != null)
+ {
+ List<View> children = selectPlaylistContentArea.Children;
+ foreach(View child in children)
+ {
+ selectPlaylistContentArea.Remove(child);
+ child?.Dispose();
+ }
+ selectPlaylistContentArea.Dispose();
+ }
+ if (createPlaylistContentArea != null)
+ {
+ List<View> children = createPlaylistContentArea.Children;
+ foreach (View child in children)
+ {
+ createPlaylistContentArea.Remove(child);
+ child?.Dispose();
+ }
+ createPlaylistContentArea.Dispose();
+ createPlaylistContentArea = null;
+ }
+
+ createNewPlaylistButton = null;
+ collectionView?.Dispose();
+ collectionView = null;
+ noListText?.Dispose();
+ noListText = null;
+ searchBox = null;
+ underText = null;
+
+ selectPlaylistCancelButton?.Dispose();
+ selectPlaylistCancelButton = null;
+ createPlaylistCancelButton?.Dispose();
+ createPlaylistCancelButton = null;
+ createPlaylistCreateButton?.Dispose();
+ createPlaylistCreateButton = null;
+
+ }
+ base.Dispose(type);
+ }
+
+ public void DeleteSelectorView()
+ {
+ Dispose(DisposeTypes.Explicit);
+ }
+
+ public CollectionView GetCollectionView()
+ {
+ return collectionView;
+ }
+
+ public void RemoveTheSelectPopup()
+ {
+ Window.Instance.Remove(selectPlaylistDialog);
+ }
+
+ public void RemoveTheCreatePopup()
+ {
+ Window.Instance.Remove(createPlaylistDialog);
+ }
+ }
+}