Fixing binding issues 55/273555/2 accepted/tizen/unified/20220421.065407 submit/tizen/20220408.090947 submit/tizen/20220418.085441
authoraman.jeph <aman.jeph@samsung.com>
Thu, 7 Apr 2022 13:14:21 +0000 (18:44 +0530)
committeraman.jeph <aman.jeph@samsung.com>
Thu, 7 Apr 2022 13:20:10 +0000 (18:50 +0530)
Change-Id: I5c240f10f9e2b30c33c95f4d657df64bab8f9d58
Signed-off-by: aman.jeph <aman.jeph@samsung.com>
music-player/ViewModels/LyricsViewModel.cs
music-player/Views/LyricsView.cs
music-player/Views/MiniPlayer.cs
music-player/Views/PlayerView.cs
packaging/org.tizen.MusicPlayer-1.0.0.tpk

index 77ea5c9fe06c804bffba0298bf390f8ba54e63f1..e63868e6e93715da0b2c866f2dcfbe6b197557f9 100755 (executable)
@@ -45,15 +45,7 @@ namespace MusicPlayer.ViewModels
         public Track CurrentTrack
         {
             get => currentTrack;
-            set
-            {
-                currentTrack = value;
-                AnimationState state = currentTrack.IsThumbPathExists ? AnimationState.NoAnimation : AnimationState.Animation;
-                UpdateTrackThumbState(state);
-                FilePath = currentTrack.FilePath;
-                lyricsModel.ThumbPath = currentTrack.ThumbnailPath;
-                lyricsModel.Lyrics = GetLyrics(FilePath);
-            }
+            set => UpdateCurrentTrack(value);
         }
 
         private Color lyricsBackgroundColor;
@@ -70,6 +62,16 @@ namespace MusicPlayer.ViewModels
             TrackThumbState?.Invoke(this, new TrackThumbStateEventArgs(trackState));
         }
 
+        private void UpdateCurrentTrack(Track track)
+        {
+            currentTrack = track;
+            AnimationState state = currentTrack.IsThumbPathExists ? AnimationState.NoAnimation : AnimationState.Animation;
+            UpdateTrackThumbState(state);
+            FilePath = currentTrack.FilePath;
+            lyricsModel.ThumbPath = currentTrack.ThumbnailPath;
+            lyricsModel.Lyrics = GetLyrics(FilePath);
+        }
+
         private string GetLyrics(string path)
         {
             string lyrics = string.Empty;
index 818c648029292f6b96b5040ccb58d17bbfcd0937..4b9b53c92ce54efe916551e00d47ec4062a31ce0 100755 (executable)
@@ -41,6 +41,22 @@ namespace MusicPlayer.Views
             AddLyricsView();
             AddRiveAnimation();
             lyricsViewModel.TrackThumbState += OnTrackStateChanged;
+
+            // This is set to the binding after the Lyrics is added to scene graph.
+            // If we set the binding before view is added to scene-graph/window than binding doesn't seem to work.
+            AddedToWindow += OnAddedToWindow;
+        }
+
+        private void OnAddedToWindow(object sender, System.EventArgs e)
+        {
+            thumbView.BindingContext = lyricsViewModel.lyricsModel;
+            thumbView.SetBinding(ImageView.ResourceUrlProperty, "ThumbPath");
+
+            scrollView.BindingContext = lyricsViewModel;
+            scrollView.SetBinding(View.BackgroundColorProperty, "LyricsBackgroundColor");
+
+            lyricsLabel.BindingContext = lyricsViewModel.lyricsModel;
+            lyricsLabel.SetBinding(TextLabel.TextProperty, "Lyrics");
         }
 
         protected override void Dispose(DisposeTypes type)
@@ -52,22 +68,23 @@ namespace MusicPlayer.Views
             if(type == DisposeTypes.Explicit)
             {
                 albumRiveAnimation.Stop();
-                base.Remove(albumRiveAnimation);
+                Remove(albumRiveAnimation);
                 albumRiveAnimation.Dispose();
                 albumRiveAnimation = null;
 
-                base.Remove(lyricsLabel);
+                Remove(lyricsLabel);
                 lyricsLabel.Dispose();
                 lyricsLabel = null;
 
-                base.Remove(scrollView);
+                Remove(scrollView);
                 scrollView.Dispose();
                 scrollView = null;
 
-                base.Remove(thumbView);
+                Remove(thumbView);
                 thumbView.Dispose();
                 thumbView = null;
                 lyricsViewModel.TrackThumbState -= OnTrackStateChanged;
+                AddedToWindow -= OnAddedToWindow;
             }
             base.Dispose(type);
         }
@@ -110,9 +127,8 @@ namespace MusicPlayer.Views
                 BoxShadow = new Shadow(6.0f, Color.Black, new Vector2(0, 3)),
                 Margin = new Extents(0, 0, 0, 0),
             };
-            thumbView.SetBinding(ImageView.ResourceUrlProperty, "ThumbPath");
+            Add(thumbView);
             FlexLayout.SetFlexPositionType(thumbView, FlexLayout.PositionType.Absolute);
-            base.Add(thumbView);
         }
 
         private void AddLyricsView()
