From: aman.jeph Date: Thu, 7 Apr 2022 13:14:21 +0000 (+0530) Subject: Fixing binding issues X-Git-Tag: submit/tizen/20220408.090947^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66659bf033a991961cd0da1ad226512accdfb0a5;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Fixing binding issues Change-Id: I5c240f10f9e2b30c33c95f4d657df64bab8f9d58 Signed-off-by: aman.jeph --- diff --git a/music-player/ViewModels/LyricsViewModel.cs b/music-player/ViewModels/LyricsViewModel.cs index 77ea5c9..e63868e 100755 --- a/music-player/ViewModels/LyricsViewModel.cs +++ b/music-player/ViewModels/LyricsViewModel.cs @@ -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; diff --git a/music-player/Views/LyricsView.cs b/music-player/Views/LyricsView.cs index 818c648..4b9b53c 100755 --- a/music-player/Views/LyricsView.cs +++ b/music-player/Views/LyricsView.cs @@ -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); } diff --git a/music-player/Views/MiniPlayer.cs b/music-player/Views/MiniPlayer.cs index e9b5b32..b6b861d 100755 --- a/music-player/Views/MiniPlayer.cs +++ b/music-player/Views/MiniPlayer.cs @@ -1,404 +1,404 @@ -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(), - }; - thumbnail.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath"); - thumbnail.TouchEvent += (object source, TouchEventArgs e) => - { - PlaybackHelper.Instance.ShowPlayer(); - return true; - }; - trackInfo.Add(thumbnail); - } - - 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, - }; - titleLabel.SetBinding(TextLabel.TextProperty, "TrackName"); - trackTextView.Add(titleLabel); - } - - 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, - }; - artistLabel.SetBinding(TextLabel.TextProperty, "TrackArtist"); - trackTextView.Add(artistLabel); - } - 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(); - }; - prevButton.BindingContext = viewModel; - prevButton.SetBinding(IsEnabledProperty, "HasPreviousTrack"); - controlsView.Add(prevButton); - } - - private void AddPlayButton() - { - playButton = new MultiStateButton() - { - Size2D = new Size2D(48, 48).SpToPx(), - BackgroundColor = Color.Transparent, - IconResources = new Dictionary>() - { - { - ThemeType.Light, - new Dictionary() - { - { - "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() - { - { - "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", - } - }, - } - } - }, - }; - playButton.BindingContext = viewModel; - playButton.SetBinding(MultiStateButton.CustomStateProperty, "PlayButtonState"); - controlsView.Add(playButton); - 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(); - }; - nextButton.BindingContext = viewModel; - nextButton.SetBinding(IsEnabledProperty, "HasNextTrack"); - controlsView.Add(nextButton); - } - - 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(); - } - } -} +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.Light, + new Dictionary() + { + { + "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() + { + { + "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(); + } + } +} diff --git a/music-player/Views/PlayerView.cs b/music-player/Views/PlayerView.cs index 47d1ee7..aed34b0 100755 --- a/music-player/Views/PlayerView.cs +++ b/music-player/Views/PlayerView.cs @@ -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(); } diff --git a/packaging/org.tizen.MusicPlayer-1.0.0.tpk b/packaging/org.tizen.MusicPlayer-1.0.0.tpk index 69c9f38..3002de7 100755 Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