2019-05-20 00:21:54 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2019-07-05 18:17:09 +00:00
|
|
|
|
using Aurora.Models.Media;
|
2020-02-02 15:26:47 +00:00
|
|
|
|
using Aurora.Services.Library;
|
2019-05-22 14:30:41 +00:00
|
|
|
|
using Xamarin.Forms;
|
2019-05-19 21:25:42 +00:00
|
|
|
|
|
2019-07-05 18:17:09 +00:00
|
|
|
|
namespace Aurora.Design.Views.Songs
|
2019-05-18 21:25:36 +00:00
|
|
|
|
{
|
2019-05-19 21:25:42 +00:00
|
|
|
|
public class SongsViewModel : BaseViewModel
|
2019-05-18 21:25:36 +00:00
|
|
|
|
{
|
2019-05-19 21:25:42 +00:00
|
|
|
|
#region Fields
|
2019-05-24 14:27:19 +00:00
|
|
|
|
private ObservableCollection<BaseMedia> _songsList;
|
|
|
|
|
private BaseMedia _selectedSong;
|
2020-02-02 15:26:47 +00:00
|
|
|
|
private ILibraryService _libraryService;
|
2019-05-19 21:25:42 +00:00
|
|
|
|
|
|
|
|
|
#endregion Fields
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
2020-02-02 15:26:47 +00:00
|
|
|
|
public SongsViewModel(ILibraryService libraryService)
|
2019-05-18 21:25:36 +00:00
|
|
|
|
{
|
2019-05-24 14:27:19 +00:00
|
|
|
|
_songsList = new ObservableCollection<BaseMedia>();
|
2019-12-05 04:42:23 +00:00
|
|
|
|
DoubleClickCommand = new Command(OnDoubleClickExecute, OnDoubleClickCanExecute);
|
2019-11-07 03:32:43 +00:00
|
|
|
|
|
2020-02-02 15:26:47 +00:00
|
|
|
|
this._libraryService = libraryService;
|
|
|
|
|
|
2019-05-19 21:25:42 +00:00
|
|
|
|
Initialize();
|
2019-05-18 21:25:36 +00:00
|
|
|
|
}
|
2019-05-19 21:25:42 +00:00
|
|
|
|
|
|
|
|
|
#endregion Constructor
|
|
|
|
|
|
|
|
|
|
#region Properties
|
2019-05-24 14:27:19 +00:00
|
|
|
|
public ObservableCollection<BaseMedia> SongsList
|
2019-05-19 21:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
get { return _songsList; }
|
2019-05-22 14:30:41 +00:00
|
|
|
|
set { SetProperty(ref _songsList, value); }
|
2019-05-19 21:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 14:27:19 +00:00
|
|
|
|
public BaseMedia SelectedSong
|
2019-05-19 21:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
get { return _selectedSong; }
|
2019-05-22 14:30:41 +00:00
|
|
|
|
set { SetProperty(ref _selectedSong, value); }
|
2019-05-19 21:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 04:42:23 +00:00
|
|
|
|
public Command DoubleClickCommand { get; private set; }
|
2019-05-22 14:30:41 +00:00
|
|
|
|
|
2019-05-19 21:25:42 +00:00
|
|
|
|
#endregion Properties
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
|
2020-02-02 15:26:47 +00:00
|
|
|
|
SongsList = this._libraryService.GetLibrary();
|
2019-05-19 21:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 03:32:43 +00:00
|
|
|
|
#endregion Methods
|
|
|
|
|
|
|
|
|
|
#region Commmands
|
2020-01-18 23:07:31 +00:00
|
|
|
|
public override bool CanPreviousButtonCommandExecute()
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-11-09 19:55:09 +00:00
|
|
|
|
public override void OnPreviousButtonExecute()
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 23:07:31 +00:00
|
|
|
|
public override bool CanPlayButtonCommandExecute()
|
2019-05-22 22:59:15 +00:00
|
|
|
|
{
|
2019-12-05 04:42:23 +00:00
|
|
|
|
return true;
|
2019-05-22 22:59:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 23:07:31 +00:00
|
|
|
|
public override void OnPlayButtonCommandExecute()
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
2019-12-04 22:53:49 +00:00
|
|
|
|
if (_selectedSong == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-05 04:42:23 +00:00
|
|
|
|
if (base.IsPlaying())
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
2019-12-05 04:42:23 +00:00
|
|
|
|
base.ChangePlayerState(_selectedSong, Main.PlayAction.Pause);
|
2019-11-07 03:32:43 +00:00
|
|
|
|
}
|
2019-12-05 04:42:23 +00:00
|
|
|
|
else
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
2019-12-05 04:42:23 +00:00
|
|
|
|
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
|
2019-11-07 03:32:43 +00:00
|
|
|
|
}
|
2019-12-05 04:42:23 +00:00
|
|
|
|
|
2019-11-07 03:32:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 23:07:31 +00:00
|
|
|
|
public override bool CanNextButtonCommandExecute()
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-09 19:55:09 +00:00
|
|
|
|
public override void OnNextButtonExecute()
|
2019-11-07 03:32:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-05 04:42:23 +00:00
|
|
|
|
|
|
|
|
|
public void OnDoubleClickExecute()
|
|
|
|
|
{
|
|
|
|
|
if (_selectedSong == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.ChangePlayerState(_selectedSong, Main.PlayAction.Play);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnDoubleClickCanExecute()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-11-07 03:32:43 +00:00
|
|
|
|
#endregion Commands
|
2019-05-18 21:25:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|