@@ -138,8 +154,6 @@ namespace MusicPlayer.Views
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
                 BackgroundColor = Color.Transparent,
             };
-            scrollView.BindingContext = lyricsViewModel;
-            scrollView.SetBinding(View.BackgroundColorProperty, "LyricsBackgroundColor");
             lyricsScrollBaseView.Add(scrollView);
 
             lyricsLabel = new TextLabel()
@@ -155,8 +169,6 @@ namespace MusicPlayer.Views
                 HorizontalAlignment = HorizontalAlignment.Center,
                 VerticalAlignment = VerticalAlignment.Top,
             };
-            lyricsLabel.BindingContext = lyricsViewModel.lyricsModel;
-            lyricsLabel.SetBinding(TextLabel.TextProperty, "Lyrics");
             scrollView.Add(lyricsLabel);
         }
 
index e9b5b3212f87ed9562f971704a34c9d3b9081b20..b6b861d1a6ad87fd8ccdc8456f62427ff4cdee35 100755 (executable)
-using Tizen.NUI;\r
-using Tizen.NUI.Components;\r
-using Tizen.NUI.BaseComponents;\r
-using Tizen.NUI.Binding;\r
-using MusicPlayer.Common;\r
-using MusicPlayer.ViewModels;\r
-using MusicPlayer.Views.Utils;\r
-using System.Collections.Generic;\r
-using MusicPlayer.Core;\r
-\r
-namespace MusicPlayer.Views\r
-{\r
-    class MiniPlayer : View\r
-    {\r
-        private const int SliderHeight = 38;\r
-        private ImageView thumbnail;\r
-        private View trackInfo;\r
-        private View trackTextView;\r
-        private TextLabel titleLabel;\r
-        private TextLabel artistLabel;\r
-\r
-        private View controlsView;\r
-        private View sliderView;\r
-        private MultiStateButton playButton;\r
-        private Button prevButton;\r
-        private Button nextButton;\r
-        private Slider playbackSlider;\r
-        private TextLabel currentTime;\r
-        private TextLabel totalTime;\r
-        private View baseView;\r
-        private readonly PlayerViewModel viewModel;\r
-\r
-        public MiniPlayer(PlayerViewModel viewModel) : base()\r
-        {\r
-            this.viewModel = viewModel;\r
-            BindingContext = viewModel.playerModel;\r
-            StyleName = "MiniPlayer";\r
-            ThemeChangeSensitive = true;\r
-            WidthSpecification = LayoutParamPolicies.MatchParent;\r
-            HeightSpecification = (DeviceInfo.IsPortrait ? 170 : 124).SpToPx();\r
-\r
-            Layout = new LinearLayout()\r
-            {\r
-                LinearOrientation = LinearLayout.Orientation.Vertical,\r
-            };\r
-            AddSeparatorLine();\r
-            baseView = new View()\r
-            {\r
-                WidthSpecification = LayoutParamPolicies.MatchParent,\r
-                HeightSpecification = 123.SpToPx(),\r
-                BackgroundColor = Color.Transparent,\r
-                Layout = new LinearLayout()\r
-                {\r
-                    LinearOrientation = LinearLayout.Orientation.Horizontal,\r
-                    VerticalAlignment = VerticalAlignment.Center,\r
-                },\r
-                Padding = new Extents(64, 64, 24, 19).SpToPx(),\r
-            };\r
-            if(DeviceInfo.IsPortrait)\r
-            {\r
-                baseView.Padding = new Extents(33, 33, 24, 8).SpToPx();\r
-                baseView.HeightSpecification = 108.SpToPx();\r
-            }\r
-            Add(baseView);\r
-            AddTrackDetails();\r
-            AddControlElements();\r
-            AddSliderElements();\r
-        }\r
-\r
-        private void AddSeparatorLine()\r
-        {\r
-            View separator = new View()\r
-            {\r
-                WidthSpecification = LayoutParamPolicies.MatchParent,\r
-                HeightSpecification = 1.SpToPx(),\r
-                StyleName = "InputLine",\r
-            };\r
-            Add(separator);\r
-        }\r
-\r
-        private void AddTrackDetails()\r
-        {\r
-            trackInfo = new View()\r
-            {\r
-                Layout = new LinearLayout()\r
-                {\r
-                    LinearOrientation = LinearLayout.Orientation.Horizontal,\r
-                },\r
-                BackgroundColor = Color.Transparent,\r
-            };\r
-            trackInfo.WidthSpecification = (DeviceInfo.IsPortrait ? 536 : 622).SpToPx();\r
-            trackInfo.HeightSpecification = 76.SpToPx();\r
-            baseView.Add(trackInfo);\r
-            AddThumbnail();\r
-            AddTrackTextLabels();\r
-        }\r
-\r
-        private void AddTrackTextLabels()\r
-        {\r
-            trackTextView = new View()\r
-            {\r
-                BackgroundColor = Color.Transparent,\r
-                Layout = new LinearLayout()\r
-                {\r
-                    LinearOrientation = LinearLayout.Orientation.Vertical,\r
-                },\r
-                HeightSpecification = 76.SpToPx(),\r
-            };\r
-            if(DeviceInfo.IsPortrait)\r
-            {\r
-                trackTextView.WidthSpecification = 436.SpToPx();\r
-                trackTextView.Margin = new Extents(24, 0, 0, 0);\r
-            }\r
-            else\r
-            {\r
-                trackTextView.WidthSpecification = 516.SpToPx();\r
-                trackTextView.Margin = new Extents(30, 0, 0, 0);\r
-            }\r
-            trackInfo.Add(trackTextView);\r
-            AddTrackName();\r
-            AddArtistName();\r
-        }\r
-\r
-        private void AddThumbnail()\r
-        {\r
-            thumbnail = new ImageView()\r
-            {\r
-                BackgroundColor = UIColors.HEXEEEFF1,\r
-                Size2D = new Size2D(76, 76).SpToPx(),\r
-            };\r
-            thumbnail.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath");\r
-            thumbnail.TouchEvent += (object source, TouchEventArgs e) =>\r
-            {\r
-                PlaybackHelper.Instance.ShowPlayer();\r
-                return true;\r
-            };\r
-            trackInfo.Add(thumbnail);\r
-        }\r
-\r
-        private void AddTrackName()\r
-        {\r
-            titleLabel = new TextLabel()\r
-            {\r
-                StyleName = "TitleText",\r
-                ThemeChangeSensitive = true,\r
-                WidthSpecification = LayoutParamPolicies.MatchParent,\r
-                HeightSpecification = 48.SpToPx(),\r
-                PixelSize = 36.SpToPx(),\r
-                FontFamily = "BreezeSans",\r
-                HorizontalAlignment = HorizontalAlignment.Begin,\r
-                VerticalAlignment = VerticalAlignment.Center,\r
-                Ellipsis = true,\r
-            };\r
-            titleLabel.SetBinding(TextLabel.TextProperty, "TrackName");\r
-            trackTextView.Add(titleLabel);\r
-        }\r
-\r
-        private void AddArtistName()\r
-        {\r
-            artistLabel = new TextLabel()\r
-            {\r
-                StyleName = "TitleText",\r
-                ThemeChangeSensitive = true,\r
-                WidthSpecification = LayoutParamPolicies.MatchParent,\r
-                HeightSpecification = 28.SpToPx(),\r
-                PixelSize = 22.SpToPx(),\r
-                FontFamily = "BreezeSans",\r
-                HorizontalAlignment = HorizontalAlignment.Begin,\r
-                VerticalAlignment = VerticalAlignment.Center,\r
-                Ellipsis = true,\r
-            };\r
-            artistLabel.SetBinding(TextLabel.TextProperty, "TrackArtist");\r
-            trackTextView.Add(artistLabel);\r
-        }\r
-        private void AddControlElements()\r
-        {\r
-            controlsView = new View()\r
-            {\r
-                WidthSpecification = 304.SpToPx(),\r
-                Layout = new LinearLayout()\r
-                {\r
-                    LinearOrientation = LinearLayout.Orientation.Horizontal,\r
-                    HorizontalAlignment = HorizontalAlignment.Begin,\r
-                    VerticalAlignment = VerticalAlignment.Center,\r
-                    CellPadding = new Size2D(80, 0).SpToPx(),\r
-                },\r
-                Margin = new Extents(120, 120, 0, 0).SpToPx(),\r
-                BackgroundColor = Color.Transparent,\r
-            };\r
-            baseView.Add(controlsView);\r
-            AddPreviousButton();\r
-            AddPlayButton();\r
-            AddNextButton();\r
-        }\r
-\r
-        private void AddPreviousButton()\r
-        {\r
-            prevButton = new Button("PrevButton")\r
-            {\r
-                ThemeChangeSensitive = true,\r
-            };\r
-            prevButton.Clicked += (object sender, ClickedEventArgs e) =>\r
-            {\r
-                viewModel.PrevButtonClicked();\r
-            };\r
-            prevButton.BindingContext = viewModel;\r
-            prevButton.SetBinding(IsEnabledProperty, "HasPreviousTrack");\r
-            controlsView.Add(prevButton);\r
-        }\r
-\r
-        private void AddPlayButton()\r
-        {\r
-            playButton = new MultiStateButton()\r
-            {\r
-                Size2D = new Size2D(48, 48).SpToPx(),\r
-                BackgroundColor = Color.Transparent,\r
-                IconResources = new Dictionary<ThemeType, Dictionary<string, StringSelector>>()\r
-                {\r
-                    {\r
-                        ThemeType.Light,\r
-                        new Dictionary<string, StringSelector>()\r
-                        {\r
-                            {\r
-                                "Play",\r
-                                new StringSelector()\r
-                                {\r
-                                    Normal = Resources.GetImagePath() + "light/play.png",\r
-                                    Pressed = Resources.GetImagePath() + "play_pressed.png",\r
-                                    Disabled = Resources.GetImagePath() + "play_disabled.png",\r
-                                }\r
-                            },\r
-                            {\r
-                                "Pause",\r
-                                new StringSelector()\r
-                                {\r
-                                    Normal = Resources.GetImagePath() + "light/pause.png",\r
-                                    Pressed = Resources.GetImagePath() + "pause_pressed.png",\r
-                                    Disabled = Resources.GetImagePath() + "pause_disabled.png",\r
-                                }\r
-                            },\r
-                        }\r
-                    },\r
-                    {\r
-                        ThemeType.Dark,\r
-                        new Dictionary<string, StringSelector>()\r
-                        {\r
-                            {\r
-                                "Play",\r
-                                new StringSelector()\r
-                                {\r
-                                    Normal = Resources.GetImagePath() + "dark/play.png",\r
-                                    Pressed = Resources.GetImagePath() + "play_pressed.png",\r
-                                    Disabled = Resources.GetImagePath() + "play_disabled.png",\r
-                                }\r
-                            },\r
-                            {\r
-                                "Pause",\r
-                                new StringSelector()\r
-                                {\r
-                                    Normal = Resources.GetImagePath() + "dark/pause.png",\r
-                                    Pressed = Resources.GetImagePath() + "pause_pressed.png",\r
-                                    Disabled = Resources.GetImagePath() + "pause_disabled.png",\r
-                                }\r
-                            },\r
-                        }\r
-                    }\r
-                },\r
-            };\r
-            playButton.BindingContext = viewModel;\r
-            playButton.SetBinding(MultiStateButton.CustomStateProperty, "PlayButtonState");\r
-            controlsView.Add(playButton);\r
-            playButton.Clicked += (object sender, ClickedEventArgs e) =>\r
-            {\r
-                viewModel.PlayingStatusChanged();\r
-            };\r
-        }\r
-\r
-        private void AddNextButton()\r
-        {\r
-            nextButton = new Button("NextButton")\r
-            {\r
-                ThemeChangeSensitive = true,\r
-            };\r
-            nextButton.Clicked += (object sender, ClickedEventArgs e) =>\r
-            {\r
-                viewModel.NextButtonClicked();\r
-            };\r
-            nextButton.BindingContext = viewModel;\r
-            nextButton.SetBinding(IsEnabledProperty, "HasNextTrack");\r
-            controlsView.Add(nextButton);\r
-        }\r
-\r
-        private void AddSliderElements()\r
-        {\r
-            AddPlaybackSlider();\r
-            AddCurrentTimeLabel();\r
-            AddTotalTimeLabel();\r
-            sliderView = new View();\r
-            sliderView.BackgroundColor = Color.Transparent;\r
-            sliderView.WidthResizePolicy = ResizePolicyType.FillToParent;\r
-            if (DeviceInfo.IsPortrait)\r
-            {\r
-                sliderView.Layout = new LinearLayout()\r
-                {\r
-                    LinearOrientation = LinearLayout.Orientation.Horizontal,\r
-                    VerticalAlignment = VerticalAlignment.Center,\r
-                    Padding = new Extents(33, 33, 0, 8).SpToPx(),\r
-                };\r
-                sliderView.SizeHeight = 61.SpToPx();\r
-                base.Add(sliderView);\r
-                currentTime.WidthSpecification = 72.SpToPx();\r
-                sliderView.Add(currentTime);\r
-                playbackSlider.WidthSpecification = 872.SpToPx();\r
-                sliderView.Add(playbackSlider);\r
-                totalTime.WidthSpecification = 72.SpToPx();\r
-                sliderView.Add(totalTime);\r
-            }\r
-            else\r
-            {\r
-                sliderView.SizeHeight = 24.SpToPx();\r
-                baseView.Add(playbackSlider);\r
-                sliderView.Layout = new RelativeLayout();\r
-                sliderView.Position2D = new Position2D(0, SliderHeight).SpToPx();\r
-                playbackSlider.Add(sliderView);\r
-                sliderView.Add(currentTime);\r
-                RelativeLayout.SetHorizontalAlignment(currentTime, RelativeLayout.Alignment.Start);\r
-                sliderView.Add(totalTime);\r
-                RelativeLayout.SetHorizontalAlignment(totalTime, RelativeLayout.Alignment.End);\r
-            }\r
-        }\r
-\r
-        private void AddPlaybackSliderEventHandler()\r
-        {\r
-            playbackSlider.SlidingStarted += (object sender, SliderSlidingStartedEventArgs e) =>\r
-            {\r
-                viewModel.StopPlaybackTimer();\r
-            };\r
-            playbackSlider.ValueChanged += (object sender, SliderValueChangedEventArgs e) =>\r
-            {\r
-                viewModel.SetElapsedTime(e.CurrentValue);\r
-            };\r
-            playbackSlider.SlidingFinished += (object sender, SliderSlidingFinishedEventArgs e) =>\r
-            {\r
-                viewModel.UpdatePlayerPosition(e.CurrentValue);\r
-            };\r
-        }\r
-\r
-        private void AddPlaybackSlider()\r
-        {\r
-            playbackSlider = new Slider("Slider")\r
-            {\r
-                ThemeChangeSensitive = true,\r
-                MinValue = 0.0f,\r
-                MaxValue = 1.0f,\r
-                WidthSpecification = 626.SpToPx(),\r
-                HeightSpecification = SliderHeight.SpToPx(),\r
-                ThumbSize = new Tizen.NUI.Size(30, 30).SpToPx(),\r
-                Direction = Slider.DirectionType.Horizontal,\r
-            };\r
-            playbackSlider.SetBinding(Slider.CurrentValueProperty, "ElapsedTime");\r
-            AddPlaybackSliderEventHandler();\r
-        }\r
-\r
-        private void AddCurrentTimeLabel()\r
-        {\r
-            currentTime = new TextLabel()\r
-            {\r
-                StyleName = "TitleText",\r
-                ThemeChangeSensitive = true,\r
-                Size2D = new Size2D(180, 24).SpToPx(),\r
-                PixelSize = 18.SpToPx(),\r
-                FontFamily = "BreezeSans",\r
-                Text = "00::00:00",\r
-                HorizontalAlignment = HorizontalAlignment.Begin,\r
-            };\r
-            currentTime.SetBinding(TextLabel.TextProperty, "PlayingTime");\r
-        }\r
-\r
-        private void AddTotalTimeLabel()\r
-        {\r
-            totalTime = new TextLabel()\r
-            {\r
-                StyleName = "TitleText",\r
-                ThemeChangeSensitive = true,\r
-                Size2D = new Size2D(180, 24).SpToPx(),\r
-                PixelSize = 18.SpToPx(),\r
-                FontFamily = "BreezeSans",\r
-                HorizontalAlignment = HorizontalAlignment.End,\r
-                Text = "59:59:59",\r
-            };\r
-            totalTime.SetBinding(TextLabel.TextProperty, "TrackLength");\r
-        }\r
-\r
-        public void ShowView()\r
-        {\r
-            Show();\r
-        }\r
-\r
-        public void HideView()\r
-        {\r
-            Hide();\r
-        }\r
-    }\r
-}\r
+using Tizen.NUI;
+using Tizen.NUI.Components;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Binding;
+using MusicPlayer.Common;
+using MusicPlayer.ViewModels;
+using MusicPlayer.Views.Utils;
+using System.Collections.Generic;
+using MusicPlayer.Core;
+
+namespace MusicPlayer.Views
+{
+    class MiniPlayer : View
+    {
+        private const int SliderHeight = 38;
+        private ImageView thumbnail;
+        private View trackInfo;
+        private View trackTextView;
+        private TextLabel titleLabel;
+        private TextLabel artistLabel;
+
+        private View controlsView;
+        private View sliderView;
+        private MultiStateButton playButton;
+        private Button prevButton;
+        private Button nextButton;
+        private Slider playbackSlider;
+        private TextLabel currentTime;
+        private TextLabel totalTime;
+        private View baseView;
+        private readonly PlayerViewModel viewModel;
+
+        public MiniPlayer(PlayerViewModel viewModel) : base()
+        {
+            this.viewModel = viewModel;
+            BindingContext = viewModel.playerModel;
+            StyleName = "MiniPlayer";
+            ThemeChangeSensitive = true;
+            WidthSpecification = LayoutParamPolicies.MatchParent;
+            HeightSpecification = (DeviceInfo.IsPortrait ? 170 : 124).SpToPx();
+
+            Layout = new LinearLayout()
+            {
+                LinearOrientation = LinearLayout.Orientation.Vertical,
+            };
+            AddSeparatorLine();
+            baseView = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = 123.SpToPx(),
+                BackgroundColor = Color.Transparent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    VerticalAlignment = VerticalAlignment.Center,
+                },
+                Padding = new Extents(64, 64, 24, 19).SpToPx(),
+            };
+            if(DeviceInfo.IsPortrait)
+            {
+                baseView.Padding = new Extents(33, 33, 24, 8).SpToPx();
+                baseView.HeightSpecification = 108.SpToPx();
+            }
+            Add(baseView);
+            AddTrackDetails();
+            AddControlElements();
+            AddSliderElements();
+        }
+
+        private void AddSeparatorLine()
+        {
+            View separator = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = 1.SpToPx(),
+                StyleName = "InputLine",
+            };
+            Add(separator);
+        }
+
+        private void AddTrackDetails()
+        {
+            trackInfo = new View()
+            {
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                },
+                BackgroundColor = Color.Transparent,
+            };
+            trackInfo.WidthSpecification = (DeviceInfo.IsPortrait ? 536 : 622).SpToPx();
+            trackInfo.HeightSpecification = 76.SpToPx();
+            baseView.Add(trackInfo);
+            AddThumbnail();
+            AddTrackTextLabels();
+        }
+
+        private void AddTrackTextLabels()
+        {
+            trackTextView = new View()
+            {
+                BackgroundColor = Color.Transparent,
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                },
+                HeightSpecification = 76.SpToPx(),
+            };
+            if(DeviceInfo.IsPortrait)
+            {
+                trackTextView.WidthSpecification = 436.SpToPx();
+                trackTextView.Margin = new Extents(24, 0, 0, 0);
+            }
+            else
+            {
+                trackTextView.WidthSpecification = 516.SpToPx();
+                trackTextView.Margin = new Extents(30, 0, 0, 0);
+            }
+            trackInfo.Add(trackTextView);
+            AddTrackName();
+            AddArtistName();
+        }
+
+        private void AddThumbnail()
+        {
+            thumbnail = new ImageView()
+            {
+                BackgroundColor = UIColors.HEXEEEFF1,
+                Size2D = new Size2D(76, 76).SpToPx(),
+            };
+            trackInfo.Add(thumbnail);
+            thumbnail.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath");
+            thumbnail.TouchEvent += (object source, TouchEventArgs e) =>
+            {
+                PlaybackHelper.Instance.ShowPlayer();
+                return true;
+            };
+        }
+
+        private void AddTrackName()
+        {
+            titleLabel = new TextLabel()
+            {
+                StyleName = "TitleText",
+                ThemeChangeSensitive = true,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = 48.SpToPx(),
+                PixelSize = 36.SpToPx(),
+                FontFamily = "BreezeSans",
+                HorizontalAlignment = HorizontalAlignment.Begin,
+                VerticalAlignment = VerticalAlignment.Center,
+                Ellipsis = true,
+            };
+            trackTextView.Add(titleLabel);
+            titleLabel.SetBinding(TextLabel.TextProperty, "TrackName");
+        }
+
+        private void AddArtistName()
+        {
+            artistLabel = new TextLabel()
+            {
+                StyleName = "TitleText",
+                ThemeChangeSensitive = true,
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = 28.SpToPx(),
+                PixelSize = 22.SpToPx(),
+                FontFamily = "BreezeSans",
+                HorizontalAlignment = HorizontalAlignment.Begin,
+                VerticalAlignment = VerticalAlignment.Center,
+                Ellipsis = true,
+            };
+            trackTextView.Add(artistLabel);
+            artistLabel.SetBinding(TextLabel.TextProperty, "TrackArtist");
+        }
+        private void AddControlElements()
+        {
+            controlsView = new View()
+            {
+                WidthSpecification = 304.SpToPx(),
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    HorizontalAlignment = HorizontalAlignment.Begin,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    CellPadding = new Size2D(80, 0).SpToPx(),
+                },
+                Margin = new Extents(120, 120, 0, 0).SpToPx(),
+                BackgroundColor = Color.Transparent,
+            };
+            baseView.Add(controlsView);
+            AddPreviousButton();
+            AddPlayButton();
+            AddNextButton();
+        }
+
+        private void AddPreviousButton()
+        {
+            prevButton = new Button("PrevButton")
+            {
+                ThemeChangeSensitive = true,
+            };
+            prevButton.Clicked += (object sender, ClickedEventArgs e) =>
+            {
+                viewModel.PrevButtonClicked();
+            };
+            controlsView.Add(prevButton);
+            prevButton.BindingContext = viewModel;
+            prevButton.SetBinding(IsEnabledProperty, "HasPreviousTrack");
+        }
+
+        private void AddPlayButton()
+        {
+            playButton = new MultiStateButton()
+            {
+                Size2D = new Size2D(48, 48).SpToPx(),
+                BackgroundColor = Color.Transparent,
+                IconResources = new Dictionary<ThemeType, Dictionary<string, StringSelector>>()
+                {
+                    {
+                        ThemeType.Light,
+                        new Dictionary<string, StringSelector>()
+                        {
+                            {
+                                "Play",
+                                new StringSelector()
+                                {
+                                    Normal = Resources.GetImagePath() + "light/play.png",
+                                    Pressed = Resources.GetImagePath() + "play_pressed.png",
+                                    Disabled = Resources.GetImagePath() + "play_disabled.png",
+                                }
+                            },
+                            {
+                                "Pause",
+                                new StringSelector()
+                                {
+                                    Normal = Resources.GetImagePath() + "light/pause.png",
+                                    Pressed = Resources.GetImagePath() + "pause_pressed.png",
+                                    Disabled = Resources.GetImagePath() + "pause_disabled.png",
+                                }
+                            },
+                        }
+                    },
+                    {
+                        ThemeType.Dark,
+                        new Dictionary<string, StringSelector>()
+                        {
+                            {
+                                "Play",
+                                new StringSelector()
+                                {
+                                    Normal = Resources.GetImagePath() + "dark/play.png",
+                                    Pressed = Resources.GetImagePath() + "play_pressed.png",
+                                    Disabled = Resources.GetImagePath() + "play_disabled.png",
+                                }
+                            },
+                            {
+                                "Pause",
+                                new StringSelector()
+                                {
+                                    Normal = Resources.GetImagePath() + "dark/pause.png",
+                                    Pressed = Resources.GetImagePath() + "pause_pressed.png",
+                                    Disabled = Resources.GetImagePath() + "pause_disabled.png",
+                                }
+                            },
+                        }
+                    }
+                },
+            };
+            controlsView.Add(playButton);
+            playButton.BindingContext = viewModel;
+            playButton.SetBinding(MultiStateButton.CustomStateProperty, "PlayButtonState");
+            playButton.Clicked += (object sender, ClickedEventArgs e) =>
+            {
+                viewModel.PlayingStatusChanged();
+            };
+        }
+
+        private void AddNextButton()
+        {
+            nextButton = new Button("NextButton")
+            {
+                ThemeChangeSensitive = true,
+            };
+            nextButton.Clicked += (object sender, ClickedEventArgs e) =>
+            {
+                viewModel.NextButtonClicked();
+            };
+            controlsView.Add(nextButton);
+            nextButton.BindingContext = viewModel;
+            nextButton.SetBinding(IsEnabledProperty, "HasNextTrack");
+        }
+
+        private void AddSliderElements()
+        {
+            AddPlaybackSlider();
+            AddCurrentTimeLabel();
+            AddTotalTimeLabel();
+            sliderView = new View();
+            sliderView.BackgroundColor = Color.Transparent;
+            sliderView.WidthResizePolicy = ResizePolicyType.FillToParent;
+            if (DeviceInfo.IsPortrait)
+            {
+                sliderView.Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    Padding = new Extents(33, 33, 0, 8).SpToPx(),
+                };
+                sliderView.SizeHeight = 61.SpToPx();
+                base.Add(sliderView);
+                currentTime.WidthSpecification = 72.SpToPx();
+                sliderView.Add(currentTime);
+                playbackSlider.WidthSpecification = 872.SpToPx();
+                sliderView.Add(playbackSlider);
+                totalTime.WidthSpecification = 72.SpToPx();
+                sliderView.Add(totalTime);
+            }
+            else
+            {
+                sliderView.SizeHeight = 24.SpToPx();
+                baseView.Add(playbackSlider);
+                sliderView.Layout = new RelativeLayout();
+                sliderView.Position2D = new Position2D(0, SliderHeight).SpToPx();
+                playbackSlider.Add(sliderView);
+                sliderView.Add(currentTime);
+                RelativeLayout.SetHorizontalAlignment(currentTime, RelativeLayout.Alignment.Start);
+                sliderView.Add(totalTime);
+                RelativeLayout.SetHorizontalAlignment(totalTime, RelativeLayout.Alignment.End);
+            }
+        }
+
+        private void AddPlaybackSliderEventHandler()
+        {
+            playbackSlider.SlidingStarted += (object sender, SliderSlidingStartedEventArgs e) =>
+            {
+                viewModel.StopPlaybackTimer();
+            };
+            playbackSlider.ValueChanged += (object sender, SliderValueChangedEventArgs e) =>
+            {
+                viewModel.SetElapsedTime(e.CurrentValue);
+            };
+            playbackSlider.SlidingFinished += (object sender, SliderSlidingFinishedEventArgs e) =>
+            {
+                viewModel.UpdatePlayerPosition(e.CurrentValue);
+            };
+        }
+
+        private void AddPlaybackSlider()
+        {
+            playbackSlider = new Slider("Slider")
+            {
+                ThemeChangeSensitive = true,
+                MinValue = 0.0f,
+                MaxValue = 1.0f,
+                WidthSpecification = 626.SpToPx(),
+                HeightSpecification = SliderHeight.SpToPx(),
+                ThumbSize = new Tizen.NUI.Size(30, 30).SpToPx(),
+                Direction = Slider.DirectionType.Horizontal,
+            };
+            playbackSlider.SetBinding(Slider.CurrentValueProperty, "ElapsedTime");
+            AddPlaybackSliderEventHandler();
+        }
+
+        private void AddCurrentTimeLabel()
+        {
+            currentTime = new TextLabel()
+            {
+                StyleName = "TitleText",
+                ThemeChangeSensitive = true,
+                Size2D = new Size2D(180, 24).SpToPx(),
+                PixelSize = 18.SpToPx(),
+                FontFamily = "BreezeSans",
+                Text = "00::00:00",
+                HorizontalAlignment = HorizontalAlignment.Begin,
+            };
+            currentTime.SetBinding(TextLabel.TextProperty, "PlayingTime");
+        }
+
+        private void AddTotalTimeLabel()
+        {
+            totalTime = new TextLabel()
+            {
+                StyleName = "TitleText",
+                ThemeChangeSensitive = true,
+                Size2D = new Size2D(180, 24).SpToPx(),
+                PixelSize = 18.SpToPx(),
+                FontFamily = "BreezeSans",
+                HorizontalAlignment = HorizontalAlignment.End,
+                Text = "59:59:59",
+            };
+            totalTime.SetBinding(TextLabel.TextProperty, "TrackLength");
+        }
+
+        public void ShowView()
+        {
+            Show();
+        }
+
+        public void HideView()
+        {
+            Hide();
+        }
+    }
+}
index 47d1ee7b61fc141fd188cf5429fa9bb051fbfe31..aed34b02acf7e8d2cc2fc07cd267ab04622bfc01 100755 (executable)
@@ -450,8 +450,8 @@ namespace MusicPlayer.Views
                 VerticalAlignment = VerticalAlignment.Center,
                 Ellipsis = true,
             };
