This commit is contained in:
watsonb8 2019-12-10 15:10:27 -05:00
parent 01736333e9
commit cf05045448
11 changed files with 98 additions and 237 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +0,0 @@
namespace Aurora.Design.Views
{
public class DialogReturnType
{
}
}

View File

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

View File

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

View File

@ -7,7 +7,7 @@ namespace Aurora.Design.Views.Party.NewPartyDialog
Join
}
public class ConnectionDetails : DialogReturnType
public class ConnectionDetails
{
public ConnectionDetails()
{

View File

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

View File

@ -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)
{