From c99f752174765e608aefa72205f3fde2138d7c1d Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Wed, 10 Jul 2019 17:17:10 -0400 Subject: [PATCH] Attempts to get horizontal list to work --- Aurora/Aurora.csproj | 117 ++++++------------ .../HorizontalList/HorizontalList.cs | 57 +++++++-- .../Components/MemberList/MemberList.xaml.cs | 2 +- Aurora/Design/Views/Party/PartyView.xaml | 20 ++- Aurora/Design/Views/Party/PartyViewModel.cs | 56 +++++++-- Aurora/Executors/ClientExecutor.cs | 63 +++++++--- 6 files changed, 190 insertions(+), 125 deletions(-) diff --git a/Aurora/Aurora.csproj b/Aurora/Aurora.csproj index b46e96e..e067622 100644 --- a/Aurora/Aurora.csproj +++ b/Aurora/Aurora.csproj @@ -1,99 +1,54 @@ - + netstandard2.0 true - + pdbonly true - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + Player.xaml - - - - + + + + \ No newline at end of file diff --git a/Aurora/Design/Components/HorizontalList/HorizontalList.cs b/Aurora/Design/Components/HorizontalList/HorizontalList.cs index 75e9577..361632b 100755 --- a/Aurora/Design/Components/HorizontalList/HorizontalList.cs +++ b/Aurora/Design/Components/HorizontalList/HorizontalList.cs @@ -1,6 +1,7 @@ using System; -using System.Collections; -using System.Collections.Generic; +using System.Linq; +using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.Windows.Input; using Xamarin.Forms; @@ -13,6 +14,7 @@ namespace Aurora.Design.Components.HorizontalList private readonly StackLayout _itemsStackLayout; public event EventHandler SelectedItemChanged; + private NotifyCollectionChangedEventHandler _itemsChangedHandler; public StackOrientation ListOrientation { get; set; } @@ -22,7 +24,12 @@ namespace Aurora.Design.Components.HorizontalList BindableProperty.Create("SelectedCommand", typeof(ICommand), typeof(HorizontalList), null); public static readonly BindableProperty ItemsSourceProperty = - BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(HorizontalList), default(IEnumerable), BindingMode.TwoWay, propertyChanged: ItemsSourceChanged); + BindableProperty.Create("ItemsSource", + typeof(ObservableCollection), + typeof(HorizontalList), + default(ObservableCollection), + BindingMode.TwoWay, + propertyChanged: ItemsSourceChanged); public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(HorizontalList), null, BindingMode.TwoWay, propertyChanged: OnSelectedItemChanged); @@ -36,9 +43,9 @@ namespace Aurora.Design.Components.HorizontalList set { SetValue(SelectedCommandProperty, value); } } - public IEnumerable ItemsSource + public ObservableCollection ItemsSource { - get { return (IEnumerable)GetValue(ItemsSourceProperty); } + get { return (ObservableCollection)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } @@ -56,12 +63,13 @@ namespace Aurora.Design.Components.HorizontalList private static void ItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) { - var itemsLayout = (HorizontalList)bindable; + HorizontalList itemsLayout = bindable as HorizontalList; itemsLayout.SetItems(); } public HorizontalList() { + _itemsChangedHandler = OnItemsChanged; // BackgroundColor = Color.FromHex("#1E2634"); Spacing = 6; _scrollView = new ScrollView(); @@ -78,6 +86,11 @@ namespace Aurora.Design.Components.HorizontalList Children.Add(_scrollView); } + ~HorizontalList() + { + ItemsSource.CollectionChanged -= _itemsChangedHandler; + } + protected virtual void SetItems() { _itemsStackLayout.Children.Clear(); @@ -99,6 +112,9 @@ namespace Aurora.Design.Components.HorizontalList return; } + //Setup collection events + ItemsSource.CollectionChanged += _itemsChangedHandler; + foreach (var item in ItemsSource) { _itemsStackLayout.Children.Add(GetItemView(item)); @@ -127,7 +143,6 @@ namespace Aurora.Design.Components.HorizontalList }; AddGesture(view, gesture); - return view; } @@ -164,5 +179,33 @@ namespace Aurora.Design.Components.HorizontalList itemsView.SelectedCommand?.Execute(newValue); } } + + private void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e) + { + switch (e.Action) + { + case System.Collections.Specialized.NotifyCollectionChangedAction.Add: + { + foreach (object item in e.NewItems) + { + _itemsStackLayout.Children.Add(GetItemView(item)); + } + break; + } + case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: + { + foreach (object item in e.OldItems) + { + //Clear layout and rebuild + _itemsStackLayout.Children.Clear(); + foreach (var source in ItemsSource) + { + _itemsStackLayout.Children.Add(GetItemView(item)); + } + } + break; + } + } + } } } \ No newline at end of file diff --git a/Aurora/Design/Components/MemberList/MemberList.xaml.cs b/Aurora/Design/Components/MemberList/MemberList.xaml.cs index aed88b8..681dc74 100644 --- a/Aurora/Design/Components/MemberList/MemberList.xaml.cs +++ b/Aurora/Design/Components/MemberList/MemberList.xaml.cs @@ -57,7 +57,7 @@ namespace Aurora.Design.Components.MemberList if (membersList != null) { _newSource = newValue as ObservableCollection; - membersList.ItemsSource = newValue as ObservableCollection; + membersList.ItemsSource = newValue as ObservableCollection; } } } diff --git a/Aurora/Design/Views/Party/PartyView.xaml b/Aurora/Design/Views/Party/PartyView.xaml index 007db4d..10f1cbd 100644 --- a/Aurora/Design/Views/Party/PartyView.xaml +++ b/Aurora/Design/Views/Party/PartyView.xaml @@ -3,7 +3,8 @@ 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:ml="clr-namespace:Aurora.Design.Components.MemberList" + xmlns:hl="clr-namespace:Aurora.Design.Components.HorizontalList" + 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"> @@ -17,9 +18,20 @@ IsVisible="{Binding IsNotSelectingHost}">