2019-05-27 16:23:14 +00:00
|
|
|
|
using System;
|
2019-07-06 19:52:28 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Collections.Specialized;
|
2019-07-12 15:34:06 +00:00
|
|
|
|
using System.Linq;
|
2019-05-27 16:23:14 +00:00
|
|
|
|
using Xamarin.Forms;
|
2019-07-07 21:12:13 +00:00
|
|
|
|
using Aurora.Proto.Party;
|
2019-05-27 16:23:14 +00:00
|
|
|
|
|
2019-07-05 18:17:09 +00:00
|
|
|
|
namespace Aurora.Design.Components.MemberList
|
2019-05-27 16:23:14 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class MemberList : ContentView
|
|
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
|
private static ObservableCollection<PartyMember> _newSource;
|
2019-07-12 15:34:06 +00:00
|
|
|
|
private static NotifyCollectionChangedEventHandler _collectionChangedHandler;
|
2019-05-27 16:23:14 +00:00
|
|
|
|
public MemberList()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for members list.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name=""Members""></param>
|
|
|
|
|
/// <param name="typeof(IEnumerable<string>"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static readonly BindableProperty MembersProperty =
|
|
|
|
|
BindableProperty.Create(propertyName: "Members",
|
2019-07-06 19:52:28 +00:00
|
|
|
|
returnType: typeof(ObservableCollection<PartyMember>),
|
2019-05-27 16:23:14 +00:00
|
|
|
|
declaringType: typeof(MemberList),
|
|
|
|
|
defaultBindingMode: BindingMode.Default,
|
|
|
|
|
propertyChanged: OnMembersChanged);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Backing property for MembersProperty
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value></value>
|
2019-07-06 19:52:28 +00:00
|
|
|
|
public ObservableCollection<PartyMember> Members
|
2019-05-27 16:23:14 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
|
return (ObservableCollection<PartyMember>)GetValue(MembersProperty);
|
2019-05-27 16:23:14 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(MembersProperty, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 15:34:06 +00:00
|
|
|
|
|
2019-05-27 16:23:14 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Memberes changed event handler. Assign member list source.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bindable"></param>
|
|
|
|
|
/// <param name="oldValue"></param>
|
|
|
|
|
/// <param name="newValue"></param>
|
|
|
|
|
private static void OnMembersChanged(BindableObject bindable, object oldValue, object newValue)
|
|
|
|
|
{
|
|
|
|
|
var control = (MemberList)bindable;
|
|
|
|
|
var membersList = control.FindByName("MembersHorizontalList") as HorizontalList.HorizontalList;
|
|
|
|
|
if (membersList != null)
|
|
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
|
_newSource = newValue as ObservableCollection<PartyMember>;
|
2019-07-12 15:34:06 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2019-05-27 16:23:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-06 19:52:28 +00:00
|
|
|
|
|