This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Design/Views/Songs/SongsViewModel.cs

116 lines
2.6 KiB
C#

using System.Collections.ObjectModel;
using Aurora.Models.Media;
using Aurora.Services.Library;
using Xamarin.Forms;
namespace Aurora.Design.Views.Songs
{
public class SongsViewModel : BaseViewModel
{
#region Fields
private ObservableCollection<BaseMedia> _songsList;
private BaseMedia _selectedSong;
private ILibraryService _libraryService;
#endregion Fields
#region Constructor
public SongsViewModel(ILibraryService libraryService)
{
_songsList = new ObservableCollection<BaseMedia>();
DoubleClickCommand = new Command(OnDoubleClickExecute, OnDoubleClickCanExecute);
this._libraryService = libraryService;
Initialize();
}
#endregion Constructor
#region Properties
public ObservableCollection<BaseMedia> SongsList
{
get { return _songsList; }
set { SetProperty(ref _songsList, value); }
}
public BaseMedia SelectedSong
{
get { return _selectedSong; }
set { SetProperty(ref _selectedSong, value); }
}
public Command DoubleClickCommand { get; private set; }
#endregion Properties
#region Methods
public void Initialize()
{
SongsList = this._libraryService.GetLibrary();
}
#endregion Methods
#region Commmands
public override bool CanPreviousButtonCommandExecute()
{
return true;
}
public override void OnPreviousButtonExecute()
{
}
public override bool CanPlayButtonCommandExecute()
{
return true;
}
public override void OnPlayButtonCommandExecute()
{
if (_selectedSong == null)
{
return;
}
if (base.IsPlaying())
{
base.ChangePlayerState(_selectedSong, Main.PlayAction.Pause);
}
else
{
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
}
}
public override bool CanNextButtonCommandExecute()
{
return true;
}
public override void OnNextButtonExecute()
{
}
public void OnDoubleClickExecute()
{
if (_selectedSong == null)
{
return;
}
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
}
public bool OnDoubleClickCanExecute()
{
return true;
}
#endregion Commands
}
}