-            titleLabel.SetBinding(TextLabel.TextProperty, "TrackName");
             controlsView.Add(titleLabel);
+            titleLabel.SetBinding(TextLabel.TextProperty, "TrackName");
         }
 
         private void AddArtistLabel()
@@ -468,8 +468,8 @@ namespace MusicPlayer.Views
                 VerticalAlignment = VerticalAlignment.Center,
                 Ellipsis = true,
             };
-            artistLabel.SetBinding(TextLabel.TextProperty, "TrackArtist");
             controlsView.Add(artistLabel);
+            artistLabel.SetBinding(TextLabel.TextProperty, "TrackArtist");
         }
 
         private void AddTextControlElements()
@@ -528,6 +528,7 @@ namespace MusicPlayer.Views
                     }
                 },
             };
+            playbackButtonsView.Add(shuffleButton);
             shuffleButton.BindingContext = viewModel.playingListViewModel;
             shuffleButton.SetBinding(MultiStateButton.CustomStateProperty, "ShuffleButtonState");
             // TODO need to implement command instead
@@ -535,7 +536,6 @@ namespace MusicPlayer.Views
             {
                 viewModel.ShuffleChanged();
             };
-            playbackButtonsView.Add(shuffleButton);
         }
 
         private void AddPreviousButton()
