Group headings working for navigation menu

This commit is contained in:
watsonb8 2019-05-18 18:18:28 -04:00
parent 9dcd411090
commit ae6bd68707
6 changed files with 61 additions and 5 deletions

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Aurora.Frontend.Components.NavigationMenu
{
public class NavigationGroupItem : List<NavigationItem>
{
public NavigationGroupItem()
{
}
public NavigationGroupItem(string heading)
{
GroupHeading = heading;
}
public List<NavigationItem> Items => this;
public string GroupHeading { get; set; }
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Aurora.Frontend.Views.Main;
namespace Aurora.Frontend.Views.Components.NavigationMenu
namespace Aurora.Frontend.Components.NavigationMenu
{
public class NavigationItem
{

View File

@ -9,6 +9,7 @@
SeparatorVisibility="None"
HasUnevenRows="true"
BackgroundColor="{StaticResource MenuBackgroundColor}"
IsGroupingEnabled="true"
CachingStrategy="RecycleElement">
<ListView.Header>
<Grid BackgroundColor="#03A9F4">
@ -27,6 +28,14 @@
</Grid>
</ListView.Header>
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<Label VerticalOptions="FillAndExpand" VerticalTextAlignment="Start" Text="{Binding GroupHeading}" FontSize="18" TextColor="White"/>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Aurora.Frontend.Views.Components.NavigationMenu;
using Xamarin.Forms;
namespace Aurora.Frontend.Components.NavigationMenu
@ -38,7 +37,34 @@ namespace Aurora.Frontend.Components.NavigationMenu
private static void OnItemsChanged(BindableObject bindable, object oldValue, object newValue)
{
var control = (NavigationMenu)bindable;
control.MenuItemsListView.ItemsSource = (ObservableCollection<NavigationItem>)newValue;
ObservableCollection<NavigationItem> items = (ObservableCollection<NavigationItem>)newValue;
Dictionary<string, NavigationGroupItem> groupDictioanry = new Dictionary<string, NavigationGroupItem>();
//Populate dictionary where group heading is the key
foreach(NavigationItem item in items)
{
if(groupDictioanry.ContainsKey(item.Group))
{
groupDictioanry.TryGetValue(item.Group, out var groupItem);
groupItem.Items.Add(item);
}
else
{
NavigationGroupItem groupItem = new NavigationGroupItem(item.Group);
groupItem.Add(item);
groupDictioanry.Add(item.Group, groupItem);
}
}
ObservableCollection<NavigationGroupItem> groups = new ObservableCollection<NavigationGroupItem>();
foreach(string groupHeading in groupDictioanry.Keys)
{
groupDictioanry.TryGetValue(groupHeading, out var groupItem);
groups.Add(groupItem);
}
control.MenuItemsListView.ItemsSource = groups;
}
}

View File

@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Aurora.Frontend.Views.Components.NavigationMenu;
using Aurora.Frontend.Components.NavigationMenu;
using Aurora.Frontend.Views.MainView;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

View File

@ -2,9 +2,9 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Aurora.Frontend.Components.NavigationMenu;
using Aurora.Frontend.Views.Albums;
using Aurora.Frontend.Views.Artists;
using Aurora.Frontend.Views.Components.NavigationMenu;
using Aurora.Frontend.Views.Songs;
using Aurora.Frontend.Views.Stations;