Fixed issue with Horizontal list not refreshing. Added clientId to joinPartyResponse. Crashing on multiple user joins.
This commit is contained in:
@ -25,10 +25,10 @@ namespace Aurora.Design.Components.HorizontalList
|
||||
|
||||
public static readonly BindableProperty ItemsSourceProperty =
|
||||
BindableProperty.Create("ItemsSource",
|
||||
typeof(ObservableCollection<object>),
|
||||
typeof(HorizontalList),
|
||||
default(ObservableCollection<object>),
|
||||
BindingMode.TwoWay,
|
||||
returnType: typeof(ObservableCollection<object>),
|
||||
declaringType: typeof(HorizontalList),
|
||||
defaultValue: default(ObservableCollection<object>),
|
||||
defaultBindingMode: BindingMode.TwoWay,
|
||||
propertyChanged: ItemsSourceChanged);
|
||||
|
||||
public static readonly BindableProperty SelectedItemProperty =
|
||||
|
@ -14,7 +14,7 @@
|
||||
<DataTemplate>
|
||||
<Frame>
|
||||
<Label
|
||||
Text="{Binding Username}"/>
|
||||
Text="{Binding UserName}"/>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</hl:HorizontalList.ItemTemplate>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using Aurora.Proto.Party;
|
||||
|
||||
@ -9,10 +10,10 @@ namespace Aurora.Design.Components.MemberList
|
||||
public partial class MemberList : ContentView
|
||||
{
|
||||
private static ObservableCollection<PartyMember> _newSource;
|
||||
private static NotifyCollectionChangedEventHandler _collectionChangedHandler;
|
||||
public MemberList()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -44,6 +45,7 @@ namespace Aurora.Design.Components.MemberList
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Memberes changed event handler. Assign member list source.
|
||||
/// </summary>
|
||||
@ -57,7 +59,56 @@ namespace Aurora.Design.Components.MemberList
|
||||
if (membersList != null)
|
||||
{
|
||||
_newSource = newValue as ObservableCollection<PartyMember>;
|
||||
membersList.ItemsSource = newValue as ObservableCollection<object>;
|
||||
membersList.ItemsSource = new ObservableCollection<object>(_newSource);
|
||||
|
||||
//Setup collection changed listeners
|
||||
//TODO evaluate for memory leak
|
||||
_newSource.CollectionChanged += (sender, e) => HandleCollectionChanged(sender, e, bindable);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, BindableObject bindable)
|
||||
{
|
||||
MemberList self = bindable as MemberList;
|
||||
var membersList = self.FindByName("MembersHorizontalList") as HorizontalList.HorizontalList;
|
||||
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
{
|
||||
foreach (PartyMember member in e.NewItems)
|
||||
{
|
||||
membersList.ItemsSource.Add(member);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
{
|
||||
foreach (PartyMember member in e.NewItems)
|
||||
{
|
||||
//Find all matches
|
||||
var sourceMembers = membersList.ItemsSource.Where((object obj) =>
|
||||
{
|
||||
bool match = false;
|
||||
if (obj is PartyMember)
|
||||
{
|
||||
PartyMember tmp = obj as PartyMember;
|
||||
match = tmp.Id == member.Id;
|
||||
}
|
||||
|
||||
return match;
|
||||
});
|
||||
|
||||
//Remove found matches
|
||||
foreach (object obj in sourceMembers)
|
||||
{
|
||||
membersList.ItemsSource.Remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:hs="clr-namespace:Aurora.Design.Components.HostSelector"
|
||||
xmlns:hl="clr-namespace:Aurora.Design.Components.HorizontalList"
|
||||
xmlns:ml="clr-namespace:Aurora.Design.Components.MemberList"
|
||||
xmlns:renderedViews="clr-namespace:Sharpnado.Presentation.Forms.RenderedViews;assembly=Sharpnado.Presentation.Forms"
|
||||
xmlns:qu="clr-namespace:Aurora.Design.Components.Queue"
|
||||
x:Class="Aurora.Design.Views.Party.PartyView">
|
||||
@ -18,20 +18,9 @@
|
||||
IsVisible="{Binding IsNotSelectingHost}">
|
||||
<Label
|
||||
Text="Party Members"/>
|
||||
<hl:HorizontalList
|
||||
x:Name="MembersHorizontalList"
|
||||
ListOrientation="Horizontal"
|
||||
VerticalOptions="Start"
|
||||
ItemsSource="{Binding Members}">
|
||||
<hl:HorizontalList.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Frame>
|
||||
<Label
|
||||
Text="{Binding UserName}"/>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</hl:HorizontalList.ItemTemplate>
|
||||
</hl:HorizontalList>
|
||||
<ml:MemberList
|
||||
VerticalOptions="FillAndExpand"
|
||||
Members="{Binding Members}"/>
|
||||
<Label
|
||||
Text="Queue"/>
|
||||
<qu:Queue/>
|
||||
|
@ -39,11 +39,8 @@ namespace Aurora.Design.Views.Party
|
||||
{
|
||||
this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute);
|
||||
this.HostCommand = new Command(OnHostExecute, CanHostExecute);
|
||||
_members = new ObservableCollection<PartyMember>
|
||||
{
|
||||
new PartyMember{UserName = "asdf"}
|
||||
};
|
||||
|
||||
_members = new ObservableCollection<PartyMember>();
|
||||
|
||||
SetState(PartyState.SelectingHost);
|
||||
}
|
||||
@ -142,17 +139,24 @@ namespace Aurora.Design.Views.Party
|
||||
/// <returns></returns>
|
||||
private async void JoinParty()
|
||||
{
|
||||
await _remotePartyClient.JoinPartyAsync(new JoinPartyRequest
|
||||
JoinPartyResponse resp = await _remotePartyClient.JoinPartyAsync(new JoinPartyRequest
|
||||
{
|
||||
UserName = SettingsService.Instance.Username,
|
||||
});
|
||||
|
||||
SettingsService.Instance.ClientId = resp.ClientId;
|
||||
|
||||
RefreshMembers();
|
||||
|
||||
//Subscribe to events
|
||||
SubscribeRequest req = new SubscribeRequest();
|
||||
req.EventTypes.Add(EventType.PartyMemberJoined);
|
||||
req.EventTypes.Add(EventType.PartyMemberLeft);
|
||||
if (!string.IsNullOrWhiteSpace(SettingsService.Instance.ClientId))
|
||||
{
|
||||
req.ClientId = SettingsService.Instance.ClientId;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_remoteEventsClient.SubscribeToEvents(req);
|
||||
@ -202,11 +206,13 @@ namespace Aurora.Design.Views.Party
|
||||
/// <returns></returns>
|
||||
private async void GetEvents()
|
||||
{
|
||||
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient.GetEvents(new Empty()))
|
||||
using (AsyncServerStreamingCall<BaseEvent> eventStream = _remoteEventsClient
|
||||
.GetEvents(new EventsRequest { ClientId = SettingsService.Instance.ClientId }))
|
||||
{
|
||||
while (!_eventCancellationTokenSource.Token.IsCancellationRequested)
|
||||
while (!_eventCancellationTokenSource.Token.IsCancellationRequested &&
|
||||
await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
|
||||
{
|
||||
if (await eventStream.ResponseStream.MoveNext(_eventCancellationTokenSource.Token))
|
||||
try
|
||||
{
|
||||
//Convert derived event type
|
||||
BaseEvent e = eventStream.ResponseStream.Current;
|
||||
@ -233,6 +239,11 @@ namespace Aurora.Design.Views.Party
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(string.Format("EXCEPTION --- " + ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user