@@ -549,9 +549,9 @@ namespace MusicPlayer.Views
             {
                 viewModel.PrevButtonClicked();
             };
+            playbackButtonsView.Add(prevButton);
             prevButton.BindingContext = viewModel;
             prevButton.SetBinding(IsEnabledProperty, "HasPreviousTrack");
-            playbackButtonsView.Add(prevButton);
         }
 
         private void AddPlayButton()
@@ -612,9 +612,9 @@ namespace MusicPlayer.Views
                     }
                 },
             };
+            playbackButtonsView.Add(playButton);
             playButton.BindingContext = viewModel;
             playButton.SetBinding(MultiStateButton.CustomStateProperty, "PlayButtonState");
-            playbackButtonsView.Add(playButton);
             // TODO need to implement command instead
             playButton.Clicked += (object sender, ClickedEventArgs e) =>
             {
@@ -633,9 +633,9 @@ namespace MusicPlayer.Views
             {
                 viewModel.NextButtonClicked();
             };
+            playbackButtonsView.Add(nextButton);
             nextButton.BindingContext = viewModel;
             nextButton.SetBinding(IsEnabledProperty, "HasNextTrack");
-            playbackButtonsView.Add(nextButton);
         }
 
         private void AddRepeatButton()
@@ -702,9 +702,9 @@ namespace MusicPlayer.Views
                     }
                 },
             };
