diff --git a/Dialer/Dialer.csproj b/Dialer/Dialer.csproj index e1a931b..4f5f1de 100644 --- a/Dialer/Dialer.csproj +++ b/Dialer/Dialer.csproj @@ -34,6 +34,7 @@ + diff --git a/Dialer/UI/Pages/ContactsPage.xaml b/Dialer/UI/Pages/ContactsPage.xaml index af54059..607636c 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml +++ b/Dialer/UI/Pages/ContactsPage.xaml @@ -6,40 +6,220 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:Dialer.UI.Controls" + xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" xmlns:Windows10FallCreatorsUpdate="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 5)" mc:Ignorable="d" NavigationCacheMode="Required"> - - - - - - - - - - - - - - - - - - - - - - A - - - - - - Loading contact list... - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A + + + + + + Loading contact list... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index db4d554..a87c1be 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -1,7 +1,10 @@ using Dialer.Systems; using Dialer.UI.Controls; using Microsoft.UI.Dispatching; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Navigation; using System; using System.Collections.Generic; @@ -10,6 +13,8 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Windows.ApplicationModel.Contacts; +using Microsoft.International.Converters.PinYinConverter; namespace Dialer.UI.Pages { @@ -58,6 +63,13 @@ private void LoadDataCompleted() _contactControls = ContactSystem.ContactControls; ContactsItemsControl.ItemsSource = _contactControls; LoadingGrid.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed; + + var collectionViewSource = grid.Resources["CollectionViewSource"] as CollectionViewSource; + collectionViewSource.Source = from item in ContactSystem.Contacts + group item by GetCharSpellCode(item.DisplayName.FirstOrDefault('#').ToString()) into g + orderby g.Key + select new GroupInfoList(g) { Key = g.Key }; + }); } @@ -119,5 +131,37 @@ public void RemoveContactControl(ContactControl cc) { _ = _contactControls.Remove(cc); } + + private static string GetCharSpellCode(string _char) + { + byte[] array = new byte[2]; + array = System.Text.Encoding.Default.GetBytes(_char.Trim()); + + if (array.Length == 1) + return _char.ToUpper(); + + if (array.Length > 1) + { + ChineseChar chineseChar = new ChineseChar(_char[0]); + return chineseChar.Pinyins.First().First().ToString(); + } + + return "#"; + + } + } +} + +internal class GroupInfoList : List +{ + public GroupInfoList(IEnumerable items) : base(items) + { + } + + public object Key { get; set; } + + public override string ToString() + { + return "Group " + Key.ToString(); } }