From: shivamv Date: Wed, 8 Dec 2021 07:17:03 +0000 (+0530) Subject: Added Track Highlights in all Views. X-Git-Tag: submit/tizen/20211213.121257^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c64a4535bcef07a51c879e5a202d0a27e93d5706;p=profile%2Fiot%2Fapps%2Fdotnet%2Fmusic-player.git Added Track Highlights in all Views. Change-Id: I859e09d9631000c8fe13529545409cc75155830e Signed-off-by: shivamv --- diff --git a/music-player/Core/CurrentPlayingTrack.cs b/music-player/Core/CurrentPlayingTrack.cs new file mode 100755 index 0000000..41dd087 --- /dev/null +++ b/music-player/Core/CurrentPlayingTrack.cs @@ -0,0 +1,45 @@ +using System; +using MusicPlayer.Views; +using MusicPlayer.ViewModels; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using MusicPlayer.Models; +using MusicPlayer.Common; + +namespace MusicPlayer.Core +{ + class PlayingTrackEventHandlerArgs : EventArgs + { + public PlayingTrackEventHandlerArgs(string mediaId) + { + CurrentTrackId = mediaId; + } + + public string CurrentTrackId { get; private set; } + } + class CurrentPlayingTrack + { + private static readonly CurrentPlayingTrack instance = new CurrentPlayingTrack(); + + public event EventHandler PlayingTrackChanged; + + public CurrentPlayingTrack() + { + MediaId = null; + } + + public static CurrentPlayingTrack Instance + { + get => instance; + } + + public string MediaId { get; private set; } + + public void SetMediaId(string id) + { + MediaId = id; + Tizen.Log.Info(AppConstants.LogTag, "Updating Current track"); + PlayingTrackChanged?.Invoke(this, new PlayingTrackEventHandlerArgs(id)); + } + } +} diff --git a/music-player/ViewModels/AlbumDetailViewModel.cs b/music-player/ViewModels/AlbumDetailViewModel.cs index e0ad562..22ebc19 100755 --- a/music-player/ViewModels/AlbumDetailViewModel.cs +++ b/music-player/ViewModels/AlbumDetailViewModel.cs @@ -22,8 +22,17 @@ namespace MusicPlayer.ViewModels UpdateAlbumDetailData(); TotalTracks = listViewModel.Count.ToString(); listViewModel.CollectionChanged += OnCollectionChanged; + CurrentPlayingTrack.Instance.PlayingTrackChanged += OnPlayingTrackChanged; } + private void OnPlayingTrackChanged(object sender, PlayingTrackEventHandlerArgs e) + { + Tizen.Log.Info(AppConstants.LogTag, "On Current track Changed"); + UpdatePlayingTrack(); + } + + public Track PlayingTrack { get; set; } + private int id; public int Id @@ -88,7 +97,7 @@ namespace MusicPlayer.ViewModels { AlbumDataProvider.AlbumDataChanged -= OnAlbumDetailChanged; ListViewModel.CollectionChanged -= OnCollectionChanged; - ListViewModel.Clear(); + //ListViewModel.Clear(); } public void PlayAll() @@ -116,6 +125,29 @@ namespace MusicPlayer.ViewModels listViewModel.Clear(); List trackList = AlbumDataProvider.GetAlbumTrackList(Id); listViewModel.CreateData(trackList); + UpdatePlayingTrack(); + } + + private void UpdatePlayingTrack() + { + if (PlayingTrack != null) + { + PlayingTrack.IsPlaying = false; + } + PlayingTrack = null; + string currentTrackId = CurrentPlayingTrack.Instance.MediaId; + if (currentTrackId != null) + { + foreach (Track item in listViewModel) + { + if (currentTrackId == item.Id) + { + item.IsPlaying = true; + PlayingTrack = item; + break; + } + } + } } private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) diff --git a/music-player/ViewModels/ArtistDetailViewModel.cs b/music-player/ViewModels/ArtistDetailViewModel.cs index d0e8921..f0e73a4 100755 --- a/music-player/ViewModels/ArtistDetailViewModel.cs +++ b/music-player/ViewModels/ArtistDetailViewModel.cs @@ -22,8 +22,17 @@ namespace MusicPlayer.ViewModels groupListViewModel = new ListViewModel(); UpdateArtistDetailView(); + CurrentPlayingTrack.Instance.PlayingTrackChanged += OnPlayingTrackChanged; } + private void OnPlayingTrackChanged(object sender, PlayingTrackEventHandlerArgs e) + { + Tizen.Log.Info(AppConstants.LogTag, "On Current track Changed"); + UpdatePlayingTrack(); + } + + public Track PlayingTrack { get; set; } + private string artistName; public string ArtistName @@ -44,9 +53,9 @@ namespace MusicPlayer.ViewModels public void OnViewDeleted() { ArtistDataProvider.ArtistDataChanged -= OnArtistDetailChanged; - trackListViewModel.Clear(); - albumListViewModel.Clear(); - groupListViewModel.Clear(); + //trackListViewModel.Clear(); + //albumListViewModel.Clear(); + //groupListViewModel.Clear(); } public void PlayAll() @@ -103,6 +112,29 @@ namespace MusicPlayer.ViewModels } groupListViewModel.Add(artistAlbum); } + UpdatePlayingTrack(); + } + + private void UpdatePlayingTrack() + { + if (PlayingTrack != null) + { + PlayingTrack.IsPlaying = false; + } + PlayingTrack = null; + string currentTrackId = CurrentPlayingTrack.Instance.MediaId; + if (currentTrackId != null) + { + foreach (Track item in TrackListViewModel) + { + if (currentTrackId == item.Id) + { + item.IsPlaying = true; + PlayingTrack = item; + break; + } + } + } } } } diff --git a/music-player/ViewModels/PlayerViewModel.cs b/music-player/ViewModels/PlayerViewModel.cs index 9bbdd47..b86cbf6 100755 --- a/music-player/ViewModels/PlayerViewModel.cs +++ b/music-player/ViewModels/PlayerViewModel.cs @@ -132,8 +132,6 @@ namespace MusicPlayer.ViewModels { Tizen.Log.Info(AppConstants.LogTag, "Setting Current track"); UpdateCurrentPlayingTrack(track); - playerModel.CurrentTrack = track; - lyricsViewModel.CurrentTrack = track; //TO DO need to set index properly Track current = playingListViewModel.Current(); if (current == null) @@ -322,15 +320,9 @@ namespace MusicPlayer.ViewModels private void UpdateCurrentPlayingTrack(Track newTrack) { - Track oldTrack = playerModel.CurrentTrack; - if(oldTrack != null) - { - oldTrack.IsPlaying = false; - } - if (newTrack != null) - { - newTrack.IsPlaying = true; - } + playerModel.CurrentTrack = newTrack; + lyricsViewModel.CurrentTrack = newTrack; + CurrentPlayingTrack.Instance.SetMediaId(newTrack.Id); } private void UpdatePlayingStatus(PlayingStatus status) diff --git a/music-player/ViewModels/PlaylistDetailViewModel.cs b/music-player/ViewModels/PlaylistDetailViewModel.cs index dbb9b96..7f198a8 100755 --- a/music-player/ViewModels/PlaylistDetailViewModel.cs +++ b/music-player/ViewModels/PlaylistDetailViewModel.cs @@ -26,6 +26,13 @@ namespace MusicPlayer.ViewModels UpdatePlaylistDetails(); PlaylistTrackCount = listViewModel.Count.ToString(); ListViewModel.CollectionChanged += OnCollectionChanged; + CurrentPlayingTrack.Instance.PlayingTrackChanged += OnPlayingTrackChanged; + } + + private void OnPlayingTrackChanged(object sender, PlayingTrackEventHandlerArgs e) + { + Tizen.Log.Info(AppConstants.LogTag, "On Current track Changed"); + UpdatePlayingTrack(); } public string PlaylistName { get; set; } @@ -59,12 +66,14 @@ namespace MusicPlayer.ViewModels set => isNotDefaultPlaylist = value; } + public Track PlayingTrack { get; set; } + // TODO do we really need this ? public void OnViewDeleted() { PlaylistManager.Instance.PlaylistDataChanged -= OnPlaylistDetailChanged; ListViewModel.CollectionChanged -= OnCollectionChanged; - ListViewModel.Clear(); + //ListViewModel.Clear(); } public void PlayAll() @@ -112,6 +121,33 @@ namespace MusicPlayer.ViewModels } listViewModel.Clear(); listViewModel.CreateData(CreatePlaylistAudioData(playlist.Id)); + UpdatePlayingTrack(); + } + + private void UpdatePlayingTrack() + { + string currentTrackId = CurrentPlayingTrack.Instance.MediaId; + string oldTrackId = null; + if (PlayingTrack != null) + { + oldTrackId = PlayingTrack.Id; + } + if (currentTrackId != oldTrackId) + { + PlayingTrack = null; + foreach (Track item in listViewModel) + { + if (oldTrackId == item.Id) + { + item.IsPlaying = false; + } + if (currentTrackId == item.Id) + { + item.IsPlaying = true; + PlayingTrack = item; + } + } + } } private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) diff --git a/music-player/ViewModels/TrackViewModel.cs b/music-player/ViewModels/TrackViewModel.cs index cc82ffd..88d013c 100755 --- a/music-player/ViewModels/TrackViewModel.cs +++ b/music-player/ViewModels/TrackViewModel.cs @@ -16,6 +16,13 @@ namespace MusicPlayer.ViewModels CreateTrackData(); listViewModel.CollectionChanged += OnCollectionChanged; TrackCount = listViewModel.Count.ToString(); + CurrentPlayingTrack.Instance.PlayingTrackChanged += OnPlayingTrackChanged; + } + + private void OnPlayingTrackChanged(object sender, PlayingTrackEventHandlerArgs e) + { + Tizen.Log.Info(AppConstants.LogTag, "On Current track Changed"); + UpdatePlayingTrack(); } private readonly ListViewModel listViewModel; @@ -37,6 +44,8 @@ namespace MusicPlayer.ViewModels } } + public Track PlayingTrack { get; set; } + public void OnTrackSelected(object selectedItem) { PlaybackHelper.Instance.PlayCurrent(ListViewModel, (Track)selectedItem); @@ -62,6 +71,29 @@ namespace MusicPlayer.ViewModels List trackList = TrackDataProvider.CurrentTrackList(); listViewModel.Clear(); listViewModel.CreateData(trackList); + UpdatePlayingTrack(); + } + + private void UpdatePlayingTrack() + { + if (PlayingTrack != null) + { + PlayingTrack.IsPlaying = false; + } + PlayingTrack = null; + string currentTrackId = CurrentPlayingTrack.Instance.MediaId; + if (currentTrackId != null) + { + foreach (Track item in listViewModel) + { + if (currentTrackId == item.Id) + { + item.IsPlaying = true; + PlayingTrack = item; + break; + } + } + } } private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) diff --git a/music-player/Views/AlbumDetailLayout.cs b/music-player/Views/AlbumDetailLayout.cs index d569eed..48fb027 100755 --- a/music-player/Views/AlbumDetailLayout.cs +++ b/music-player/Views/AlbumDetailLayout.cs @@ -1,6 +1,7 @@ using Tizen.NUI.Components; using Tizen.NUI.BaseComponents; using Tizen.NUI; +using Tizen.NUI.Binding; using MusicPlayer.Common; namespace MusicPlayer.Views @@ -18,6 +19,21 @@ namespace MusicPlayer.Views private const int LeftPadding = 64; private const int X = 0; + public static readonly BindableProperty IsPlayingProperty = BindableProperty.Create(nameof(IsPlaying), typeof(bool), typeof(AlbumDetailLayout), false, propertyChanged: (bindable, oldValue, newValue) => + { + var instance = (AlbumDetailLayout)bindable; + if (newValue != null) + { + bool newPlaying = (bool)newValue; + bool oldPlaying = (bool)oldValue; + if (oldPlaying != newPlaying) + { + instance.UpdateItem(newPlaying); + } + } + }, + defaultValueCreator: (bindable) => ((AlbumDetailLayout)bindable).isPlaying); + public AlbumDetailLayout(int width = 832, int height = 108) : base() { base.OnInitialize(); @@ -32,15 +48,14 @@ namespace MusicPlayer.Views subtitleLabel = CreateSubTitleLabel(); additionalLabel = CreateAdditionalLabel(width); itemSeperator = CreateItemSeparator(width, height); - IsCreateByXaml = true; + UpdateLabelColors(); + ThemeManager.ThemeChanged += OnThemeUpdated; } private TextLabel CreateTitleLabel() { TextLabel titleLabel = new TextLabel() { - StyleName = "ItemLabel", - ThemeChangeSensitive = true, Size2D = new Size2D(596, 40), PixelSize = 32, FontFamily = "BreezeSans", @@ -58,8 +73,6 @@ namespace MusicPlayer.Views { TextLabel subtitleLabel = new TextLabel() { - StyleName = "ItemLabel", - ThemeChangeSensitive = true, Size2D= new Size2D(596,36), PixelSize = 28, FontFamily = "BreezeSans", @@ -77,8 +90,6 @@ namespace MusicPlayer.Views { TextLabel additionalLabel = new TextLabel() { - StyleName = "ItemLabel", - ThemeChangeSensitive = true, Size2D= new Size2D(108,36), PixelSize = 28, FontFamily = "BreezeSans", @@ -117,6 +128,83 @@ namespace MusicPlayer.Views get => additionalLabel; } + private bool isPlaying = false; + + public bool IsPlaying + { + get => (bool)GetValue(IsPlayingProperty); + set => SetValue(IsPlayingProperty, value); + } + + private void UpdateItem(bool currentValue) + { + if (currentValue) + { + Tizen.Log.Info(AppConstants.LogTag, "setting highlight color"); + if (titleLabel != null) + { + titleLabel.TextColor = UIColors.HEX1473E6; + } + if (subtitleLabel != null) + { + subtitleLabel.TextColor = UIColors.HEX1473E6; + } + if (additionalLabel != null) + { + additionalLabel.TextColor = UIColors.HEX1473E6; + } + } + else + { + Tizen.Log.Info(AppConstants.LogTag, "setting normal color"); + UpdateLabelColors(); + } + isPlaying = currentValue; + } + + private void OnThemeUpdated(object sender, ThemeChangedEventArgs e) + { + if (e.IsPlatformThemeChanged && IsPlaying == false) + { + UpdateLabelColors(); + } + } + + private void UpdateLabelColors() + { + string currentPlatformThemeId = ThemeManager.PlatformThemeId; + if (currentPlatformThemeId.Equals(AppConstants.LightPlatformThemeId)) + { + if (titleLabel != null) + { + titleLabel.TextColor = UIColors.HEX001447; + } + if (subtitleLabel != null) + { + subtitleLabel.TextColor = UIColors.HEX001447; + } + if (additionalLabel != null) + { + additionalLabel.TextColor = UIColors.HEX001447; + } + } + else if (currentPlatformThemeId.Equals(AppConstants.DarkPlatformThemeId)) + { + if (titleLabel != null) + { + titleLabel.TextColor = Color.White; + } + if (subtitleLabel != null) + { + subtitleLabel.TextColor = Color.White; + } + if (additionalLabel != null) + { + additionalLabel.TextColor = Color.White; + } + } + } + protected override void Dispose(DisposeTypes type) { if (Disposed) diff --git a/music-player/Views/AlbumDetailView.cs b/music-player/Views/AlbumDetailView.cs index c0c4bca..1880944 100755 --- a/music-player/Views/AlbumDetailView.cs +++ b/music-player/Views/AlbumDetailView.cs @@ -32,6 +32,7 @@ namespace MusicPlayer.Views UpdateCollectionView(); AddAlbumArt(); AddAlbumInfo(); + TouchEvent += (object source, TouchEventArgs e) => false; } public override string GetTitleText() @@ -209,6 +210,7 @@ namespace MusicPlayer.Views layout.TitleLabel.SetBinding(TextLabel.TextProperty, "TrackTitle"); layout.SubtitleLabel.SetBinding(TextLabel.TextProperty, "ArtistName"); layout.AdditionalLabel.SetBinding(TextLabel.TextProperty, "Duration"); + layout.SetBinding(AlbumDetailLayout.IsPlayingProperty, "IsPlaying"); return layout; }); collectionView.ItemsSource = viewModel.ListViewModel; diff --git a/music-player/Views/ArtistDetailItemLayout.cs b/music-player/Views/ArtistDetailItemLayout.cs index 0eb0c50..884dc45 100755 --- a/music-player/Views/ArtistDetailItemLayout.cs +++ b/music-player/Views/ArtistDetailItemLayout.cs @@ -1,6 +1,7 @@ using Tizen.NUI.Components; using Tizen.NUI.BaseComponents; using Tizen.NUI; +using Tizen.NUI.Binding; using MusicPlayer.Common; namespace MusicPlayer.Views @@ -19,10 +20,24 @@ namespace MusicPlayer.Views private TextLabel titleLabel; private TextLabel extraLabel; + public static readonly BindableProperty IsPlayingProperty = BindableProperty.Create(nameof(IsPlaying), typeof(bool), typeof(ArtistDetailItemLayout), false, propertyChanged: (bindable, oldValue, newValue) => + { + var instance = (ArtistDetailItemLayout)bindable; + if (newValue != null) + { + bool newPlaying = (bool)newValue; + bool oldPlaying = (bool)oldValue; + if (oldPlaying != newPlaying) + { + instance.UpdateItem(newPlaying); + } + } + }, + defaultValueCreator: (bindable) => ((ArtistDetailItemLayout)bindable).isPlaying); + public ArtistDetailItemLayout(int width = 1792, int height = 108) : base() { base.OnInitialize(); - base.IsCreateByXaml = true; Width = width; Height = height; WidthSpecification = Width; @@ -34,7 +49,8 @@ namespace MusicPlayer.Views titleLabel = CreateTitleLabel(); extraLabel = CreateExtraLabel(); itemSeperator = CreateItemSeparator(); - IsCreateByXaml = true; + UpdateLabelColors(); + ThemeManager.ThemeChanged += OnThemeUpdated; } private View CreateItemSeparator() @@ -54,8 +70,6 @@ namespace MusicPlayer.Views { TextLabel titleLabel = new TextLabel() { - StyleName = "ItemLabel", - ThemeChangeSensitive = true, Size2D = new Size2D(1272, 40), PixelSize = 32, FontFamily = "BreezeSans", @@ -72,8 +86,6 @@ namespace MusicPlayer.Views { TextLabel extraLabel = new TextLabel() { - StyleName = "ItemLabel", - ThemeChangeSensitive = true, Size2D = new Size2D(360, 36), PixelSize = 28, FontFamily = "BreezeSans", @@ -96,6 +108,71 @@ namespace MusicPlayer.Views get => extraLabel; } + private bool isPlaying = false; + + public bool IsPlaying + { + get => (bool)GetValue(IsPlayingProperty); + set => SetValue(IsPlayingProperty, value); + } + + private void UpdateItem(bool currentValue) + { + if (currentValue) + { + Tizen.Log.Info(AppConstants.LogTag, "setting highlight color"); + if (titleLabel != null) + { + titleLabel.TextColor = UIColors.HEX1473E6; + } + if (extraLabel != null) + { + extraLabel.TextColor = UIColors.HEX1473E6; + } + } + else + { + Tizen.Log.Info(AppConstants.LogTag, "setting normal color"); + UpdateLabelColors(); + } + isPlaying = currentValue; + } + + private void OnThemeUpdated(object sender, ThemeChangedEventArgs e) + { + if (e.IsPlatformThemeChanged && IsPlaying == false) + { + UpdateLabelColors(); + } + } + + private void UpdateLabelColors() + { + string currentPlatformThemeId = ThemeManager.PlatformThemeId; + if (currentPlatformThemeId.Equals(AppConstants.LightPlatformThemeId)) + { + if (titleLabel != null) + { + titleLabel.TextColor = UIColors.HEX001447; + } + if (extraLabel != null) + { + extraLabel.TextColor = UIColors.HEX001447; + } + } + else if (currentPlatformThemeId.Equals(AppConstants.DarkPlatformThemeId)) + { + if (titleLabel != null) + { + titleLabel.TextColor = Color.White; + } + if(extraLabel != null) + { + extraLabel.TextColor = Color.White; + } + } + } + protected override void Dispose(DisposeTypes type) { if (Disposed) diff --git a/music-player/Views/ArtistDetailView.cs b/music-player/Views/ArtistDetailView.cs index 16f25c3..7190cba 100755 --- a/music-player/Views/ArtistDetailView.cs +++ b/music-player/Views/ArtistDetailView.cs @@ -19,6 +19,7 @@ namespace MusicPlayer.Views countLabel.SetBinding(TextLabel.TextProperty, "TotalCount"); UpdateCollectionView(); Add(listContainer); + TouchEvent += (object source, TouchEventArgs e) => false; } public override string GetTitleText() @@ -79,6 +80,7 @@ namespace MusicPlayer.Views ArtistDetailItemLayout layout = new ArtistDetailItemLayout(); layout.TitleLabel.SetBinding(TextLabel.TextProperty, "TrackTitle"); layout.ExtraLabel.SetBinding(TextLabel.TextProperty, "Duration"); + layout.SetBinding(ArtistDetailItemLayout.IsPlayingProperty, "IsPlaying"); return layout; }); collectionView.GroupHeaderTemplate = new DataTemplate(() => diff --git a/music-player/Views/PlayingListView.cs b/music-player/Views/PlayingListView.cs index a9a62c5..6d43bfe 100755 --- a/music-player/Views/PlayingListView.cs +++ b/music-player/Views/PlayingListView.cs @@ -53,7 +53,12 @@ namespace MusicPlayer.Views private void OnItemSelected(object sender, SelectionChangedEventArgs e) { + if (collectionView.SelectedItem == null) + { + return; + } viewModel.OnItemSelected(collectionView.SelectedItem); + collectionView.SelectedItem = null; } private void ItemSourceChanged(object sender, EventArgs e) diff --git a/music-player/Views/PlaylistDetailView.cs b/music-player/Views/PlaylistDetailView.cs index 0b2881c..8eaced6 100755 --- a/music-player/Views/PlaylistDetailView.cs +++ b/music-player/Views/PlaylistDetailView.cs @@ -23,7 +23,7 @@ namespace MusicPlayer.Views layout.Icon.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath"); layout.TitleLabel.SetBinding(TextLabel.TextProperty, "TrackTitle"); layout.SubtitleLabel.SetBinding(TextLabel.TextProperty, "ArtistName"); - //layout.SetBinding(ListItemLayout.IsPlayingProperty, "IsPlaying"); //Need to Modify + layout.SetBinding(ListItemLayout.IsPlayingProperty, "IsPlaying"); return layout; }); collectionView.SelectionChanged += OnTrackSelection; diff --git a/music-player/Views/TrackView.cs b/music-player/Views/TrackView.cs index f756ccb..b621e80 100755 --- a/music-player/Views/TrackView.cs +++ b/music-player/Views/TrackView.cs @@ -26,7 +26,7 @@ namespace MusicPlayer.Views layout.Icon.SetBinding(ImageView.ResourceUrlProperty, "ThumbnailPath"); layout.TitleLabel.SetBinding(TextLabel.TextProperty, "TrackTitle"); layout.SubtitleLabel.SetBinding(TextLabel.TextProperty, "ArtistName"); - //layout.SetBinding(ListItemLayout.IsPlayingProperty, "IsPlaying"); //Need to Modify + layout.SetBinding(ListItemLayout.IsPlayingProperty, "IsPlaying"); return layout; }); collectionView.ScrollingDirection = ScrollableBase.Direction.Vertical; diff --git a/music-player/music-player.csproj b/music-player/music-player.csproj index be15aa6..400a827 100755 --- a/music-player/music-player.csproj +++ b/music-player/music-player.csproj @@ -19,7 +19,7 @@ - + Runtime diff --git a/packaging/org.tizen.MusicPlayer-1.0.0.tpk b/packaging/org.tizen.MusicPlayer-1.0.0.tpk index 39280c9..f705adc 100755 Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