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/BaseViewModel.cs

104 lines
2.6 KiB
C#

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Aurora.Models.Media;
using Xamarin.Forms;
using Aurora.Design.Views.Main;
namespace Aurora.Design.Views
{
public class BaseViewModel : INotifyPropertyChanged
{
private BaseMedia _baseMedia;
public BaseViewModel()
{
}
#region Player
/// <summary>
/// Command event handler for player play button
/// </summary>
public virtual void OnPlayExecute() { }
public virtual bool CanPlayExecute()
{
return true;
}
/// <summary>
/// Command event handler for player next button
/// </summary>
public virtual void OnNextExecute() { }
public virtual bool CanNextExecute()
{
return true;
}
/// <summary>
/// Command event handler for player previous button
/// </summary>
public virtual void OnPreviousExecute() { }
public virtual bool CanPreviousExecute()
{
return true;
}
/// <summary>
/// Model for the currently playing music.
/// </summary>
/// <value></value>
public BaseMedia Media
{
get
{
return this._baseMedia;
}
set
{
if (value != _baseMedia)
{
_baseMedia = value;
if (this.SetPlayerMetadata != null)
{
SetPlayerMetadata.Invoke(value);
}
}
}
}
public SetPlayerMetadataDelegate SetPlayerMetadata { get; set; }
#endregion Player
#region Lifecycle
public virtual void OnActive() { }
public virtual void OnInactive() { }
#endregion
#region INotifyPropertyChanged Implementation
public bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (Object.Equals(storage, value))
return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged == null)
return;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}