From d78dce44f06ddbb40b56892dbb404b8004296226 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 12 Jul 2019 11:34:06 -0400 Subject: [PATCH] Fixed issue with Horizontal list not refreshing. Added clientId to joinPartyResponse. Crashing on multiple user joins. --- .../HorizontalList/HorizontalList.cs | 8 +-- .../Components/MemberList/MemberList.xaml | 2 +- .../Components/MemberList/MemberList.xaml.cs | 55 ++++++++++++++++++- Aurora/Design/Views/Party/PartyView.xaml | 19 ++----- Aurora/Design/Views/Party/PartyViewModel.cs | 27 ++++++--- Aurora/Models/PartyMember.cs | 22 ++++++++ Aurora/Proto/events.proto | 19 +++++-- Aurora/Proto/party.proto | 1 + Aurora/RemoteImpl/RemoteEventImpl.cs | 44 ++++++++++++--- Aurora/RemoteImpl/RemotePartyImpl.cs | 13 +---- Aurora/Services/SettingsService.cs | 17 ++++++ 11 files changed, 173 insertions(+), 54 deletions(-) create mode 100644 Aurora/Models/PartyMember.cs diff --git a/Aurora/Design/Components/HorizontalList/HorizontalList.cs b/Aurora/Design/Components/HorizontalList/HorizontalList.cs index 361632b..5a92475 100755 --- a/Aurora/Design/Components/HorizontalList/HorizontalList.cs +++ b/Aurora/Design/Components/HorizontalList/HorizontalList.cs @@ -25,10 +25,10 @@ namespace Aurora.Design.Components.HorizontalList public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", - typeof(ObservableCollection), - typeof(HorizontalList), - default(ObservableCollection), - BindingMode.TwoWay, + returnType: typeof(ObservableCollection), + declaringType: typeof(HorizontalList), + defaultValue: default(ObservableCollection), + defaultBindingMode: BindingMode.TwoWay, propertyChanged: ItemsSourceChanged); public static readonly BindableProperty SelectedItemProperty = diff --git a/Aurora/Design/Components/MemberList/MemberList.xaml b/Aurora/Design/Components/MemberList/MemberList.xaml index ba3e38d..3297930 100644 --- a/Aurora/Design/Components/MemberList/MemberList.xaml +++ b/Aurora/Design/Components/MemberList/MemberList.xaml @@ -14,7 +14,7 @@ diff --git a/Aurora/Design/Components/MemberList/MemberList.xaml.cs b/Aurora/Design/Components/MemberList/MemberList.xaml.cs index 681dc74..9bd916e 100644 --- a/Aurora/Design/Components/MemberList/MemberList.xaml.cs +++ b/Aurora/Design/Components/MemberList/MemberList.xaml.cs @@ -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 _newSource; + private static NotifyCollectionChangedEventHandler _collectionChangedHandler; public MemberList() { InitializeComponent(); - } /// @@ -44,6 +45,7 @@ namespace Aurora.Design.Components.MemberList } } + /// /// Memberes changed event handler. Assign member list source. /// @@ -57,7 +59,56 @@ namespace Aurora.Design.Components.MemberList if (membersList != null) { _newSource = newValue as ObservableCollection; - membersList.ItemsSource = newValue as ObservableCollection; + membersList.ItemsSource = new ObservableCollection(_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; + } } } } diff --git a/Aurora/Design/Views/Party/PartyView.xaml b/Aurora/Design/Views/Party/PartyView.xaml index 10f1cbd..e6b7f50 100644 --- a/Aurora/Design/Views/Party/PartyView.xaml +++ b/Aurora/Design/Views/Party/PartyView.xaml @@ -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}">