From: aman.jeph Date: Fri, 18 Jun 2021 11:13:22 +0000 (+0530) Subject: Adding Lyrics View and related class X-Git-Tag: submit/tizen/20210915.141722~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f7981e20b28c588ab4f43946056abac34f92924;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Adding Lyrics View and related class Change-Id: Ifc100b49a80809775bc879f8c64ee89472bba9e7 Signed-off-by: aman.jeph --- diff --git a/Models/LyricsModel.cs b/Models/LyricsModel.cs new file mode 100644 index 0000000..6ea25e5 --- /dev/null +++ b/Models/LyricsModel.cs @@ -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 index 0000000..2c2df15 --- /dev/null +++ b/ViewModels/LyricsViewModel.cs @@ -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 index 0000000..234fe9a --- /dev/null +++ b/Views/LyricsView.cs @@ -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); + } + } +} diff --git a/Views/PlayerView.cs b/Views/PlayerView.cs index 3202405..d975dd6 100755 --- a/Views/PlayerView.cs +++ b/Views/PlayerView.cs @@ -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); diff --git a/Views/TrackLayout.cs b/Views/TrackLayout.cs index d9908ab..a3fe758 100755 --- a/Views/TrackLayout.cs +++ b/Views/TrackLayout.cs @@ -7,75 +7,75 @@ namespace MusicPlayer.Views { class TrackLayout : RecyclerViewItem { + private static int Width = 1792; + private static int Height = 108; + + private const int IconSize = 64; + private const int LayoutMargin = 16; + private const int LayoutPadding = 32; + private const int SeperatorHeight = 1; + private const int LeftPadding = 64; + private const int x = 0; + private View itemSeperator; private TextLabel titleLabel; private TextLabel subtitleLabel; private ImageView icon; - private static int WIDTH = 1792; - private static int HEIGHT = 108; - - private const int ICON_SIZE = 64; - private const int MARGIN = 16; - private const int PADDING = 32; - private const int SEPERATOR_HEIGHT = 1; - private const int LEFT_PADDING = 64; - private const int X = 0; - public TrackLayout(int width = 1792, int height = 108) : base() { base.OnInitialize(); base.IsCreateByXaml = true; - WIDTH = width; - HEIGHT = height; - WidthSpecification = WIDTH; - HeightSpecification = HEIGHT; + Width = width; + Height = height; + WidthSpecification = Width; + HeightSpecification = Height; // to show the rounded rect of the bg BackgroundColor = Color.Transparent; icon = new ImageView() { - WidthSpecification = ICON_SIZE, - HeightSpecification = ICON_SIZE, + WidthSpecification = IconSize, + HeightSpecification = IconSize, IsCreateByXaml = true, - Position2D = new Position2D(X, ((HEIGHT / 2) - (ICON_SIZE / 2))), + Position2D = new Position2D(x, ((Height / 2) - (IconSize / 2))), }; base.Add(icon); itemSeperator = new View() { - WidthSpecification = (WIDTH - (2 * LEFT_PADDING)), - HeightSpecification = SEPERATOR_HEIGHT, + WidthSpecification = (Width - (2 * LeftPadding)), + HeightSpecification = SeperatorHeight, ExcludeLayouting = true, - Position2D = new Position2D(X, HEIGHT - SEPERATOR_HEIGHT), + Position2D = new Position2D(x, Height - SeperatorHeight), BackgroundColor = UIColors.ItemSeperator, }; base.Add(itemSeperator); titleLabel = new TextLabel() { - WidthSpecification = (WIDTH - (2 * LEFT_PADDING) - ICON_SIZE - PADDING), + WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding), HeightSpecification = 40, TextColor = Color.Blue, PixelSize = 32, FontFamily = "BreezeSans", VerticalAlignment = VerticalAlignment.Center, IsCreateByXaml = true, - Position2D = new Position2D((X + ICON_SIZE + PADDING), MARGIN), + Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin), }; base.Add(titleLabel); subtitleLabel = new TextLabel() { - WidthSpecification = (WIDTH - (2 * LEFT_PADDING) - ICON_SIZE - PADDING), + WidthSpecification = (Width - (2 * LeftPadding) - IconSize - LayoutPadding), HeightSpecification = 36, TextColor = Color.Black, PixelSize = 28, FontFamily = "BreezeSans", VerticalAlignment = VerticalAlignment.Center, IsCreateByXaml = true, - Position2D = new Position2D((X + ICON_SIZE + PADDING), MARGIN + 40) + Position2D = new Position2D((x + IconSize + LayoutPadding), LayoutMargin + 40) }; base.Add(subtitleLabel); IsCreateByXaml = true;