Adding rive animation for track without thumbnail 86/266186/2 accepted/tizen/unified/20211110.122311 submit/tizen/20211109.094344
authoraman.jeph <aman.jeph@samsung.com>
Tue, 9 Nov 2021 04:40:28 +0000 (10:10 +0530)
committeraman.jeph <aman.jeph@samsung.com>
Tue, 9 Nov 2021 09:13:57 +0000 (14:43 +0530)
Change-Id: Idc5bf355c2465da0424b1e1fdc5a0d94b646d8c3
Signed-off-by: aman.jeph <aman.jeph@samsung.com>
music-player/Common/UIColors.cs
music-player/Models/Track.cs
music-player/ViewModels/LyricsViewModel.cs
music-player/ViewModels/PlayerViewModel.cs
music-player/Views/LyricsView.cs
music-player/res/images/music.riv [new file with mode: 0755]
packaging/org.tizen.MusicPlayer-1.0.0.tpk

index 2562765e32b5396daff656b15e87bee242b4c26a..44bb8e8a8b91c58679f576e084f57de99f771368 100755 (executable)
@@ -12,6 +12,7 @@ namespace MusicPlayer.Common
         public static readonly Color HEXEEEFF1 = new Color(0.9333f, 0.9373f, 0.9450f, 1.0f);
         public static readonly Color HEX000C2B = new Color(0.0f, 0.0471f, 0.1686f, 1.0f);
         public static readonly Color HEXC3CAD2 = new Color(0.7647f, 0.7922f, 0.8235f, 1.0f);
+        public static readonly Color HEX1473E6 = new Color(0.0784f, 0.4510f, 0.9020f, 1.0f);
 
         public static readonly Color LyricsBackground = new Color(0.0f, 0.0f, 0.0f, 0.85f);
         public static readonly Color ItemSeperator = new Color(0.75f, 0.79f, 0.82f, 1.0f);
index d611cb324ee9d927a456a398547667581bceff8d..bf15a3649d1197434dae05c0d1455f3a88834111 100755 (executable)
@@ -23,6 +23,8 @@ namespace MusicPlayer.Models
             IsSelected = false;\r
         }\r
 \r
+        public bool IsThumbPathExists { get; private set; }\r
+\r
         private string trackTitle;\r
 \r
         public string TrackTitle\r
@@ -86,7 +88,13 @@ namespace MusicPlayer.Models
             get => thumbnailPath;\r
             set\r
             {\r
-                string thumb = string.IsNullOrEmpty(value) ? Resources.GetImagePath() + "thumbnail.png" : value;\r
+                string thumb = value;\r
+                IsThumbPathExists = true;\r
+                if (string.IsNullOrEmpty(value))\r
+                {\r
+                    thumb = Resources.GetImagePath() + "thumbnail.png";\r
+                    IsThumbPathExists = false;\r
+                }\r
                 SetProperty(ref thumbnailPath, thumb);\r
             }\r
         }\r
index b9db5a364ef63a88bf67c0274c8bd13642c0c2ac..77ea5c9fe06c804bffba0298bf390f8ba54e63f1 100755 (executable)
@@ -1,14 +1,32 @@
-using Tizen.Multimedia;
+using System;
+using Tizen.NUI;
+using Tizen.Multimedia;
 using MusicPlayer.Models;
 using MusicPlayer.Common;