+            playbackButtonsView.Add(repeatButton);
             repeatButton.BindingContext = viewModel.playingListViewModel;
             repeatButton.SetBinding(MultiStateButton.CustomStateProperty, "RepeatButtonState");
-            playbackButtonsView.Add(repeatButton);
             // TODO need to implement command instead
             repeatButton.Clicked += (object sender, ClickedEventArgs e) =>
             {
@@ -844,8 +844,8 @@ namespace MusicPlayer.Views
                 ThumbSize = new Tizen.NUI.Size(36, 36).SpToPx(),
                 Direction = Slider.DirectionType.Horizontal,
             };
-            playbackSlider.SetBinding(Slider.CurrentValueProperty, "ElapsedTime");
             sliderView.Add(playbackSlider);
+            playbackSlider.SetBinding(Slider.CurrentValueProperty, "ElapsedTime");
             AddPlaybackSliderEventHandler();
         }
 
@@ -861,8 +861,8 @@ namespace MusicPlayer.Views
                 Text = "00::00:00",
                 HorizontalAlignment = HorizontalAlignment.Begin,
             };
-            currentTime.SetBinding(TextLabel.TextProperty, "PlayingTime");
             playbackSliderTextView.Add(currentTime);
+            currentTime.SetBinding(TextLabel.TextProperty, "PlayingTime");
             RelativeLayout.SetHorizontalAlignment(currentTime, RelativeLayout.Alignment.Start);
             RelativeLayout.SetLeftRelativeOffset(currentTime, 0.0f);
         }
