Work in progress

This commit is contained in:
watsonb8 2019-12-18 20:23:59 -05:00
parent 555eb07ec1
commit 93dc9ae8c9
9 changed files with 166 additions and 112 deletions

View File

@ -87,6 +87,7 @@
</ResourceDictionary> </ResourceDictionary>
</Grid.Resources> </Grid.Resources>
</Grid> </Grid>
<ListView x:Name="DataList" Grid.Row="1" BackgroundColor="#222222" />
<ContentView <ContentView
x:Name="_noDataView" x:Name="_noDataView"
Grid.RowSpan="2" Grid.RowSpan="2"

View File

@ -2,6 +2,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Windows.Input; using System.Windows.Input;
@ -13,16 +14,15 @@ namespace Aurora.Design.Components.DataGrid
public partial class DataGrid : Grid public partial class DataGrid : Grid
{ {
#region Private Fields #region Private Fields
private IList<object> _internalItems; private ObservableCollection<object> _internalItems;
private Dictionary<int, SortingOrder> _sortingOrders; private Dictionary<int, SortingOrder> _sortingOrders;
private ListView _listView;
#endregion Fields #endregion Fields
#region Constructor #region Constructor
public DataGrid() : this(ListViewCachingStrategy.RecycleElement) public DataGrid() : this(ListViewCachingStrategy.RetainElement)
{ {
} }
@ -33,35 +33,28 @@ namespace Aurora.Design.Components.DataGrid
_sortingOrders = new Dictionary<int, SortingOrder>(); _sortingOrders = new Dictionary<int, SortingOrder>();
_listView = new ListView(cachingStrategy) DataList.ItemTemplate = new DataGridRowTemplateSelector();
{
BackgroundColor = Color.FromHex("#222222"),
ItemTemplate = new DataGridRowTemplateSelector(),
SeparatorVisibility = SeparatorVisibility.Default,
};
_listView.ItemSelected += (s, e) => DataList.ItemSelected += (s, e) =>
{ {
if (SelectionEnabled) if (SelectionEnabled)
{ {
SelectedItem = _listView.SelectedItem; SelectedItem = DataList.SelectedItem;
} }
else else
{ {
_listView.SelectedItem = null; DataList.SelectedItem = null;
} }
ItemSelected?.Invoke(this, e); ItemSelected?.Invoke(this, e);
}; };
_listView.Refreshing += (s, e) => DataList.Refreshing += (s, e) =>
{ {
Refreshing?.Invoke(this, e); Refreshing?.Invoke(this, e);
}; };
_listView.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this)); DataList.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this));
Grid.SetRow(_listView, 1);
Children.Add(_listView);
} }
#endregion Constructor #endregion Constructor
@ -151,29 +144,29 @@ namespace Aurora.Design.Components.DataGrid
defaultValueCreator: bindable => { return new ColumnCollection(); } defaultValueCreator: bindable => { return new ColumnCollection(); }
); );
public static readonly BindableProperty ItemsSourceProperty = public static BindableProperty ItemsSourceProperty =
BindableProperty.Create( BindableProperty.Create(
nameof(ItemsSource), propertyName: nameof(ItemsSource),
typeof(IEnumerable), returnType: typeof(IEnumerable),
typeof(DataGrid), declaringType: typeof(DataGrid),
null, defaultBindingMode: BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => propertyChanged: (bindable, oldValue, newValue) =>
{ {
DataGrid self = bindable as DataGrid; DataGrid self = bindable as DataGrid;
//ObservableCollection Tracking //ObservableCollection Tracking
if (oldValue != null && oldValue is INotifyCollectionChanged) if (oldValue != null && oldValue is INotifyCollectionChanged)
(oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
if (newValue != null)
{ {
if (newValue is INotifyCollectionChanged) (oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
{ }
(newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged;
} if (newValue != null && newValue is INotifyCollectionChanged)
self.InternalItems = new List<object>(((IEnumerable)newValue).Cast<object>()); {
(newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged;
self.InternalItems = new ObservableCollection<object>(((IEnumerable<object>)newValue));
//Assign listview item source //Assign listview item source
// self._listView.ItemsSource = self.InternalItems; self.DataList.ItemsSource = self.InternalItems;
self._listView.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsSource", source: self)); self.DataList.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsSource", source: self));
} }
if (self.SelectedItem != null && !self.InternalItems.Contains(self.SelectedItem)) if (self.SelectedItem != null && !self.InternalItems.Contains(self.SelectedItem))
@ -181,7 +174,6 @@ namespace Aurora.Design.Components.DataGrid
self.SelectedItem = null; self.SelectedItem = null;
} }
if (self.NoDataView != null) if (self.NoDataView != null)
{ {
if (self.ItemsSource == null || self.InternalItems.Count() == 0) if (self.ItemsSource == null || self.InternalItems.Count() == 0)
@ -197,7 +189,7 @@ namespace Aurora.Design.Components.DataGrid
}); });
private void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) private void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
// InternalItems = new List<object>(((IEnumerable)sender).Cast<object>());
if (e.NewItems != null) if (e.NewItems != null)
{ {
foreach (object item in e.NewItems) foreach (object item in e.NewItems)
@ -224,7 +216,7 @@ namespace Aurora.Design.Components.DataGrid
propertyChanged: (bindable, oldValue, newValue) => propertyChanged: (bindable, oldValue, newValue) =>
{ {
var self = bindable as DataGrid; var self = bindable as DataGrid;
self._listView.RowHeight = (int)newValue; self.DataList.RowHeight = (int)newValue;
}); });
@ -275,9 +267,9 @@ namespace Aurora.Design.Components.DataGrid
propertyChanged: (bindable, oldValue, newValue) => propertyChanged: (bindable, oldValue, newValue) =>
{ {
var self = bindable as DataGrid; var self = bindable as DataGrid;
if (self._listView.SelectedItem != newValue) if (self.DataList.SelectedItem != newValue)
{ {
self._listView.SelectedItem = newValue; self.DataList.SelectedItem = newValue;
} }
} }
); );
@ -300,13 +292,13 @@ namespace Aurora.Design.Components.DataGrid
var self = bindable as DataGrid; var self = bindable as DataGrid;
if (newValue == null) if (newValue == null)
{ {
self._listView.IsPullToRefreshEnabled = false; self.DataList.IsPullToRefreshEnabled = false;
self._listView.RefreshCommand = null; self.DataList.RefreshCommand = null;
} }
else else
{ {
self._listView.IsPullToRefreshEnabled = true; self.DataList.IsPullToRefreshEnabled = true;
self._listView.RefreshCommand = newValue as ICommand; self.DataList.RefreshCommand = newValue as ICommand;
} }
}); });
@ -319,7 +311,7 @@ namespace Aurora.Design.Components.DataGrid
BindingMode.TwoWay, BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => propertyChanged: (bindable, oldValue, newValue) =>
{ {
(bindable as DataGrid)._listView.IsRefreshing = (bool)newValue; (bindable as DataGrid).DataList.IsRefreshing = (bool)newValue;
}); });
public static readonly BindableProperty BorderThicknessProperty = public static readonly BindableProperty BorderThicknessProperty =
@ -480,7 +472,7 @@ namespace Aurora.Design.Components.DataGrid
set { SetValue(ItemsSourceProperty, value); } set { SetValue(ItemsSourceProperty, value); }
} }
internal IList<object> InternalItems internal ObservableCollection<object> InternalItems
{ {
get { return _internalItems; } get { return _internalItems; }
set set
@ -493,8 +485,7 @@ namespace Aurora.Design.Components.DataGrid
SortItems(SortedColumnIndex); SortItems(SortedColumnIndex);
} }
} }
// _listView.ItemsSource = _internalItems; DataList.ItemsSource = _internalItems;
} }
} }
@ -638,7 +629,7 @@ namespace Aurora.Design.Components.DataGrid
private void Reload() private void Reload()
{ {
InternalItems = new List<object>(_internalItems); InternalItems = new ObservableCollection<object>(_internalItems);
} }
private void SortItems(SortData sData) private void SortItems(SortData sData)
{ {
@ -655,10 +646,10 @@ namespace Aurora.Design.Components.DataGrid
throw new InvalidOperationException("Please set the PropertyName property of Column"); throw new InvalidOperationException("Please set the PropertyName property of Column");
//Sort //Sort
if (order == SortingOrder.Descendant) // if (order == SortingOrder.Descendant)
items = items.OrderByDescending(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList(); // items = items.OrderByDescending(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
else // else
items = items.OrderBy(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList(); // items = items.OrderBy(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
column.SortingIcon.Style = (order == SortingOrder.Descendant) ? column.SortingIcon.Style = (order == SortingOrder.Descendant) ?
AscendingIconStyle ?? (Style)_headerView.Resources["DescendingIconStyle"] : AscendingIconStyle ?? (Style)_headerView.Resources["DescendingIconStyle"] :

View File

@ -12,15 +12,17 @@ namespace Aurora.Design.Components.DataGrid
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{ {
var listView = container as ListView; ListView listView = container as ListView;
var dataGrid = listView.Parent as DataGrid; DataGrid dataGrid = listView.Parent as DataGrid;
var items = dataGrid.InternalItems; var items = dataGrid.InternalItems;
_dataGridRowTemplate.SetValue(DataGridViewCell.DataGridProperty, dataGrid); _dataGridRowTemplate.SetValue(DataGridViewCell.DataGridProperty, dataGrid);
_dataGridRowTemplate.SetValue(DataGridViewCell.RowContextProperty, item); _dataGridRowTemplate.SetValue(DataGridViewCell.RowContextProperty, item);
if (items != null) if (items != null)
{
_dataGridRowTemplate.SetValue(DataGridViewCell.IndexProperty, items.IndexOf(item)); _dataGridRowTemplate.SetValue(DataGridViewCell.IndexProperty, items.IndexOf(item));
}
return _dataGridRowTemplate; return _dataGridRowTemplate;
} }

View File

@ -32,15 +32,26 @@ namespace Aurora.Design.Components.DataGrid
#region Bindable Properties #region Bindable Properties
public static readonly BindableProperty DataGridProperty = public static readonly BindableProperty DataGridProperty =
BindableProperty.Create(nameof(DataGrid), typeof(DataGrid), typeof(DataGridViewCell), null, BindableProperty.Create(
nameof(DataGrid),
typeof(DataGrid),
typeof(DataGridViewCell),
null,
propertyChanged: (b, o, n) => (b as DataGridViewCell).CreateView()); propertyChanged: (b, o, n) => (b as DataGridViewCell).CreateView());
public static readonly BindableProperty IndexProperty = public static readonly BindableProperty IndexProperty =
BindableProperty.Create(nameof(Index), typeof(int), typeof(DataGridViewCell), 0, BindableProperty.Create(
nameof(Index),
typeof(int),
typeof(DataGridViewCell),
0,
propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor()); propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor());
public static readonly BindableProperty RowContextProperty = public static readonly BindableProperty RowContextProperty =
BindableProperty.Create(nameof(RowContext), typeof(object), typeof(DataGridViewCell), BindableProperty.Create(
nameof(RowContext),
typeof(object),
typeof(DataGridViewCell),
propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor()); propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor());
#endregion #endregion

View File

@ -2,8 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Xamarin.Forms; using Xamarin.Forms;
using System.ComponentModel;
using System.Collections.Specialized;
namespace Aurora.Design.Components.Library namespace Aurora.Design.Components.Library
{ {
@ -33,51 +31,9 @@ namespace Aurora.Design.Components.Library
propertyChanged: (BindableObject bindable, object oldValue, object newValue) => propertyChanged: (BindableObject bindable, object oldValue, object newValue) =>
{ {
Library control = bindable as Library; Library control = bindable as Library;
control.LibraryDataGrid.ItemsSource = (IEnumerable<object>)newValue;
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> /// <summary>
/// Backing property for the ItemsSource property. /// Backing property for the ItemsSource property.
@ -164,10 +120,10 @@ namespace Aurora.Design.Components.Library
private static void OnDoubleClickPropertyChanged(BindableObject bindable, object newValue, object oldValue) private static void OnDoubleClickPropertyChanged(BindableObject bindable, object newValue, object oldValue)
{ {
Library control = bindable as Library; Library control = bindable as Library;
var queueDataGrid = control.LibraryDataGrid; var dataGrid = control.LibraryDataGrid;
if (queueDataGrid.GestureRecognizers.Count > 0) if (dataGrid.GestureRecognizers.Count > 0)
{ {
var gestureRecognizer = queueDataGrid.GestureRecognizers.First(); var gestureRecognizer = dataGrid.GestureRecognizers.First();
if (gestureRecognizer is TapGestureRecognizer) if (gestureRecognizer is TapGestureRecognizer)
{ {

View File

@ -3,5 +3,7 @@
xmlns="http://xamarin.com/schemas/2014/forms" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Aurora.Design.Views.Artists.ArtistsView"> x:Class="Aurora.Design.Views.Artists.ArtistsView">
<ContentPage.Content></ContentPage.Content> <ContentView.Content>
</ContentView.Content>
</ContentView> </ContentView>

View File

@ -1,10 +1,19 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
namespace Aurora.Design.Views.Artists namespace Aurora.Design.Views.Artists
{ {
public class TestObj
{
public string Test1 { get; set; }
public string Test2 { get; set; }
}
public class ArtistsViewModel : BaseViewModel public class ArtistsViewModel : BaseViewModel
{ {
public ArtistsViewModel() public ArtistsViewModel()
{ {
} }
} }
} }

View File

@ -3,6 +3,7 @@
xmlns="http://xamarin.com/schemas/2014/forms" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ml="clr-namespace:Aurora.Design.Components.MemberList" xmlns:ml="clr-namespace:Aurora.Design.Components.MemberList"
xmlns:dg="clr-namespace:Aurora.Design.Components.DataGrid"
xmlns:library="clr-namespace:Aurora.Design.Components.Library" xmlns:library="clr-namespace:Aurora.Design.Components.Library"
x:Class="Aurora.Design.Views.Party.PartyView"> x:Class="Aurora.Design.Views.Party.PartyView">
<ContentView.Content> <ContentView.Content>
@ -20,17 +21,97 @@
Members="{Binding Members}"/> Members="{Binding Members}"/>
<Label <Label
Text="Queue"/> Text="Queue"/>
<library:Library <dg:DataGrid
x:Name="LibraryDataGrid"
SelectionEnabled="True"
RowHeight="30"
BorderColor="#3a3a3a"
BorderThickness="0"
HeaderHeight="40"
HeaderBackground="#222222"
ItemsSource="{Binding Queue}">
<dg:DataGrid.HeaderLabelStyle>
<Style
TargetType="Label">
<Setter
Property="HorizontalOptions"
Value="Start"/>
<Setter
Property="FontSize"
Value="14"/>
<Setter
Property="TextColor"
Value="White"/>
</Style>
</dg:DataGrid.HeaderLabelStyle>
<dg:DataGrid.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="2"/>
</dg:DataGrid.GestureRecognizers>
<dg:DataGrid.Columns>
<dg:DataGridColumn
Title=""
PropertyName="Icon"
Width="15">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Image
Source="../../Resources/unselected.png"/>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn
Title="Title"
PropertyName="Metadata.Title"
Width="2*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Label
LineBreakMode="TailTruncation"
Text="{Binding .}"/>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn
Title="Album"
PropertyName="Metadata.Album"
Width="0.95*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Label
LineBreakMode="TailTruncation"
Text="{Binding .}"/>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
<dg:DataGridColumn
Title="Artist"
PropertyName="Metadata.Artist"
Width="1*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<Label
LineBreakMode="TailTruncation"
Text="{Binding .}"/>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsTextColorPalette>
<dg:PaletteCollection>
<Color>White</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsTextColorPalette>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>Transparent</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid><!-- <library:Library
ItemsSource="{Binding Queue}" ItemsSource="{Binding Queue}"
SelectedItem="{Binding SelectedSong}" SelectedItem="{Binding SelectedSong}"
ItemDoubleClicked="{Binding PlayCommand}"/> ItemDoubleClicked="{Binding PlayCommand}"/> -->
</StackLayout><!--<hs:HostSelector </StackLayout>
Grid.Row="0"
x:Name="HostSelectionDialog"
Hostname="{Binding Hostname}"
HostCommand="{Binding HostCommand}"
JoinCommand="{Binding JoinCommand}"
IsVisible="{Binding IsSelectingHost}"/>-->
</Grid> </Grid>
</ContentView.Content> </ContentView.Content>
</ContentView> </ContentView>

View File

@ -390,6 +390,7 @@ namespace Aurora.Design.Views.Party
_client.RemoteSyncClient); _client.RemoteSyncClient);
Queue.Add(remote); Queue.Add(remote);
OnPropertyChanged("Queue");
} }
} }
catch (Exception ex) catch (Exception ex)