Members now appearing on host

This commit is contained in:
watsonb8 2019-07-05 17:37:10 -04:00
parent b18abf0400
commit 0d64c0732e
7 changed files with 61 additions and 35 deletions

View File

@ -14,7 +14,7 @@
<DataTemplate> <DataTemplate>
<Frame> <Frame>
<Label <Label
Text="{Binding .}"/> Text="{Binding Username}"/>
</Frame> </Frame>
</DataTemplate> </DataTemplate>
</hl:HorizontalList.ItemTemplate> </hl:HorizontalList.ItemTemplate>

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Xamarin.Forms; using Xamarin.Forms;
using Aurora.Design.Components.HorizontalList; using Aurora.Design.Components.HorizontalList;
using Aurora.Models;
namespace Aurora.Design.Components.MemberList namespace Aurora.Design.Components.MemberList
{ {
@ -21,7 +22,7 @@ namespace Aurora.Design.Components.MemberList
/// <returns></returns> /// <returns></returns>
public static readonly BindableProperty MembersProperty = public static readonly BindableProperty MembersProperty =
BindableProperty.Create(propertyName: "Members", BindableProperty.Create(propertyName: "Members",
returnType: typeof(IEnumerable<string>), returnType: typeof(IEnumerable<PartyMember>),
declaringType: typeof(MemberList), declaringType: typeof(MemberList),
defaultBindingMode: BindingMode.Default, defaultBindingMode: BindingMode.Default,
propertyChanged: OnMembersChanged); propertyChanged: OnMembersChanged);
@ -30,11 +31,11 @@ namespace Aurora.Design.Components.MemberList
/// Backing property for MembersProperty /// Backing property for MembersProperty
/// </summary> /// </summary>
/// <value></value> /// <value></value>
public IEnumerable<string> Members public IEnumerable<PartyMember> Members
{ {
get get
{ {
return (IEnumerable<string>)GetValue(MembersProperty); return (IEnumerable<PartyMember>)GetValue(MembersProperty);
} }
set set
{ {
@ -54,7 +55,7 @@ namespace Aurora.Design.Components.MemberList
var membersList = control.FindByName("MembersHorizontalList") as HorizontalList.HorizontalList; var membersList = control.FindByName("MembersHorizontalList") as HorizontalList.HorizontalList;
if (membersList != null) if (membersList != null)
{ {
membersList.ItemsSource = newValue as IEnumerable<string>; membersList.ItemsSource = newValue as IEnumerable<PartyMember>;
} }
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using Aurora.Executors; using Aurora.Executors;
using Aurora.Design.Components.HostSelector; using Aurora.Design.Components.HostSelector;
using Aurora.Services; using Aurora.Services;
using Aurora.Models;
using Xamarin.Forms; using Xamarin.Forms;
namespace Aurora.Design.Views.Party namespace Aurora.Design.Views.Party
@ -16,8 +17,6 @@ namespace Aurora.Design.Views.Party
public class PartyViewModel : BaseViewModel public class PartyViewModel : BaseViewModel
{ {
private ObservableCollection<string> _members;
private PartyState _state; private PartyState _state;
private BaseExecutor _executor; private BaseExecutor _executor;
@ -26,32 +25,25 @@ namespace Aurora.Design.Views.Party
private string _port; private string _port;
private ObservableCollection<PartyMember> _members;
public PartyViewModel() public PartyViewModel()
{ {
_members = new ObservableCollection<string>()
{
"Kevin",
"Brandon",
"Sheila",
"Dale",
"Austin",
"Tori",
"Ashley",
"Spencer",
};
OnPropertyChanged("Members");
this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute); this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute);
this.HostCommand = new Command(OnHostExecute, CanHostExecute); this.HostCommand = new Command(OnHostExecute, CanHostExecute);
_members = new ObservableCollection<PartyMember>();
State(PartyState.SelectingHost); State(PartyState.SelectingHost);
} }
#region Properties #region Properties
public ObservableCollection<string> Members public ObservableCollection<PartyMember> Members
{ {
get { return _members; } get
{
return _members;
}
set { SetProperty(ref _members, value); } set { SetProperty(ref _members, value); }
} }
@ -87,6 +79,7 @@ namespace Aurora.Design.Views.Party
{ {
_state = state; _state = state;
OnPropertyChanged("IsSelectingHost"); OnPropertyChanged("IsSelectingHost");
OnPropertyChanged("IsNotSelectingHost");
} }
#region Commands #region Commands
@ -117,6 +110,13 @@ namespace Aurora.Design.Views.Party
ServerService.Instance.Start(); ServerService.Instance.Start();
_members = _executor.PartyMembers;
OnPropertyChanged("Members");
_executor.PartyMembers.CollectionChanged += (sender, e) =>
{
OnPropertyChanged("Members");
};
//Change state //Change state
State(PartyState.Connecting); State(PartyState.Connecting);
} }

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
using System.Collections.ObjectModel;
using Aurora.Models;
namespace Aurora.Executors namespace Aurora.Executors
{ {
@ -12,6 +14,8 @@ namespace Aurora.Executors
public Type ExecutorType { get; protected set; } public Type ExecutorType { get; protected set; }
public abstract ObservableCollection<PartyMember> PartyMembers { get; }
public static BaseExecutor CreateExecutor<T>() public static BaseExecutor CreateExecutor<T>()
{ {
@ -40,7 +44,7 @@ namespace Aurora.Executors
public abstract void Close(); public abstract void Close();
public abstract void GetMembers(); public abstract ObservableCollection<PartyMember> GetMembers();
public abstract void GetQueue(); public abstract void GetQueue();

View File

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.ObjectModel;
using Aurora.Models;
using Aurora.Executors; using Aurora.Executors;
namespace Aurora.Executors namespace Aurora.Executors
@ -10,6 +12,14 @@ namespace Aurora.Executors
} }
#region Properties
public override ObservableCollection<PartyMember> PartyMembers
{
get { return null; }
}
#endregion Properties
public override void AddToQueue() public override void AddToQueue()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -20,7 +30,7 @@ namespace Aurora.Executors
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override void GetMembers() public override ObservableCollection<PartyMember> GetMembers()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Aurora.Models;
using Aurora.Executors; using Aurora.Executors;
using Aurora.Services; using Aurora.Services;
using Aurora.Proto; using Aurora.Proto;
@ -9,21 +11,29 @@ namespace Aurora.Executors
{ {
public class HostExecutor : BaseExecutor public class HostExecutor : BaseExecutor
{ {
RemotePartyServiceImpl _remoteServiceImpl; RemotePartyServiceImpl _remotePartyServiceImpl;
RemotePlaybackServiceImpl _remotePlaybackImpl; RemotePlaybackServiceImpl _remotePlaybackImpl;
public HostExecutor() public HostExecutor()
{ {
_remoteServiceImpl = new RemotePartyServiceImpl(); _remotePartyServiceImpl = new RemotePartyServiceImpl();
_remotePlaybackImpl = new RemotePlaybackServiceImpl(); _remotePlaybackImpl = new RemotePlaybackServiceImpl();
} }
public override void Initialize() public override void Initialize()
{ {
//Register grpc RemoteService with singleton server service //Register grpc RemoteService with singleton server service
ServerService.Instance.RegisterService(RemotePartyService.BindService(_remoteServiceImpl)); ServerService.Instance.RegisterService(RemotePartyService.BindService(_remotePartyServiceImpl));
ServerService.Instance.RegisterService(RemotePlaybackService.BindService(_remotePlaybackImpl)); ServerService.Instance.RegisterService(RemotePlaybackService.BindService(_remotePlaybackImpl));
} }
#region Properties
public override ObservableCollection<PartyMember> PartyMembers
{
get { return _remotePartyServiceImpl.PartyMembers; }
}
#endregion Properties
public override async void Close() public override async void Close()
{ {
await ServerService.Instance.Stop(); await ServerService.Instance.Stop();
@ -34,7 +44,7 @@ namespace Aurora.Executors
throw new NotImplementedException(); throw new NotImplementedException();
} }
public override void GetMembers() public override ObservableCollection<PartyMember> GetMembers()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.ObjectModel;
using System.Linq;
using Aurora.Proto; using Aurora.Proto;
using Aurora.Models; using Aurora.Models;
using Aurora.Services; using Aurora.Services;
@ -12,14 +13,14 @@ namespace Aurora.RemoteImpl
/// <summary> /// <summary>
/// Dictionary of party members. Key -> ClientId /// Dictionary of party members. Key -> ClientId
/// </summary> /// </summary>
private Dictionary<string, PartyMember> _partyMembers; private ObservableCollection<PartyMember> _partyMembers;
public RemotePartyServiceImpl() public RemotePartyServiceImpl()
{ {
_partyMembers = new Dictionary<string, PartyMember>(); _partyMembers = new ObservableCollection<PartyMember>();
//Add self to members list //Add self to members list
_partyMembers.Add(SettingsService.Instance.Username, new PartyMember _partyMembers.Add(new PartyMember
{ {
Username = SettingsService.Instance.Username, Username = SettingsService.Instance.Username,
Id = "asdf", Id = "asdf",
@ -28,7 +29,7 @@ namespace Aurora.RemoteImpl
}); });
} }
public Dictionary<string, PartyMember> PartyMembers public ObservableCollection<PartyMember> PartyMembers
{ {
get get
{ {
@ -38,7 +39,7 @@ namespace Aurora.RemoteImpl
public override Task<JoinPartyResponse> JoinParty(JoinPartyRequest request, Grpc.Core.ServerCallContext context) public override Task<JoinPartyResponse> JoinParty(JoinPartyRequest request, Grpc.Core.ServerCallContext context)
{ {
_partyMembers.Add(request.ClientId, new PartyMember() _partyMembers.Add(new PartyMember()
{ {
Username = request.UserName, Username = request.UserName,
Id = request.ClientId, Id = request.ClientId,
@ -52,7 +53,7 @@ namespace Aurora.RemoteImpl
public override Task<LeavePartyResponse> LeaveParty(LeavePartyRequest request, Grpc.Core.ServerCallContext context) public override Task<LeavePartyResponse> LeaveParty(LeavePartyRequest request, Grpc.Core.ServerCallContext context)
{ {
_partyMembers.Remove(request.ClientId); _partyMembers.Remove(_partyMembers.Where(e => e.Id == request.ClientId).Single());
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected }; LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
return Task.FromResult(response); return Task.FromResult(response);
} }