Player controls now get dynamically assigned to view model base classes.

This gives view models more freedom in how play events from the player are handled
This commit is contained in:
watsonb8
2019-11-06 22:32:43 -05:00
parent 759c05e53b
commit 794b4739b1
12 changed files with 549 additions and 187 deletions

View File

@ -17,6 +17,7 @@ namespace Aurora.Design.Views.Party
{
SelectingHost,
InParty,
Hosting,
Connecting,
}
@ -51,6 +52,10 @@ namespace Aurora.Design.Views.Party
#region Properties
/// <summary>
/// Publc property for the members list
/// </summary>
/// <value></value>
public ObservableCollection<PartyMember> Members
{
get
@ -68,11 +73,19 @@ namespace Aurora.Design.Views.Party
get { return _state == PartyState.SelectingHost; }
}
/// <summary>
/// Public property indicating the state.
/// </summary>
/// <value></value>
public bool IsNotSelectingHost
{
get { return _state != PartyState.SelectingHost; }
}
/// <summary>
/// Public property for queue item source
/// </summary>
/// <value></value>
public ObservableCollection<BaseMedia> Queue
{
get
@ -88,26 +101,63 @@ namespace Aurora.Design.Views.Party
}
}
public Command JoinCommand { get; set; }
public Command HostCommand { get; set; }
/// <summary>
/// Public property for the hostname bindable field
/// </summary>
/// <value></value>
public string Hostname
{
get { return _hostname; }
set { SetProperty(ref _hostname, value); }
}
/// <summary>
/// Public property for the currently selected song.
/// </summary>
/// <value></value>
public BaseMedia SelectedSong
{
get { return _selectedSong; }
set { SetProperty(ref _selectedSong, value); }
}
/// <summary>
/// Public property for playing media
/// </summary>
/// <value></value>
public Command PlayCommand { get; private set; }
/// <summary>
/// Public property for join command
/// </summary>
/// <value></value>
public Command JoinCommand { get; set; }
/// <summary>
/// Pubic property for host command
/// </summary>
/// <value></value>
public Command HostCommand { get; set; }
#endregion Properties
#region Events
public override void OnActive()
{
//TODO
//If in party subscribe to events
//If in party get events
}
public override void OnInactive()
{
//TODO
//unsubscribe
//stop getting events
}
/// <summary>
/// An event handler for the client receiving update events
/// </summary>
@ -154,10 +204,11 @@ namespace Aurora.Design.Views.Party
#region Commands
private async void OnJoinExecute()
{
SetState(PartyState.Connecting);
ClientService.Instance.Start(Hostname, SettingsService.Instance.DefaultPort.ToString());
await JoinParty();
SetState(PartyState.Connecting);
SetState(PartyState.InParty);
}
private bool CanJoinExecute()
@ -167,15 +218,24 @@ namespace Aurora.Design.Views.Party
private async void OnHostExecute()
{
//Change state
SetState(PartyState.Connecting);
ServerService.Instance.Start();
string localHost = ServerService.GetLocalIPAddress();
ClientService.Instance.Start(localHost, SettingsService.Instance.DefaultPort.ToString());
await JoinParty();
ClientService.Instance.GetEvents();
try
{
//Execute task without waiting
await ClientService.Instance.GetEvents().ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred while receiviing events: ", ex.Message);
}
//Change state
SetState(PartyState.Connecting);
SetState(PartyState.Hosting);
}
private bool CanHostExecute()
@ -243,6 +303,22 @@ namespace Aurora.Design.Views.Party
}
}
private async Task LeaveParty()
{
//Stop receiving events
ClientService.Instance.StopEvents();
//Unsubscribe
UnsubscribeAllRequest unsubscribeReq = new UnsubscribeAllRequest();
await ClientService.Instance.RemoteEventClient.UnsubscribeFromAllAsync(unsubscribeReq);
//Leave party
LeavePartyRequest leaveReq = new LeavePartyRequest();
await ClientService.Instance.RemotePartyClient.LeavePartyAsync(leaveReq);
}
/// <summary>
/// Refresh members list.
/// </summary>