From: aman.jeph Date: Thu, 23 Sep 2021 15:59:32 +0000 (+0530) Subject: Add more menu in PlayerView and implemented create playlist feature in Playlist View X-Git-Tag: submit/tizen/20210923.162342^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad0facfa50bcfe5c4bdbb9373e65c1a68202fc04;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Add more menu in PlayerView and implemented create playlist feature in Playlist View Change-Id: Ie998930de4d9291036afd670668e0a51864dda6c Signed-off-by: aman.jeph --- diff --git a/music-player/ViewModels/PlayerViewModel.cs b/music-player/ViewModels/PlayerViewModel.cs index f2882c0..e1ea1a1 100755 --- a/music-player/ViewModels/PlayerViewModel.cs +++ b/music-player/ViewModels/PlayerViewModel.cs @@ -280,6 +280,30 @@ namespace MusicPlayer.ViewModels } } + public void OnCurrentTrackShare() + { + List trackIdList = new List() + { + playerModel.CurrentTrack.Id, + }; + TrackDataProvider.ShareTrackList(trackIdList); + } + + public void OnCurrentTrackDelete() + { + StopPlayback(); + List trackIdList = new List() + { + playerModel.CurrentTrack.Id, + }; + TrackDataProvider.DeleteTrackList(trackIdList); + Track nextTrack = playingListViewModel.ForceNext(); + if(nextTrack != null) + { + SetCurrentTrack(nextTrack); + } + } + private void OnPlayingListItemSelected(object sender, PlayingListItemSelectedEvent e) { SetCurrentTrack((Track)e.CurrentSelectedItem); diff --git a/music-player/ViewModels/PlayingListViewModel.cs b/music-player/ViewModels/PlayingListViewModel.cs index fa683da..debbc99 100755 --- a/music-player/ViewModels/PlayingListViewModel.cs +++ b/music-player/ViewModels/PlayingListViewModel.cs @@ -143,8 +143,23 @@ namespace MusicPlayer.ViewModels ItemSelected?.Invoke(this, new PlayingListItemSelectedEvent(selectedItem)); } - public Track Next() - { + public Track ForceNext() + { + if (currentIndex < 0 || shuffleList.Count <= 0) + { + Tizen.Log.Error(AppConstants.LogTag, "Invalid track index"); + return null; + } + currentIndex += 1; + if(currentIndex >= shuffleList.Count) + { + currentIndex = 0; + } + return tracklistViewModel[shuffleList[currentIndex]]; + } + + public Track Next() + { if(currentIndex < 0 ) { Tizen.Log.Error(AppConstants.LogTag,"Invalid track index"); @@ -179,7 +194,7 @@ namespace MusicPlayer.ViewModels return tracklistViewModel[shuffleList[currentIndex]]; } } - } + } public Track Prev() { diff --git a/music-player/ViewModels/PlaylistViewModel.cs b/music-player/ViewModels/PlaylistViewModel.cs index dd28972..7f0775b 100755 --- a/music-player/ViewModels/PlaylistViewModel.cs +++ b/music-player/ViewModels/PlaylistViewModel.cs @@ -32,6 +32,17 @@ namespace MusicPlayer.ViewModels get => CreateUserPlayListViewModel(); } + public bool CreatePlaylist(string name) + { + Playlist newPlaylist = PlaylistManager.Instance.GetPlaylist(name); + if(newPlaylist == null) + { + PlaylistManager.Instance.AddPlaylist(name); + return true; + } + return false; + } + private string playlistCount; public string PlaylistCount @@ -106,8 +117,9 @@ namespace MusicPlayer.ViewModels foreach(Playlist playlist in playlists) { if (playlist.Name == AppConstants.FavouritePlaylist || playlist.Name == AppConstants.RecentlyAddedPlaylist) + { continue; - Tizen.Log.Error(AppConstants.LogTag, playlist.Id + ": "+playlist.Name); + } dataList.Add(new PlaylistData(playlist.Id, playlist.Name, GetTrackCountForPlaylist(playlist.Id), playlist.ThumbnailPath)); } return dataList; diff --git a/music-player/Views/PlayerView.cs b/music-player/Views/PlayerView.cs index 32a69ec..b66ae8b 100755 --- a/music-player/Views/PlayerView.cs +++ b/music-player/Views/PlayerView.cs @@ -179,6 +179,79 @@ namespace MusicPlayer.Views moreButton.ThemeChangeSensitive = true; moreButton.Position2D = new Position2D(Window.Instance.WindowSize.Width / 2 - LayoutPadding - IconSize, TopBarButtonsY); rightView.Add(moreButton); + moreButton.Clicked += OnMoreButtonClicked; + } + + private Menu CreateMenu() + { + Menu moreMenu = new Menu() + { + Anchor = moreButton, + HorizontalPositionToAnchor = Menu.RelativePosition.End, + VerticalPositionToAnchor = Menu.RelativePosition.End, + }; + return moreMenu; + } + + private void OnMoreButtonClicked(object sender, ClickedEventArgs e) + { + Menu moreMenu = CreateMenu(); + var share = new MenuItem { Text = "Share" }; + share.Clicked += (object o, ClickedEventArgs e) => + { + moreMenu?.Dismiss(); + viewModel.OnCurrentTrackShare(); + }; + + var delete = new MenuItem { Text = "Delete" }; + delete.Clicked += (object o, ClickedEventArgs e) => + { + moreMenu?.Dismiss(); + OnDeleteClicked(); + }; + + moreMenu.Items = new MenuItem[] { share, delete }; + moreMenu.Post(); + } + + private void RemoveAlertDialog(AlertDialog alertDialog, Button cancelButton, Button deleteButton) + { + Window.Instance.Remove(alertDialog); + alertDialog.Dispose(); + cancelButton.Dispose(); + deleteButton.Dispose(); + } + + private void OnDeleteClicked() + { + Button cancelbutton = new Button("CancelButton") + { + ThemeChangeSensitive = true, + }; + cancelbutton.TextLabel.FontStyle = UIFontStyles.AllNormal; + + Button deleteButton = new Button() + { + Text = "Delete", + }; + + AlertDialog alertDialog = new AlertDialog() + { + Title = "Delete", + Message = "This track will be deleted", + Actions = new List { cancelbutton, deleteButton }, + }; + + cancelbutton.Clicked += (object o, ClickedEventArgs e) => + { + RemoveAlertDialog(alertDialog, cancelbutton, deleteButton); + }; + deleteButton.Clicked += (object o, ClickedEventArgs e) => + { + viewModel.OnCurrentTrackDelete(); + RemoveAlertDialog(alertDialog, cancelbutton, deleteButton); + }; + Window.Instance.Add(alertDialog); } private void AddControlView() diff --git a/music-player/Views/PlaylistSelectorView.cs b/music-player/Views/PlaylistSelectorView.cs index 3c6cbea..973f93c 100755 --- a/music-player/Views/PlaylistSelectorView.cs +++ b/music-player/Views/PlaylistSelectorView.cs @@ -261,19 +261,9 @@ namespace MusicPlayer.Views textField.Text = viewModel.NewPlayListName; textField.TextChanged += TextFieldTextChanged; - ButtonStyle crossButtonStyle = new ButtonStyle() + crossButton = new Button("ClearButton") { - Icon = new ImageViewStyle() - { - ResourceUrl = Resources.GetImagePath() + "cross_button.png", - }, - IsSelectable = true, - IsEnabled = true, - }; - - crossButton = new Button(crossButtonStyle) - { - Size2D = new Size2D(48, 48), + ThemeChangeSensitive = true, Position2D = new Position2D(976, 6), }; crossButton.Clicked += CrossButtonClicked; diff --git a/music-player/Views/PlaylistView.cs b/music-player/Views/PlaylistView.cs index 4d905ad..6ad637a 100755 --- a/music-player/Views/PlaylistView.cs +++ b/music-player/Views/PlaylistView.cs @@ -12,6 +12,9 @@ namespace MusicPlayer.Views { class PlaylistView : BaseContentView { + + private const string DefaultPlaylistName = "My playlist"; + private TextLabel playlistCountLabel; private Button playlistCreateButton; private PlaylistViewModel viewModel; @@ -93,7 +96,7 @@ namespace MusicPlayer.Views private void OnPlaylistCreate(object sender, ClickedEventArgs e) { - // CreatePlaylistPopup(); + CreatePlaylistAlertDialog(); } private void OnPlaylistSelectionChange(object sender, SelectionChangedEventArgs e) @@ -109,10 +112,11 @@ namespace MusicPlayer.Views collectionView.SelectedItem = null; } - private void CreatePlaylistPopup() + private TextLabel CreateAlertDialogTitle() { TextLabel titleLabel = new TextLabel() { + Name = "AlertDialogTitle", StyleName = "LabelText", ThemeChangeSensitive = true, PixelSize = 40, @@ -120,48 +124,251 @@ namespace MusicPlayer.Views FontStyle = UIFontStyles.AllNormal, Text = "Create playlist", }; + return titleLabel; + } - View contentArea = new View() - { - SizeHeight = 144, - WidthResizePolicy = ResizePolicyType.FillToParent, - BackgroundColor = Color.Transparent, - }; - + private TextLabel CreateAlertDialogContentMessgae() + { TextLabel contentLabel = new TextLabel() { + Name = "AlertDialogContentMessage", StyleName = "LabelText", ThemeChangeSensitive = true, PixelSize = 32, FontFamily = "BreezeSans", FontStyle = UIFontStyles.NormalLight, Text = "Create a playlist", - WidthResizePolicy = ResizePolicyType.FillToParent, + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = 40, + HorizontalAlignment = HorizontalAlignment.Center, + }; + return contentLabel; + } + + private TextField CreatePlaylistNameField() + { + TextField inputTextField = new TextField() + { + Name = "AlertDialogInputField", + PlaceholderText = "Enter Playlist Name", + Text = DefaultPlaylistName, HorizontalAlignment = HorizontalAlignment.Begin, - PositionY = 40, }; - contentArea.Add(contentLabel); + return inputTextField; + } + + private Button CreateClearButton() + { + Button clearButton = new Button("ClearButton") + { + Name = "AlertDialogClearButton", + ThemeChangeSensitive = true, + Margin = new Extents(48, 0, 0, 0), + }; + return clearButton; + } + + private View CreateInputContent() + { + View inputArea = new View() + { + Name = "AlertDialogInputArea", + BackgroundColor = Color.Transparent, + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = 48, + Margin = new Extents(0, 0, 24, 0), + Layout = new RelativeLayout() + }; + return inputArea; + } + + private View CreateAlertDialogContent() + { + View contentArea = new View() + { + Name = "AlertDialogContent", + SizeWidth = 1024, + WidthSpecification = 1024, + SizeHeight = 240, + HeightSpecification = 240, + BackgroundColor = Color.Transparent, + Layout = new LinearLayout() + { + LinearOrientation = LinearLayout.Orientation.Vertical, + LinearAlignment = LinearLayout.Alignment.Center, + Margin = new Extents(0, 0, 0, 24), + } + }; + return contentArea; + } + private Button CreateAlertDialogCancelButton() + { Button cancelbutton = new Button("CancelButton") { + Name = "AlertDialogCancelButton", ThemeChangeSensitive = true, }; cancelbutton.TextLabel.FontStyle = UIFontStyles.AllNormal; - //cancelbutton.Clicked += OnCanelClicked; + return cancelbutton; + } - Button allowButton = new Button() + private Button CreateAlertDialogCreateButton() + { + Button createButton = new Button() { + Name = "AlertDialogCreateButton", Text = "Allow", }; - //allowButton.Clicked += OnAllowClicked; + return createButton; + } + + private void DeleteChildren(List childrenList) + { + if(childrenList == null || childrenList.Count == 0) + { + Tizen.Log.Error(AppConstants.LogTag, "List is empty, can't delete children"); + return; + } + foreach(View child in childrenList) + { + child?.Dispose(); + } + } + + private void RemoveAlertDialog(AlertDialog alertDialog) + { + List contentChilds = alertDialog.Content.Children.GetRange(0, alertDialog.Content.Children.Count); + List actionContentChilds = alertDialog.ActionContent.Children.GetRange(0, alertDialog.ActionContent.Children.Count); + foreach (View child in contentChilds) + { + if (child != null) + { + if (child.Name == "AlertDialogInputArea") + { + List inputAreaChildrenList = child.Children.GetRange(0, child.Children.Count); + DeleteChildren(inputAreaChildrenList); + } + child.Dispose(); + } + } + DeleteChildren(actionContentChilds); + Window.Instance.Remove(alertDialog); + alertDialog.Dispose(); + } + + private View CreateInputBaseLine() + { + View view = new View() + { + Name = "InputLineView", + StyleName = "InputLine", + HeightSpecification = 2, + WidthSpecification = LayoutParamPolicies.MatchParent, + }; + return view; + } + + private View CreateButtonArea() + { + View buttonArea = new View() + { + HeightSpecification = 136, + WidthSpecification = 1024, + Layout = new RelativeLayout(), + }; + return buttonArea; + } + + private void CreatePlaylistAlertDialog() + { + View contentArea = CreateAlertDialogContent(); + + TextLabel contentMessgae = CreateAlertDialogContentMessgae(); + contentArea.Add(contentMessgae); + + View inputArea = CreateInputContent(); + contentArea.Add(inputArea); + + View inputBaseLine = CreateInputBaseLine(); + contentArea.Add(inputBaseLine); + + TextField inputFiled = CreatePlaylistNameField(); + inputArea.Add(inputFiled); + RelativeLayout.SetLeftRelativeOffset(inputFiled, 0.0f); + RelativeLayout.SetFillHorizontal(inputFiled, true); + RelativeLayout.SetHorizontalAlignment(inputFiled, RelativeLayout.Alignment.Start); + + Button clearButton = CreateClearButton(); + inputArea.Add(clearButton); + clearButton.Clicked += (object o, ClickedEventArgs e) => + { + inputFiled.Text = string.Empty; + }; + RelativeLayout.SetRightRelativeOffset(clearButton, 1.0f); + RelativeLayout.SetHorizontalAlignment(clearButton, RelativeLayout.Alignment.End); + RelativeLayout.SetRightTarget(inputFiled, clearButton); + RelativeLayout.SetRightRelativeOffset(inputFiled, 0.0f); + + View buttonArea = CreateButtonArea(); + + Button cancelButton = CreateAlertDialogCancelButton(); + buttonArea.Add(cancelButton); + RelativeLayout.SetLeftRelativeOffset(cancelButton, 0.0f); + RelativeLayout.SetHorizontalAlignment(cancelButton, RelativeLayout.Alignment.Start); + RelativeLayout.SetVerticalAlignment(cancelButton, RelativeLayout.Alignment.Start); + + Button createButton = CreateAlertDialogCreateButton(); + buttonArea.Add(createButton); + RelativeLayout.SetRightRelativeOffset(createButton, 1.0f); + RelativeLayout.SetHorizontalAlignment(createButton, RelativeLayout.Alignment.End); + RelativeLayout.SetVerticalAlignment(createButton, RelativeLayout.Alignment.Start); AlertDialog alertDialog = new AlertDialog() { - TitleContent = titleLabel, + TitleContent = CreateAlertDialogTitle(), Content = contentArea, - Actions = new List { cancelbutton, allowButton }, + ActionContent = buttonArea }; Window.Instance.Add(alertDialog); + + cancelButton.Clicked += (object o, ClickedEventArgs e) => + { + RemoveAlertDialog(alertDialog); + }; + + createButton.Clicked += (object o, ClickedEventArgs e) => + { + if(OnPlaylistCreate(inputFiled.Text) == true) + { + RemoveAlertDialog(alertDialog); + } + }; + } + + private void ShowInfoMessage(string messgae) + { + Notification.MakeToast(messgae, Notification.ToastBottom).Post(Notification.ToastShort); + } + + private bool OnPlaylistCreate(string name) + { + if(string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name)) + { + ShowInfoMessage("Can't create playlist with empty or whitespace character only"); + return false; + } + if(name.Length > 64) + { + ShowInfoMessage("Playlist name can't be longer than 64 characters"); + return false; + } + if(viewModel.CreatePlaylist(name) == false) + { + ShowInfoMessage("Playlist name is already in use."); + return false; + } + return true; } private void OnDeleteClick(object sender, ClickedEventArgs e) diff --git a/music-player/Views/SearchView.cs b/music-player/Views/SearchView.cs index 3cab90c..2ac62ae 100755 --- a/music-player/Views/SearchView.cs +++ b/music-player/Views/SearchView.cs @@ -140,20 +140,10 @@ namespace MusicPlayer.Views }; textField.TextChanged += TextFieldTextChanged; - ButtonStyle crossButtonStyle = new ButtonStyle() - { - Icon = new ImageViewStyle() - { - ResourceUrl = Resources.GetImagePath() + "cross_button.png", - }, - IsSelectable = true, - IsEnabled = true, - }; - - crossButton = new Button(crossButtonStyle) + crossButton = new Button("ClearButton") { + ThemeChangeSensitive = true, Name = "crossButton", - Size2D = new Size2D(48, 48), Margin = new Extents(24, 0, 6, 6), Position2D = new Position2D(572, 6), }; @@ -337,8 +327,6 @@ namespace MusicPlayer.Views List children = searchBox.Children; foreach (View child in children) { - //TODO CHECK - Tizen.Log.Debug(AppConstants.LogTag, "child info " + child.Name); searchBox.Remove(child); child?.Dispose(); } diff --git a/music-player/res/images/cross_button.png b/music-player/res/images/cross_button.png deleted file mode 100755 index 2c9e1c3..0000000 Binary files a/music-player/res/images/cross_button.png and /dev/null differ diff --git a/music-player/res/images/light/cross_button.png b/music-player/res/images/light/cross_button.png new file mode 100755 index 0000000..2c9e1c3 Binary files /dev/null and b/music-player/res/images/light/cross_button.png differ diff --git a/music-player/res/themes/dark.xaml b/music-player/res/themes/dark.xaml index 529f73d..c9ed54a 100755 --- a/music-player/res/themes/dark.xaml +++ b/music-player/res/themes/dark.xaml @@ -6,6 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components" Id="LightTheme"> + @@ -170,4 +171,12 @@ Id="LightTheme"> + + + + *Resource*/images/dark/cross_button.png + + + + \ No newline at end of file diff --git a/music-player/res/themes/light.xaml b/music-player/res/themes/light.xaml index 8ae333a..d938af0 100755 --- a/music-player/res/themes/light.xaml +++ b/music-player/res/themes/light.xaml @@ -6,6 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components" Id="LightTheme"> + @@ -170,4 +171,12 @@ Id="LightTheme"> + + + + *Resource*/images/light/cross_button.png + + + + \ No newline at end of file diff --git a/packaging/org.tizen.MusicPlayer-1.0.0.tpk b/packaging/org.tizen.MusicPlayer-1.0.0.tpk index aff9ba5..98fca5c 100755 Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