Adding Lyrics View and related class 08/260108/6
authoraman.jeph <aman.jeph@samsung.com>
Fri, 18 Jun 2021 11:13:22 +0000 (16:43 +0530)
committeraman.jeph <aman.jeph@samsung.com>
Tue, 22 Jun 2021 11:24:17 +0000 (16:54 +0530)
Change-Id: Ifc100b49a80809775bc879f8c64ee89472bba9e7
Signed-off-by: aman.jeph <aman.jeph@samsung.com>
Models/LyricsModel.cs [new file with mode: 0644]
ViewModels/LyricsViewModel.cs [new file with mode: 0644]
Views/LyricsView.cs [new file with mode: 0644]
Views/PlayerView.cs
Views/TrackLayout.cs

diff --git a/Models/LyricsModel.cs b/Models/LyricsModel.cs
new file mode 100644 (file)
index 0000000..6ea25e5
--- /dev/null
@@ -0,0 +1,35 @@
+using Tizen.Multimedia;
+using System.ComponentModel;
+using MusicPlayer.Common;
+
+namespace MusicPlayer.Models
+{
+    class LyricsModel: PropertyNotifier
+    {
+        public LyricsModel()
+        {
+        }
+
+        public LyricsModel(string thumbPath, string lyrics)
+        {
+            ThumbPath = thumbPath;
+            Lyrics = lyrics;
+        }
+
+        private string thumbPath;
+
+        public string ThumbPath
+        {
+            get => thumbPath;
+            set => SetProperty(ref thumbPath, value);
+        }
+
+        private string lyrics;
+
+        public string Lyrics
+        {
+            get => lyrics;
+            set => SetProperty(ref lyrics, value);
+        }
+    }
+}
diff --git a/ViewModels/LyricsViewModel.cs b/ViewModels/LyricsViewModel.cs
new file mode 100644 (file)
index 0000000..2c2df15
--- /dev/null
@@ -0,0 +1,44 @@
+using Tizen.Multimedia;
+using MusicPlayer.Models;
+
+namespace MusicPlayer.ViewModels
+{
+    class LyricsViewModel
+    {
+        internal LyricsModel lyricsModel;
+
+        public LyricsViewModel()
+        {
+            lyricsModel = new LyricsModel();
+        }
+
+        public LyricsViewModel(Track currentTrack)
+        {
+            FilePath = currentTrack.FilePath;
+            lyricsModel = new LyricsModel(currentTrack.ThumbnailPath, GetLyrics(FilePath));
+        }
+
+        public string FilePath { get; set; }
+
+        private Track currentTrack;
+
+        public Track CurrentTrack
+        {
+            get => currentTrack;
+            set
+            {
+                currentTrack = value;
+                FilePath = currentTrack.FilePath;
+                lyricsModel.ThumbPath = currentTrack.ThumbnailPath;
+                lyricsModel.Lyrics = GetLyrics(FilePath);
+            }
+        }
+
+        private string GetLyrics(string path)
+        {
+            var metadataExtractor = new MetadataExtractor(path);
+            Metadata metadata = metadataExtractor.GetMetadata();
+            return metadata.UnsyncLyrics;
+        }
+    }
+}
diff --git a/Views/LyricsView.cs b/Views/LyricsView.cs
new file mode 100644 (file)
index 0000000..234fe9a
--- /dev/null
@@ -0,0 +1,67 @@
+using Tizen.NUI;
+using Tizen.NUI.Binding;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+using MusicPlayer.ViewModels;
+using MusicPlayer.Common;
+
+namespace MusicPlayer.Views
+{
+    class LyricsView : View
+    {
+        private const int ViewSize = 784;
+        private const int LyricsViewMargin = 40;
+        private const int LyricsViewSize = 704;
+
+        private readonly LyricsViewModel lyricsViewModel;
+
+        private ImageView thumbView;
+        private ScrollableBase scrollView;
+        private TextLabel lyricsLabel;
+
+        public LyricsView(LyricsViewModel lyricsViewModel) : base()
+        {
+            this.lyricsViewModel = lyricsViewModel;
+            BindingContext = lyricsViewModel.lyricsModel;
+            Size2D = new Size2D(ViewSize, ViewSize);
+
+            AddThumbnail();
+            AddLyricsView();
+        }
+
+        private void AddThumbnail()
+        {
+            thumbView = new ImageView()
+            {
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+            };
+            thumbView.SetBinding(ImageView.ResourceUrlProperty, "ThumbPath");
+            base.Add(thumbView);
+        }
+
+        private void AddLyricsView()
+        {
+            scrollView = new ScrollableBase()
+            {
+                Position2D = new Position2D(LyricsViewMargin, LyricsViewMargin),
+                Size2D = new Size2D(LyricsViewSize, LyricsViewSize),
+                ScrollingDirection = ScrollableBase.Direction.Vertical,
+            };
+            base.Add(scrollView);
+
+            lyricsLabel = new TextLabel()
+            {
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+                BackgroundColor = UIColors.LyricsBackground,
+                TextColor = Color.White,
+                MultiLine = true,
+                LineWrapMode = LineWrapMode.Word,
+                PointSize = 25.0f,
+                HorizontalAlignment = HorizontalAlignment.Center,
+            };
+            lyricsLabel.SetBinding(TextLabel.TextProperty, "Lyrics");
+            scrollView.Add(lyricsLabel);
+        }
+    }
+}
index 3202405dbc0390b3ddd25055c72f86b41be1dbb2..d975dd627c6168fbf8d618804490b0caaae3a487 100755 (executable)
@@ -12,12 +12,14 @@ namespace MusicPlayer.Views
 {
     class PlayerView : View
     {
-        private const int LAYOUT_PADDING = 64;
-        private const int ICON_SIZE = 48;
-        private const int TOPBAR_SIZE = 120;
-        private const int CONTROL_VIEW_WIDTH = 640;
-        private const int CONTROL_VIEW_HEIGHT = 384;
-        private const int CONTROL_VIEW_MARGIN = 315;
+        private const int LayoutPadding = 64;
+        private const int IconSize = 48;
+        private const int TopBarSize = 120;
+        private const int ControlViewWidth = 640;
+        private const int ControlViewHeight = 384;
+        private const int ControlViewMargin = 315;
+        private const int TitleLabelHeight = 48;
+        private const int ArtistLabelHeight = 36;
 
         private View leftView;
         private View rightView;
@@ -83,7 +85,7 @@ namespace MusicPlayer.Views
 
             Button button = new Button(buttonStyle)
             {
-                Size2D = new Size2D(ICON_SIZE, ICON_SIZE),
+                Size2D = new Size2D(IconSize, IconSize),
                 Position2D = new Position2D(x, y),
             };
             return button;
@@ -117,10 +119,10 @@ namespace MusicPlayer.Views
 
         private void AddTopButtons()
         {
-            backButton = CreatButton(Resources.GetImagePath() + "back_button.png", LAYOUT_PADDING, (TOPBAR_SIZE / 2 - ICON_SIZE / 2));
+            backButton = CreatButton(Resources.GetImagePath() + "back_button.png", LayoutPadding, (TopBarSize / 2 - IconSize / 2));
             leftView.Add(backButton);
 
-            moreButton = CreatButton(Resources.GetImagePath() + "more_button.png", Window.Instance.WindowSize.Width / 2 - LAYOUT_PADDING - ICON_SIZE, (TOPBAR_SIZE / 2 - ICON_SIZE / 2));
+            moreButton = CreatButton(Resources.GetImagePath() + "more_button.png", Window.Instance.WindowSize.Width / 2 - LayoutPadding - IconSize, (TopBarSize / 2 - IconSize / 2));
             rightView.Add(moreButton);
         }
 
@@ -129,8 +131,8 @@ namespace MusicPlayer.Views
             controlsView = new View()
             {
                 BackgroundColor = Color.Transparent,
-                Size2D = new Size2D(640, 384),
-                Position2D = new Position2D((Window.Instance.WindowSize.Width / 4 - CONTROL_VIEW_WIDTH / 2), TOPBAR_SIZE + CONTROL_VIEW_MARGIN),
+                Size2D = new Size2D(ControlViewWidth, ControlViewHeight),
+                Position2D = new Position2D((Window.Instance.WindowSize.Width / 4 - ControlViewWidth / 2), TopBarSize + ControlViewMargin),
             };
             rightView.Add(controlsView);
         }
@@ -139,7 +141,7 @@ namespace MusicPlayer.Views
         {
             titleLabel = new TextLabel()
             {
-                Size2D = new Size2D(640, 48),
+                Size2D = new Size2D(ControlViewWidth, TitleLabelHeight),
                 Position2D = new Position2D(0, 0),
                 PixelSize = 36,
                 FontFamily = "BreezeSans",
@@ -153,7 +155,7 @@ namespace MusicPlayer.Views
 
             artistLabel = new TextLabel()
             {
-                Size2D = new Size2D(640, 36),
+                Size2D = new Size2D(ControlViewWidth, ArtistLabelHeight),
                 Position2D = new Position2D(0, 62),
                 PixelSize = 28,
                 FontFamily = "BreezeSans",
@@ -206,14 +208,14 @@ namespace MusicPlayer.Views
         {
             leftVolumeIcon = new ImageView(Resources.GetImagePath() + "left_sound_icon.png")
             {
-                Size2D = new Size2D(ICON_SIZE, ICON_SIZE),
+                Size2D = new Size2D(IconSize, IconSize),
                 Position2D = new Position2D(0, 336),
             };
             controlsView.Add(leftVolumeIcon);
 
             rightVolumeIcon = new ImageView(Resources.GetImagePath() + "right_sound_icon.png")
             {
-                Size2D = new Size2D(ICON_SIZE, ICON_SIZE),
+                Size2D = new Size2D(IconSize, IconSize),
                 Position2D = new Position2D(592, 336),
             };
             controlsView.Add(rightVolumeIcon);
@@ -335,7 +337,7 @@ namespace MusicPlayer.Views
             View actionButtonView = new View()
             {
                 Size2D = new Size2D(224, 48),
-                Position2D = new Position2D((Window.Instance.WindowSize.Width / 2 - 224 - LAYOUT_PADDING), 120),
+                Position2D = new Position2D((Window.Instance.WindowSize.Width / 2 - 224 - LayoutPadding), 120),
                 BackgroundColor = Color.Transparent,
             };
             rightView.Add(actionButtonView);
index d9908aba6fed5968c902653308041ed462d7972e..a3fe758f3f0af1a69f2b3e63c63a439d29bdf659 100755 (executable)
@@ -7,75 +7,75 @@ namespace MusicPlayer.Views
 {\r
     class TrackLayout : RecyclerViewItem\r
     {\r
+        private static int Width = 1792;\r
+        private static int Height = 108;\r
+\r
+        private const int IconSize = 64;\r
+        private const int LayoutMargin = 16;\r
+        private const int LayoutPadding = 32;\r
+        private const int SeperatorHeight = 1;\r
+        private const int LeftPadding = 64;\r
+        private const int x = 0;\r
+\r
         private View itemSeperator;\r
         private TextLabel titleLabel;\r
         private TextLabel subtitleLabel;\r
         private ImageView icon;\r
 \r
-        private static int WIDTH = 1792;\r
-        private static int HEIGHT = 108;\r
-\r
-        private const int ICON_SIZE = 64;\r
-        private const int MARGIN = 16;\r
-        private const int PADDING = 32;\r
-        private const int SEPERATOR_HEIGHT = 1;\r
-        private const int LEFT_PADDING = 64;\r
-        private const int X = 0;\r
-\r
         public TrackLayout(int width = 1792, int height = 108) : base()\r
         {\r
             base.OnInitialize();\r
             base.IsCreateByXaml = true;\r
-            WIDTH = width;\r
-            HEIGHT = height;\r
-            WidthSpecification = WIDTH;\r
-            HeightSpecification = HEIGHT;\r
+            Width = width;\r
+            Height = height;\r
+            WidthSpecification = Width;\r
+            HeightSpecification = Height;\r
 \r
             // to show the rounded rect of the bg\r
             BackgroundColor = Color.Transparent;\r
 \r
             icon = new ImageView()\r
             {\r
-                WidthSpecification = ICON_SIZE,\r
-                HeightSpecification = ICON_SIZE,\r
+                WidthSpecification = IconSize,\r
+                HeightSpecification = IconSize,\r
                 IsCreateByXaml = true,\r
-                Position2D = new Position2D(X, ((HEIGHT / 2) - (ICON_SIZE / 2))),\r
+                Position2D = new Position2D(x, ((Height / 2) - (IconSize / 2))),\r
             };\r
             base.Add(icon);\r
 \r
             itemSeperator = new View()\r
             {\r
-                WidthSpecification = (WIDTH - (2 * LEFT_PADDING)),\r
-                HeightSpecification = SEPERATOR_HEIGHT,\r
+                WidthSpecification = (Width - (2 * LeftPadding)),\r
+                HeightSpecification = SeperatorHeight,\r
                 ExcludeLayouting = true,\r
-                Position2D = new Position2D(X, HEIGHT - SEPERATOR_HEIGHT),\r
+                Position2D = new Position2D(x, Height - SeperatorHeight),\r
                 BackgroundColor = UIColors.ItemSeperator,\r
             };\r
             base.Add(itemSeperator);\r
 \r
             titleLabel = new TextLabel()\r
             {\r
-                WidthSpecification = (WIDTH - (2 * LEFT_PADDING) - ICON_SIZE - PADDING),\r
+                WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding),\r
                 HeightSpecification = 40,\r
                 TextColor = Color.Blue,\r
                 PixelSize = 32,\r
                 FontFamily = "BreezeSans",\r
                 VerticalAlignment = VerticalAlignment.Center,\r
                 IsCreateByXaml = true,\r
-                Position2D = new Position2D((X + ICON_SIZE + PADDING), MARGIN),\r
+                Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin),\r
             };\r
             base.Add(titleLabel);\r
 \r
             subtitleLabel = new TextLabel()\r
             {\r
-                WidthSpecification = (WIDTH - (2 * LEFT_PADDING) - ICON_SIZE - PADDING),\r
+                WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding),\r
                 HeightSpecification = 36,\r
                 TextColor = Color.Black,\r
                 PixelSize = 28,\r
                 FontFamily = "BreezeSans",\r
                 VerticalAlignment = VerticalAlignment.Center,\r
                 IsCreateByXaml = true,\r
-                Position2D = new Position2D((X + ICON_SIZE + PADDING), MARGIN + 40)\r
+                Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin + 40)\r
             };\r
             base.Add(subtitleLabel);\r
             IsCreateByXaml = true;\r