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);
-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();
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 => 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;
using Tizen.NUI;
+using Tizen.NUI.Extension;
using Tizen.NUI.Binding;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Components;
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()
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);
+ }
+ }
}
}