From cf05045448915e52fec9aff459b8e3b4da3fe31c Mon Sep 17 00:00:00 2001 From: watsonb8 <watsonb8133@gmail.com> Date: Tue, 10 Dec 2019 15:10:27 -0500 Subject: [PATCH] Progress --- .../Components/DataGrid/DataGrid.xaml.cs | 18 ++- .../Components/HostSelector/HostSelector.xaml | 37 ------ .../HostSelector/HostSelector.xaml.cs | 121 ------------------ .../Design/Components/Library/Library.xaml.cs | 65 ++++++++-- Aurora/Design/Views/BaseDialogViewModel.cs | 2 +- Aurora/Design/Views/DialogReturnObject.cs | 7 - Aurora/Design/Views/MainView/MainView.xaml | 3 +- Aurora/Design/Views/MainView/MainView.xaml.cs | 3 +- .../Party/NewPartyDialog/ConnectionDetails.cs | 2 +- Aurora/Design/Views/Party/PartyView.xaml | 7 +- Aurora/Design/Views/Party/PartyViewModel.cs | 70 ++++------ 11 files changed, 98 insertions(+), 237 deletions(-) delete mode 100644 Aurora/Design/Components/HostSelector/HostSelector.xaml delete mode 100644 Aurora/Design/Components/HostSelector/HostSelector.xaml.cs delete mode 100644 Aurora/Design/Views/DialogReturnObject.cs diff --git a/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs b/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs index aba83ea..35eafee 100644 --- a/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs +++ b/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs @@ -99,10 +99,24 @@ namespace Aurora.Design.Components.DataGrid self._noDataView.IsVisible = false; } }); - void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - InternalItems = new List<object>(((IEnumerable)sender).Cast<object>()); + // InternalItems = new List<object>(((IEnumerable)sender).Cast<object>()); + if (e.NewItems != null) + { + foreach (object item in e.NewItems) + { + InternalItems.Add(item); + } + } + + if (e.OldItems != null) + { + foreach (object item in e.OldItems) + { + InternalItems.Remove(item); + } + } if (SelectedItem != null && !InternalItems.Contains(SelectedItem)) SelectedItem = null; } diff --git a/Aurora/Design/Components/HostSelector/HostSelector.xaml b/Aurora/Design/Components/HostSelector/HostSelector.xaml deleted file mode 100644 index 931ce04..0000000 --- a/Aurora/Design/Components/HostSelector/HostSelector.xaml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ContentView - xmlns="http://xamarin.com/schemas/2014/forms" - xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" - x:Class="Aurora.Design.Components.HostSelector.HostSelector"> - <ContentView.Content> - <Grid> - <Grid.RowDefinitions> - <RowDefinition - Height="*"/> - </Grid.RowDefinitions> - <StackLayout - Grid.Row="0" - x:Name="CredentialEditorLayout" - HorizontalOptions="Center" - VerticalOptions="Start"> - <Label - Text="Hostname" - VerticalOptions="Center"/> - <Entry - x:Name="HostnameEntry"/> - <StackLayout - Orientation="Horizontal" - HorizontalOptions="Center"> - <Button - HorizontalOptions="Center" - x:Name="buttonHost" - Text="Host"/> - <Button - HorizontalOptions="Center" - x:Name="buttonClient" - Text="Join"/> - </StackLayout> - </StackLayout> - </Grid> - </ContentView.Content> -</ContentView> \ No newline at end of file diff --git a/Aurora/Design/Components/HostSelector/HostSelector.xaml.cs b/Aurora/Design/Components/HostSelector/HostSelector.xaml.cs deleted file mode 100644 index 763d95f..0000000 --- a/Aurora/Design/Components/HostSelector/HostSelector.xaml.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using Xamarin.Forms; - -namespace Aurora.Design.Components.HostSelector -{ - public enum ConnectionType - { - Host, - Client, - } - - public enum SelectorState - { - SelectingHost, - EnteringCredentials, - } - - public partial class HostSelector : ContentView - { - - public HostSelector() - { - InitializeComponent(); - //Set initial conditions - CredentialEditorLayout.IsVisible = true; - - buttonHost.Clicked += OnButtonHostClicked; - buttonClient.Clicked += OnButtonClientClicked; - HostnameEntry.TextChanged += (sender, e) => - { - Hostname = e.NewTextValue; - }; - } - - - /// <summary> - /// On the host button clicked. - /// </summary> - /// <param name="sender">Sender.</param> - /// <param name="e">E.</param> - void OnButtonHostClicked(object sender, EventArgs e) - { - if (HostCommand.CanExecute(null)) - { - HostCommand.Execute(null); - } - } - - /// <summary> - /// On the client button clicked. - /// </summary> - /// <param name="sender">Sender.</param> - /// <param name="e">E.</param> - void OnButtonClientClicked(object sender, EventArgs e) - { - if (JoinCommand.CanExecute(null)) - { - JoinCommand.Execute(null); - } - } - - #region Host Selected Command - public static readonly BindableProperty HostCommandProperty = - BindableProperty.Create(propertyName: "HostSelectedCommand", - returnType: typeof(Command), - declaringType: typeof(HostSelector)); - - public Command HostCommand - { - get { return (Command)GetValue(HostCommandProperty); } - set { SetValue(HostCommandProperty, value); } - } - - #endregion Host Selected Command - - #region Client Selected Command - public static readonly BindableProperty JoinCommandProperty = - BindableProperty.Create(propertyName: "JoinSelectedCommand", - returnType: typeof(Command), - declaringType: typeof(HostSelector)); - - public Command JoinCommand - { - get { return (Command)GetValue(JoinCommandProperty); } - set { SetValue(JoinCommandProperty, value); } - } - - #endregion Client Selected Command - - #region Hostname property - public static readonly BindableProperty HostnameProperty = - BindableProperty.Create(propertyName: "Hostname", - returnType: typeof(string), - declaringType: typeof(HostSelector), - defaultBindingMode: BindingMode.TwoWay, - propertyChanged: OnHostNameChanged); - - public string Hostname - { - get { return (string)GetValue(HostnameProperty); } - set { SetValue(HostnameProperty, value); } - } - - private static void OnHostNameChanged(BindableObject bindable, object oldValue, object newValue) - { - string newVal = newValue as string; - HostSelector instance = bindable as HostSelector; - if (instance.HostnameEntry.Text != newVal) - { - instance.HostnameEntry.Text = newVal; - } - - } - - #endregion Hostname property - - - } - -} diff --git a/Aurora/Design/Components/Library/Library.xaml.cs b/Aurora/Design/Components/Library/Library.xaml.cs index dde5a28..7a355c8 100644 --- a/Aurora/Design/Components/Library/Library.xaml.cs +++ b/Aurora/Design/Components/Library/Library.xaml.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Xamarin.Forms; using Aurora.Models.Media; +using System.ComponentModel; +using System.Collections.Specialized; namespace Aurora.Design.Components.Library { @@ -29,7 +32,54 @@ namespace Aurora.Design.Components.Library returnType: typeof(IEnumerable<object>), declaringType: typeof(Library), defaultBindingMode: BindingMode.Default, - propertyChanged: OnItemsSourceChanged); + propertyChanged: (BindableObject bindable, object oldValue, object newValue) => + { + Library control = bindable as Library; + + var libraryDataGrid = control.LibraryDataGrid; + libraryDataGrid.ItemsSource = newValue as IEnumerable<object>; + if (newValue is INotifyPropertyChanged) + { + var collection = newValue as INotifyCollectionChanged; + collection.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs eventArgs) => + OnItemSourceCollectionChanged(sender, eventArgs, bindable); + } + + if (oldValue is INotifyPropertyChanged) + { + var collection = newValue as INotifyCollectionChanged; + collection.CollectionChanged -= (object sender, NotifyCollectionChangedEventArgs eventArgs) => + OnItemSourceCollectionChanged(sender, eventArgs, bindable); + } + }); + + private static void OnItemSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, BindableObject bindable) + { + if (sender is IEnumerable<object>) + { + Library control = bindable as Library; + var libraryDataGrid = control.LibraryDataGrid; + var collection = libraryDataGrid.ItemsSource as IEnumerable<object>; + if (e.NewItems != null) + { + foreach (object obj in e.NewItems) + { + collection.Concat(new[] { obj }); + } + } + + if (e.OldItems != null) + { + foreach (object obj in e.OldItems) + { + var list = collection.ToList(); + list.Remove(obj); + collection = list; + } + } + } + } + /// <summary> /// Backing property for the ItemsSource property. @@ -47,19 +97,6 @@ namespace Aurora.Design.Components.Library } } - /// <summary> - /// ItemsSource Changed event handler - /// </summary> - /// <param name="bindable"></param> - /// <param name="oldValue"></param> - /// <param name="newValue"></param> - private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) - { - Library control = bindable as Library; - - var libraryDataGrid = control.LibraryDataGrid; - libraryDataGrid.ItemsSource = newValue as IEnumerable<object>; - } #endregion ItemsSource Property diff --git a/Aurora/Design/Views/BaseDialogViewModel.cs b/Aurora/Design/Views/BaseDialogViewModel.cs index 6969660..279c0f7 100644 --- a/Aurora/Design/Views/BaseDialogViewModel.cs +++ b/Aurora/Design/Views/BaseDialogViewModel.cs @@ -10,6 +10,6 @@ namespace Aurora.Design.Views public FinishDialogDelegate Finish { get; set; } - public DialogReturnType ReturnObject { get; protected set; } + public object ReturnObject { get; protected set; } } } diff --git a/Aurora/Design/Views/DialogReturnObject.cs b/Aurora/Design/Views/DialogReturnObject.cs deleted file mode 100644 index 3daa267..0000000 --- a/Aurora/Design/Views/DialogReturnObject.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Aurora.Design.Views -{ - public class DialogReturnType - { - - } -} \ No newline at end of file diff --git a/Aurora/Design/Views/MainView/MainView.xaml b/Aurora/Design/Views/MainView/MainView.xaml index 8654823..37714c9 100644 --- a/Aurora/Design/Views/MainView/MainView.xaml +++ b/Aurora/Design/Views/MainView/MainView.xaml @@ -22,6 +22,7 @@ <ColumnDefinition Width="150"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> + <!--Header--> <StackLayout x:Name="Header" @@ -51,7 +52,7 @@ <views:PageContainer Grid.Column="1" Grid.Row="2" - x:Name="ContentPage"/> + x:Name="Content"/> <!--Modal Dialog--> <dialog:Modal x:Name="Modal" diff --git a/Aurora/Design/Views/MainView/MainView.xaml.cs b/Aurora/Design/Views/MainView/MainView.xaml.cs index e079c6b..b25e5e7 100644 --- a/Aurora/Design/Views/MainView/MainView.xaml.cs +++ b/Aurora/Design/Views/MainView/MainView.xaml.cs @@ -48,7 +48,7 @@ namespace Aurora.Design.Views.Main _playerComponent = Player; - _viewContent = (ContentPresenter)ContentPage.Content.FindByName("ViewContent"); + _viewContent = (ContentPresenter)Content.FindByName("ViewContent"); _playerService = PlayerService.Instance; MasterPage.ListView.ItemSelected += OnNavItemSelected; @@ -267,7 +267,6 @@ namespace Aurora.Design.Views.Main private void ChangeModalVisiblity(bool isVisible) { - ContentPage.IsVisible = !isVisible; Modal.IsVisible = isVisible; } } diff --git a/Aurora/Design/Views/Party/NewPartyDialog/ConnectionDetails.cs b/Aurora/Design/Views/Party/NewPartyDialog/ConnectionDetails.cs index 5e58dfa..ea51311 100644 --- a/Aurora/Design/Views/Party/NewPartyDialog/ConnectionDetails.cs +++ b/Aurora/Design/Views/Party/NewPartyDialog/ConnectionDetails.cs @@ -7,7 +7,7 @@ namespace Aurora.Design.Views.Party.NewPartyDialog Join } - public class ConnectionDetails : DialogReturnType + public class ConnectionDetails { public ConnectionDetails() { diff --git a/Aurora/Design/Views/Party/PartyView.xaml b/Aurora/Design/Views/Party/PartyView.xaml index 647fdcf..db599dd 100644 --- a/Aurora/Design/Views/Party/PartyView.xaml +++ b/Aurora/Design/Views/Party/PartyView.xaml @@ -2,7 +2,6 @@ <ContentView 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:library="clr-namespace:Aurora.Design.Components.Library" x:Class="Aurora.Design.Views.Party.PartyView"> @@ -13,8 +12,7 @@ Height="*"/> </Grid.RowDefinitions> <StackLayout - Grid.Row="0" - IsVisible="{Binding IsNotSelectingHost}"> + Grid.Row="0"> <Label Text="Party Members"/> <ml:MemberList @@ -26,8 +24,7 @@ ItemsSource="{Binding Queue}" SelectedItem="{Binding SelectedSong}" ItemDoubleClicked="{Binding PlayCommand}"/> - </StackLayout> - <!--<hs:HostSelector + </StackLayout><!--<hs:HostSelector Grid.Row="0" x:Name="HostSelectionDialog" Hostname="{Binding Hostname}" diff --git a/Aurora/Design/Views/Party/PartyViewModel.cs b/Aurora/Design/Views/Party/PartyViewModel.cs index 8a59f68..ac7d792 100644 --- a/Aurora/Design/Views/Party/PartyViewModel.cs +++ b/Aurora/Design/Views/Party/PartyViewModel.cs @@ -28,7 +28,7 @@ namespace Aurora.Design.Views.Party public class PartyViewModel : BaseViewModel { private PartyState _state; - private string _hostname; + private string _hostname = ""; private ObservableCollection<PartyMember> _members; private ObservableCollection<BaseMedia> _queue; private BaseMedia _selectedMedia; @@ -36,9 +36,6 @@ namespace Aurora.Design.Views.Party public PartyViewModel() { - this.JoinCommand = new Command(OnJoinExecute, CanJoinExecute); - this.HostCommand = new Command(OnHostExecute, CanHostExecute); - _members = new ObservableCollection<PartyMember>(); _queue = new ObservableCollection<BaseMedia>(); @@ -78,20 +75,6 @@ namespace Aurora.Design.Views.Party } } - public bool IsSelectingHost - { - get { return _state == PartyState.SelectingHost; } - } - - /// <summary> - /// Public property indicating the state. - /// </summary> - /// <value></value> - public bool IsNotSelectingHost - { - get { return _state != PartyState.SelectingHost; } - } - /// <summary> /// Public property for queue item source /// </summary> @@ -111,18 +94,6 @@ namespace Aurora.Design.Views.Party } } - - - /// <summary> - /// Public property for the hostname bindable field - /// </summary> - /// <value></value> - public string Hostname - { - get { return _hostname; } - set { SetProperty(ref _hostname, value); } - } - /// <summary> /// Public property for the currently selected song. /// </summary> @@ -139,18 +110,6 @@ namespace Aurora.Design.Views.Party /// <value></value> public Command PlayCommand { get; private set; } - /// <summary> - /// Public property for join command - /// </summary> - /// <value></value> - public Command JoinCommand { get; set; } - - /// <summary> - /// Pubic property for host command - /// </summary> - /// <value></value> - public Command HostCommand { get; set; } - #endregion Properties #region Events @@ -167,8 +126,26 @@ namespace Aurora.Design.Views.Party } else { - var asdf = await this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), typeof(NewPartyDialogViewModel)); - System.Diagnostics.Debug.WriteLine(""); + //Open host selection modal + var modalResult = await this.ShowModal(typeof(NewPartyDialog.NewPartyDialog), typeof(NewPartyDialogViewModel)); + if (modalResult is ConnectionDetails) + { + ConnectionDetails details = modalResult as ConnectionDetails; + _hostname = details.HostName; + switch (details.ConnectionType) + { + case ConnectionType.Host: + { + OnHostExecute(); + break; + } + case ConnectionType.Join: + { + OnJoinExecute(); + break; + } + } + } } } @@ -250,7 +227,7 @@ namespace Aurora.Design.Views.Party private async void OnJoinExecute() { SetState(PartyState.Connecting); - _client.Start(Hostname, SettingsService.Instance.DefaultPort.ToString()); + _client.Start(_hostname, SettingsService.Instance.DefaultPort.ToString()); await JoinParty(false); //TODO add cancellation token @@ -392,9 +369,10 @@ namespace Aurora.Design.Views.Party //Subscribe to events await SubscribeToEvents(); + Queue.Clear(); QueueResponse queueResponse = _client.RemotePartyClient.GetQueue(new Empty()); - Queue.Clear(); + //Convert received data to remote audio models foreach (RemoteMediaData data in queueResponse.MediaList) {