Fixed issue with Horizontal list not refreshing. Added clientId to joinPartyResponse. Crashing on multiple user joins.

This commit is contained in:
watsonb8
2019-07-12 11:34:06 -04:00
parent 11a585ecc0
commit d78dce44f0
11 changed files with 173 additions and 54 deletions

View File

@ -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 =

View File

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

View File

@ -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;
}
}
}
}