Add more menu in PlayerView and implemented create playlist feature in Playlist View 15/264515/1 accepted/tizen/unified/20210924.132707 submit/tizen/20210923.162342
authoraman.jeph <aman.jeph@samsung.com>
Thu, 23 Sep 2021 15:59:32 +0000 (21:29 +0530)
committeraman.jeph <aman.jeph@samsung.com>
Thu, 23 Sep 2021 15:59:32 +0000 (21:29 +0530)
Change-Id: Ie998930de4d9291036afd670668e0a51864dda6c
Signed-off-by: aman.jeph <aman.jeph@samsung.com>
12 files changed:
music-player/ViewModels/PlayerViewModel.cs
music-player/ViewModels/PlayingListViewModel.cs
music-player/ViewModels/PlaylistViewModel.cs
music-player/Views/PlayerView.cs
music-player/Views/PlaylistSelectorView.cs
music-player/Views/PlaylistView.cs
music-player/Views/SearchView.cs
music-player/res/images/cross_button.png [deleted file]
music-player/res/images/light/cross_button.png [new file with mode: 0755]
music-player/res/themes/dark.xaml
music-player/res/themes/light.xaml
packaging/org.tizen.MusicPlayer-1.0.0.tpk

index f2882c0352bafc2fa882662ae562bd9bddc09e86..e1ea1a1027a2c7fa6266b4c73f0e7f96438d7b7e 100755 (executable)
@@ -280,6 +280,30 @@ namespace MusicPlayer.ViewModels
             }
         }
 
+        public void OnCurrentTrackShare()
+        {
+            List<string> trackIdList = new List<string>()
+            {
+                playerModel.CurrentTrack.Id,
+            };
+            TrackDataProvider.ShareTrackList(trackIdList);
+        }
+
+        public void OnCurrentTrackDelete()
+        {
+            StopPlayback();
+            List<string> trackIdList = new List<string>()
+            {
+                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);
index fa683da46b4fbd23775045c74cf81887055b1190..debbc99528efb03e31326776123c2cc5b8ea89d6 100755 (executable)
@@ -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()
         {
index dd289721256e912037739cf3ca58a88f3d7d17b6..7f0775b7010933d1abe02480455eed3f6cc50385 100755 (executable)
@@ -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;
index 32a69ecaa51594eeb40e9feb0dfb235f40601cd1..b66ae8b8b50d3b23c8c4045ca43120b37665422c 100755 (executable)
@@ -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<View> { 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()
index 3c6cbeada9c83c9bbbb5dfbd27f5a5c58ad6a490..973f93c4f95561cfc817764dac988b2cc6a9d431 100755 (executable)
@@ -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;
index 4d905ad63da7a74eb72c4b434187231faa075261..6ad637a2e595219c61f85783fb9fc3c18e5c8138 100755 (executable)
@@ -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<View> 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<View> contentChilds = alertDialog.Content.Children.GetRange(0, alertDialog.Content.Children.Count);
+            List<View> actionContentChilds = alertDialog.ActionContent.Children.GetRange(0, alertDialog.ActionContent.Children.Count);
+            foreach (View child in contentChilds)
+            {
+                if (child != null)
+                {
+                    if (child.Name == "AlertDialogInputArea")
+                    {
+                        List<View> 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<View> { 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)
index 3cab90c7b39cc107766d7d70dc77df5fb8a8aec5..2ac62ae40611d4d9e2f6556da841551e0f8cca46 100755 (executable)
@@ -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<View> 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 (executable)
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 (executable)
index 0000000..2c9e1c3
Binary files /dev/null and b/music-player/res/images/light/cross_button.png differ
index 529f73d4eb5f30dee994ab2e342ce1e538c6bc63..c9ed54a6daedaf7418fa695a77f3ec4179d2dc87 100755 (executable)
@@ -6,6 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
 Id="LightTheme">
 
   <ViewStyle x:Key="AppBackground" BackgroundColor="#0E1017" />
+  <ViewStyle x:Key="InputLine" BackgroundColor="#FFFFFF" />
 
   <c:ButtonStyle x:Key="PrevButton" Size="48, 48" Position="168, 196" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
     <c:ButtonStyle.Icon>
@@ -170,4 +171,12 @@ Id="LightTheme">
 
   <ImageViewStyle x:Key="SelectAllBg" ResourceUrl="*Resource*/images/dark/selectall_bg.png" />
 
+  <c:ButtonStyle x:Key="ClearButton" Size="48, 48" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
+      <c:ButtonStyle.Icon>
+          <ImageViewStyle>
+                <ImageViewStyle.ResourceUrl>*Resource*/images/dark/cross_button.png</ImageViewStyle.ResourceUrl>
+          </ImageViewStyle>
+      </c:ButtonStyle.Icon>
+  </c:ButtonStyle>
+
 </Theme>
\ No newline at end of file
index 8ae333af53d36d563068a3cf0f908df8f631cf94..d938af022531d0f46b95e1adb67b519ff0f13614 100755 (executable)
@@ -6,6 +6,7 @@ xmlns:c="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
 Id="LightTheme">
 
   <ViewStyle x:Key="AppBackground" BackgroundColor="#EEEFF1" />
+  <ViewStyle x:Key="InputLine" BackgroundColor="#0A0E4A" />
 
   <c:ButtonStyle x:Key="PrevButton" Size="48, 48" Position="168, 196" BackgroundColor="Transparent">
     <c:ButtonStyle.Icon>
@@ -170,4 +171,12 @@ Id="LightTheme">
 
   <ImageViewStyle x:Key="SelectAllBg" ResourceUrl="*Resource*/images/light/selectall_bg.png" />
 
+  <c:ButtonStyle x:Key="ClearButton" Size="48, 48" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
+      <c:ButtonStyle.Icon>
+          <ImageViewStyle>
+                <ImageViewStyle.ResourceUrl>*Resource*/images/light/cross_button.png</ImageViewStyle.ResourceUrl>
+          </ImageViewStyle>
+      </c:ButtonStyle.Icon>
+  </c:ButtonStyle>
+
 </Theme>
\ No newline at end of file
index aff9ba58966ef691796bda868232840f9ac76d86..98fca5cf4217ae11741ec464aba366a0218ea698 100755 (executable)
Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