@@ -879,8 +879,8 @@ namespace MusicPlayer.Views
                 HorizontalAlignment = HorizontalAlignment.End,
                 Text = "59:59:59",
             };
-            totalTime.SetBinding(TextLabel.TextProperty, "TrackLength");
             playbackSliderTextView.Add(totalTime);
+            totalTime.SetBinding(TextLabel.TextProperty, "TrackLength");
             RelativeLayout.SetHorizontalAlignment(totalTime, RelativeLayout.Alignment.End);
             RelativeLayout.SetRightRelativeOffset(totalTime, 1.0f);
         }
@@ -1020,9 +1020,9 @@ namespace MusicPlayer.Views
                     }
                 },
             };
+            actionButtonView.Add(favouriteButton);
             favouriteButton.BindingContext = viewModel;
             favouriteButton.SetBinding(MultiStateButton.CustomStateProperty, "FavouriteButtonState");
-            actionButtonView.Add(favouriteButton);
             favouriteButton.Clicked += (object sender, ClickedEventArgs e) =>
             {
                 viewModel.FavouriteStatusChanged();
@@ -1123,8 +1123,8 @@ namespace MusicPlayer.Views
                 Size2D = new Size2D(200, 200).SpToPx(),
                 BoxShadow = new Shadow(6.0f, Color.Black, new Vector2(0, 3)),
             };
-            thumb.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath");
             topRightView.Add(thumb);
+            thumb.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath");
             thumb.Hide();
         }
 
index 69c9f38b7c8172eaad310abdf70f2330e462e661..3002de7286f1b47094d5d40b991a7102569dc77c 100755 (executable)
Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