-using Tizen.NUI;
 
 namespace MusicPlayer.ViewModels
 {
+    public enum AnimationState
+    {
+        Animation,
+        NoAnimation,
+        AnimationPlay,
+        AnimationPause,
+    }
+    class TrackThumbStateEventArgs : EventArgs
+    {
+        public TrackThumbStateEventArgs(AnimationState animationState)
+        {
+            CurrentAnimationState = animationState;
+        }
+        public AnimationState CurrentAnimationState { get; private set; }
+    }
+
     class LyricsViewModel : PropertyNotifier
     {
         internal LyricsModel lyricsModel;
-
+        private AnimationState trackState;
+        public event EventHandler<TrackThumbStateEventArgs> TrackThumbState;
         public LyricsViewModel()
         {
             lyricsModel = new LyricsModel();
@@ -30,6 +48,8 @@ namespace MusicPlayer.ViewModels
             set
             {
                 currentTrack = value;
+                AnimationState state = currentTrack.IsThumbPathExists ? AnimationState.NoAnimation : AnimationState.Animation;
+                UpdateTrackThumbState(state);
                 FilePath = currentTrack.FilePath;
                 lyricsModel.ThumbPath = currentTrack.ThumbnailPath;
                 lyricsModel.Lyrics = GetLyrics(FilePath);
@@ -44,6 +64,12 @@ namespace MusicPlayer.ViewModels
             set => SetProperty(ref lyricsBackgroundColor, value);
         }
 
+        public void UpdateTrackThumbState(AnimationState state)
+        {
+            trackState = state;
+            TrackThumbState?.Invoke(this, new TrackThumbStateEventArgs(trackState));
+        }
+
         private string GetLyrics(string path)
         {
             string lyrics = string.Empty;
index 4eb4cf3a1879ab3b6171967f71ef2915f65fc24e..a07a24739db11853d4e32276fac29b12602f11e4 100755 (executable)
@@ -324,11 +324,13 @@ namespace MusicPlayer.ViewModels
             {
                 case PlayingStatus.Playing:
                     PlayButtonState = PauseState;
+                    lyricsViewModel.UpdateTrackThumbState(AnimationState.AnimationPlay);
                     break;
                 case PlayingStatus.Paused:  // Fall Through
                 case PlayingStatus.Stopped: // Fall Through
                 case PlayingStatus.None:
                     PlayButtonState = PlayState;
+                    lyricsViewModel.UpdateTrackThumbState(AnimationState.AnimationPause);
                     break;
             }
         }
index 63c55fce3a7b1a8eb673f2af067bc434adfbff48..7ecf43a47351ba407e54ce088104de8851b3453c 100755 (executable)
@@ -1,4 +1,5 @@
 using Tizen.NUI;
+using Tizen.NUI.Extension;
 using Tizen.NUI.Binding;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
@@ -18,15 +19,77 @@ namespace MusicPlayer.Views
         private ImageView thumbView;
         private ScrollableBase scrollView;
         private TextLabel lyricsLabel;
+        private RiveAnimationView albumRiveAnimation;
+        private bool isAnimating;
 
         public LyricsView(LyricsViewModel lyricsViewModel) : base()
         {
             this.lyricsViewModel = lyricsViewModel;
             BindingContext = lyricsViewModel.lyricsModel;
             Size2D = new Size2D(ViewSize, ViewSize);
-
+            isAnimating = false;
             AddThumbnail();
             AddLyricsView();
+            AddRiveAnimation();
+            lyricsViewModel.TrackThumbState += OnTrackStateChanged;
+        }
+
+        protected override void Dispose(DisposeTypes type)
+        {
+            if(Disposed)
+            {
+                return;
+            }
+            if(type == DisposeTypes.Explicit)
+            {
+                albumRiveAnimation.Stop();
+                base.Remove(albumRiveAnimation);
+                albumRiveAnimation.Dispose();
+                albumRiveAnimation = null;
+
+                base.Remove(lyricsLabel);
+                lyricsLabel.Dispose();
+                lyricsLabel = null;
+
+                base.Remove(scrollView);
+                scrollView.Dispose();
+                scrollView = null;
+
+                base.Remove(thumbView);
+                thumbView.Dispose();
+                thumbView = null;
+                lyricsViewModel.TrackThumbState -= OnTrackStateChanged;
+            }
+            base.Dispose(type);
+        }
+
+        private void OnTrackStateChanged(object sender, TrackThumbStateEventArgs e)
+        {
+            if(e.CurrentAnimationState == AnimationState.Animation)
+            {
+                thumbView.Hide();
+                scrollView.Hide();
+                albumRiveAnimation.Show();
+                isAnimating = true;
+            }
+            else if(e.CurrentAnimationState == AnimationState.NoAnimation)
+            {
+                UnSetAnimationPlayingState();
+                albumRiveAnimation.Stop();
+                albumRiveAnimation.Hide();
+                thumbView.Show();
+                scrollView.Show();
+                isAnimating = false;
+            }
+            else if(e.CurrentAnimationState == AnimationState.AnimationPlay)
+            {
+                SetAnimationPlayingState();
+                albumRiveAnimation.Play();
+            }
+            else if(e.CurrentAnimationState == AnimationState.AnimationPause)
+            {
+                UnSetAnimationPlayingState();
+            }
         }
 
         private void AddThumbnail()
@@ -67,5 +130,36 @@ namespace MusicPlayer.Views
             lyricsLabel.SetBinding(TextLabel.TextProperty, "Lyrics");
             scrollView.Add(lyricsLabel);
         }
+
+        private void AddRiveAnimation()
+        {
+            albumRiveAnimation = new RiveAnimationView(Resources.GetImagePath() + "music.riv")
+            {
+                HeightResizePolicy = ResizePolicyType.FillToParent,
+                WidthResizePolicy = ResizePolicyType.FillToParent,
+            };
+            base.Add(albumRiveAnimation);
+            albumRiveAnimation.Hide();
+        }
+
+        private void SetAnimationPlayingState()
+        {
+            if(albumRiveAnimation != null && isAnimating)
+            {
+                albumRiveAnimation.EnableAnimation("Loop", true);
+                albumRiveAnimation.EnableAnimation("Start", true);
+                albumRiveAnimation.EnableAnimation("Stop", false);
+            }
+        }
+
+        private void UnSetAnimationPlayingState()
+        {
+            if (albumRiveAnimation != null && isAnimating)
+            {
+                albumRiveAnimation.EnableAnimation("Loop", false);
+                albumRiveAnimation.EnableAnimation("Start", false);
+                albumRiveAnimation.EnableAnimation("Stop", true);
+            }
+        }
     }
 }
diff --git a/music-player/res/images/music.riv b/music-player/res/images/music.riv
new file mode 100755 (executable)
index 0000000..dbac0a9
Binary files /dev/null and b/music-player/res/images/music.riv differ
index e542fbc748ece1ab7e53702b0f775f9a165b7716..3fe6e47d9578299028bc74ab2c2bf63a85ee51b7 100755 (executable)
Binary files a/packaging/org.tizen.MusicPlayer-1.0.0.tpk and b/packaging/org.tizen.MusicPlayer-1.0.0.tpk differ