From a6979cd00a0cb6b88122cef026172c146a78f0b7 Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Mon, 12 Jul 2021 17:29:21 +0200 Subject: [PATCH 01/12] First work into contacts page --- Dialer/UI/Controls/ContactControl.xaml | 51 ++++++++++++++ Dialer/UI/Controls/ContactControl.xaml.cs | 69 +++++++++++++++++++ .../UI/Controls/VerticalIndexScrollbar.xaml | 44 ++++++++++++ .../Controls/VerticalIndexScrollbar.xaml.cs | 30 ++++++++ Dialer/UI/Pages/ContactsPage.xaml | 22 +++++- Dialer/UI/Pages/ContactsPage.xaml.cs | 57 +++++++++++++-- 6 files changed, 264 insertions(+), 9 deletions(-) create mode 100644 Dialer/UI/Controls/ContactControl.xaml create mode 100644 Dialer/UI/Controls/ContactControl.xaml.cs create mode 100644 Dialer/UI/Controls/VerticalIndexScrollbar.xaml create mode 100644 Dialer/UI/Controls/VerticalIndexScrollbar.xaml.cs diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml new file mode 100644 index 0000000..4403462 --- /dev/null +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dialer/UI/Controls/ContactControl.xaml.cs b/Dialer/UI/Controls/ContactControl.xaml.cs new file mode 100644 index 0000000..16c2a0c --- /dev/null +++ b/Dialer/UI/Controls/ContactControl.xaml.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.Storage; +using Windows.Storage.Streams; +using Windows.UI.Composition; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Imaging; +using Windows.UI.Xaml.Navigation; + + +namespace Dialer.UI.Controls +{ + public sealed partial class ContactControl : UserControl + { + public string ContactName + { + get => ContactNameTB.Text; + set => ContactNameTB.Text = value; + } + + public string ContactMainPhone + { + get => ContactMainPhoneTB.Text; + set => ContactMainPhoneTB.Text = value; + } + + public IRandomAccessStreamReference ContactPicture + { + set => ContactImage.Source = new BitmapImage(new Uri(((StorageFile) value).Path)); + } + + public ContactControl() + { + InitializeComponent(); + } + + private void ToggleMoreDataButton_Tapped(object sender, TappedRoutedEventArgs e) + { + if (MoreDataPanel.Visibility == Visibility.Collapsed) + { + ToggleMoreDataButtonIcon.Glyph = "\uE010"; + MoreDataPanel.Visibility = Visibility.Visible; + //MoreDataPanel.Margin = new Thickness(0, 80, 0, 0); + HeightAnimationOpen.To = 80 + MoreDataPanel.ActualHeight; + ShowPaneAnimation.Begin(); + PrimaryPanel.CornerRadius = new CornerRadius(4, 4, 0, 0); + } else + { + ToggleMoreDataButtonIcon.Glyph = "\uE011"; + //MoreDataPanel.Margin = new Thickness(0, 0, 0, 0); + HeightAnimationClose.From = 80 + MoreDataPanel.ActualHeight; + HidePaneAnimation.Completed += (object a, object b) => MoreDataPanel.Visibility = Visibility.Collapsed; + HidePaneAnimation.Begin(); + PrimaryPanel.CornerRadius = new CornerRadius(4, 4, 4, 4); + } + } + } +} diff --git a/Dialer/UI/Controls/VerticalIndexScrollbar.xaml b/Dialer/UI/Controls/VerticalIndexScrollbar.xaml new file mode 100644 index 0000000..afe14f0 --- /dev/null +++ b/Dialer/UI/Controls/VerticalIndexScrollbar.xaml @@ -0,0 +1,44 @@ + + + + + # + A + B + C + D + E + F + G + H + I + J + K + L + M + N + O + P + Q + R + S + T + U + V + W + X + Y + Z + ? + + + diff --git a/Dialer/UI/Controls/VerticalIndexScrollbar.xaml.cs b/Dialer/UI/Controls/VerticalIndexScrollbar.xaml.cs new file mode 100644 index 0000000..dd407f6 --- /dev/null +++ b/Dialer/UI/Controls/VerticalIndexScrollbar.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +namespace Dialer.UI.Controls +{ + public sealed partial class VerticalIndexScrollbar : UserControl + { + public VerticalIndexScrollbar() + { + InitializeComponent(); + } + + public void FixSpacing() + { + LettersStackPanel.Spacing = (LettersStackPanel.ActualHeight / 26d) - 21d; + } + } +} diff --git a/Dialer/UI/Pages/ContactsPage.xaml b/Dialer/UI/Pages/ContactsPage.xaml index 31761b9..46c9538 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml +++ b/Dialer/UI/Pages/ContactsPage.xaml @@ -4,11 +4,29 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Dialer.UI.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)" + xmlns:controls="using:Dialer.UI.Controls" mc:Ignorable="d" NavigationCacheMode="Required"> - + + + + + + + + + + + + + + + Loading contact list... + + diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index 73da3c2..f34a8ce 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -1,17 +1,60 @@ -using Windows.UI.Xaml.Controls; - -// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 +using Dialer.UI.Controls; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using Windows.ApplicationModel.Contacts; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Navigation; namespace Dialer.UI.Pages { - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// + public sealed partial class ContactsPage : Page { + + ObservableCollection ContactControls; + public ContactsPage() { - this.InitializeComponent(); + InitializeComponent(); + ContactControls = new ObservableCollection(); + } + + protected async override void OnNavigatedTo(NavigationEventArgs e) + { + base.OnNavigatedTo(e); + SizeChanged += ContactsPage_SizeChanged; + + LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; + + //if(ContactControls.Count != 0) + //{ + ContactStore contactStore = await ContactManager.RequestStoreAsync(); + IReadOnlyList contacts = await contactStore.FindContactsAsync(); + + Debug.WriteLine("Found " + contacts.Count + " contacts"); + + foreach (Contact contact in contacts) + { + ContactControl cc = new ContactControl(); + cc.ContactName = contact.DisplayName; + if (contact.Phones.Count == 0) continue; + cc.ContactMainPhone = contact.Phones[0].Number; + try + { + if(contact.SmallDisplayPicture != null) cc.ContactPicture = contact.SmallDisplayPicture; + } catch { } + ContactControls.Add(cc); + } + //} + + LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; + } + + private void ContactsPage_SizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) + { + viScrollbar.FixSpacing(); } } } From 0ffe0ce91333e5a0e881ee151b11ede0c9167a0a Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Mon, 12 Jul 2021 21:39:18 +0200 Subject: [PATCH 02/12] Can now call from the contacts page; various improvements --- Dialer/Dialer.csproj | 16 ++++++++++++++- Dialer/UI/Controls/ContactControl.xaml | 2 +- Dialer/UI/Controls/ContactControl.xaml.cs | 25 ++++++++++++++++++++++- Dialer/UI/Pages/ContactsPage.xaml | 8 +++++--- Dialer/UI/Pages/ContactsPage.xaml.cs | 17 ++++++++++++--- 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/Dialer/Dialer.csproj b/Dialer/Dialer.csproj index 10b7919..8b3e374 100644 --- a/Dialer/Dialer.csproj +++ b/Dialer/Dialer.csproj @@ -31,7 +31,7 @@ 0 True SHA256 - 22CE1297025BAE413F6BEF99F1A63E5B7BB2536B + 040885C2D07C83DDF905F42787FC244EFB3EFD00 true @@ -143,9 +143,15 @@ CallHistoryEntryPresenter.xaml + + ContactControl.xaml + LinePresenter.xaml + + VerticalIndexScrollbar.xaml + @@ -292,6 +298,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -308,6 +318,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml index 4403462..b2a1568 100644 --- a/Dialer/UI/Controls/ContactControl.xaml +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -20,7 +20,7 @@ - + + + + diff --git a/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml.cs b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml.cs new file mode 100644 index 0000000..f376930 --- /dev/null +++ b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + + +namespace Dialer.UI.Controls +{ + public sealed partial class AdditionalPhoneContactPresenter : UserControl + { + public string PhoneType + { + get => PhoneTypeTB.Text; + set => PhoneTypeTB.Text = value; + } + + public string PhoneNumber + { + get => PhoneNumberTB.Text; + set => PhoneNumberTB.Text = value; + } + + public AdditionalPhoneContactPresenter() + { + InitializeComponent(); + } + } +} diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml index 16308ed..e6e9ed1 100644 --- a/Dialer/UI/Controls/ContactControl.xaml +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -4,13 +4,15 @@ xmlns:local="using:Dialer.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:Custom="using:System.Numerics" xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)" + xmlns:Custom="using:System.Numerics" + xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" x:Class="Dialer.UI.Controls.ContactControl" mc:Ignorable="d" d:DesignHeight="80" d:DesignWidth="600"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Dialer/UI/Controls/ContactControl.xaml.cs b/Dialer/UI/Controls/ContactControl.xaml.cs index f8a89d4..40c375e 100644 --- a/Dialer/UI/Controls/ContactControl.xaml.cs +++ b/Dialer/UI/Controls/ContactControl.xaml.cs @@ -1,11 +1,14 @@ using Dialer.Systems; +using Microsoft.UI.Xaml.Controls; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices.WindowsRuntime; +using System.Timers; using Windows.ApplicationModel.Calls; using Windows.Foundation; using Windows.Foundation.Collections; @@ -26,6 +29,9 @@ namespace Dialer.UI.Controls { public sealed partial class ContactControl : UserControl { + private List> additionalPhoneContacts; + private ObservableCollection additionalPhoneContactPresenters; + public string ContactName { get => ContactNameTB.Text; @@ -38,6 +44,22 @@ public string ContactMainPhone set => ContactMainPhoneTB.Text = value; } + public List> AdditionalContactPhones + { + get => additionalPhoneContacts; + set + { + additionalPhoneContacts = value; + foreach (Tuple additionalPhone in value) + { + AdditionalPhoneContactPresenter apcp = new AdditionalPhoneContactPresenter(); + apcp.PhoneType = additionalPhone.Item1; + apcp.PhoneNumber = additionalPhone.Item2; + additionalPhoneContactPresenters.Add(apcp); + } + } + } + public IRandomAccessStreamReference ContactPicture { set @@ -55,27 +77,7 @@ public IRandomAccessStreamReference ContactPicture public ContactControl() { InitializeComponent(); - } - - private void ToggleMoreDataButton_Tapped(object sender, TappedRoutedEventArgs e) - { - if (MoreDataPanel.Visibility == Visibility.Collapsed) - { - ToggleMoreDataButtonIcon.Glyph = "\uE010"; - MoreDataPanel.Visibility = Visibility.Visible; - //MoreDataPanel.Margin = new Thickness(0, 80, 0, 0); - HeightAnimationOpen.To = 80 + MoreDataPanel.ActualHeight; - ShowPaneAnimation.Begin(); - PrimaryPanel.CornerRadius = new CornerRadius(4, 4, 0, 0); - } else - { - ToggleMoreDataButtonIcon.Glyph = "\uE011"; - //MoreDataPanel.Margin = new Thickness(0, 0, 0, 0); - HeightAnimationClose.From = 80 + MoreDataPanel.ActualHeight; - HidePaneAnimation.Completed += (object a, object b) => MoreDataPanel.Visibility = Visibility.Collapsed; - HidePaneAnimation.Begin(); - PrimaryPanel.CornerRadius = new CornerRadius(4, 4, 4, 4); - } + additionalPhoneContactPresenters = new ObservableCollection(); } private void MainCallButton_Tapped(object sender, TappedRoutedEventArgs e) diff --git a/Dialer/UI/Pages/ContactsPage.xaml b/Dialer/UI/Pages/ContactsPage.xaml index 5b05fb6..1b897aa 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml +++ b/Dialer/UI/Pages/ContactsPage.xaml @@ -5,7 +5,6 @@ xmlns:local="using:Dialer.UI.Pages" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:Windows10version1903="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 8)" xmlns:controls="using:Dialer.UI.Controls" mc:Ignorable="d" NavigationCacheMode="Required"> diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index 29240bb..1c60c58 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -59,6 +59,12 @@ protected async override void OnNavigatedTo(NavigationEventArgs e) cc.ContactName = contact.DisplayName; if (contact.Phones.Count == 0) continue; cc.ContactMainPhone = contact.Phones[0].Number; + List> additionalPhones = new List>(); + foreach (ContactPhone contactPhone in contact.Phones) + { + additionalPhones.Add(new Tuple(contactPhone.Kind.ToString(), contactPhone.Number)); + } + cc.AdditionalContactPhones = additionalPhones; if(contact.SmallDisplayPicture != null) //TODO: Fix wrong cast cc.ContactPicture = contact.SmallDisplayPicture; From 86cd816de933a882694ddb9ec379dcbe4b0ed7c1 Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Wed, 14 Jul 2021 17:22:05 +0200 Subject: [PATCH 09/12] Fixes a breaking bug due to a leftover --- Dialer/UI/Controls/ContactControl.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml index e6e9ed1..a7df8f1 100644 --- a/Dialer/UI/Controls/ContactControl.xaml +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -54,7 +54,7 @@ --> - + From c20c7e28abb0b9cbf5083642fba0aeb5e2b1556b Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Thu, 15 Jul 2021 09:29:53 +0200 Subject: [PATCH 10/12] Removes leftover event handler which was not used --- Dialer/UI/Pages/ContactsPage.xaml.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index 1c60c58..b177d75 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -116,10 +116,5 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => } catch { } Debug.WriteLine("Got request to navigate to letter " + letter); } - - private void ScrollLetterHintHide_Completed(object sender, object e) - { - throw new NotImplementedException(); - } } } From d58d13a65bfc3a7487a900b3d7c34368426d8241 Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Fri, 16 Jul 2021 18:01:48 +0200 Subject: [PATCH 11/12] Refactored Contacts System into separate class. Added Context menus (might be removed later) --- Dialer/App.xaml.cs | 1 + Dialer/Dialer.csproj | 1 + Dialer/Systems/ContactSystem.cs | 100 ++++++++++++++++++ .../AdditionalPhoneContactPresenter.xaml | 6 ++ Dialer/UI/Controls/ContactControl.xaml | 53 ++-------- Dialer/UI/Controls/ContactControl.xaml.cs | 25 ++--- Dialer/UI/Pages/ContactsPage.xaml | 2 +- Dialer/UI/Pages/ContactsPage.xaml.cs | 86 +++++++-------- 8 files changed, 166 insertions(+), 108 deletions(-) create mode 100644 Dialer/Systems/ContactSystem.cs diff --git a/Dialer/App.xaml.cs b/Dialer/App.xaml.cs index 58ef1ee..bef1382 100644 --- a/Dialer/App.xaml.cs +++ b/Dialer/App.xaml.cs @@ -71,6 +71,7 @@ private async Task InitializateSystems() ResourceLoader = ResourceLoader.GetForViewIndependentUse(); NotificationSystem.Initializate(); await CallSystem.Initializate(); + await ContactSystem.LoadContacts(); } protected override void OnActivated(IActivatedEventArgs args) diff --git a/Dialer/Dialer.csproj b/Dialer/Dialer.csproj index b5aaaac..ae2b2fb 100644 --- a/Dialer/Dialer.csproj +++ b/Dialer/Dialer.csproj @@ -136,6 +136,7 @@ + diff --git a/Dialer/Systems/ContactSystem.cs b/Dialer/Systems/ContactSystem.cs new file mode 100644 index 0000000..0bbf7a4 --- /dev/null +++ b/Dialer/Systems/ContactSystem.cs @@ -0,0 +1,100 @@ +using Dialer.UI.Controls; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.ApplicationModel.Contacts; + +namespace Dialer.Systems +{ + class ContactSystem + { + private static ContactStore _contactStore; + private static ObservableCollection _contacts; + private static ObservableCollection _contactControls; + + public static event EventHandler ContactsLoaded; + + public static bool ContactsLoading = false; + + public static ObservableCollection Contacts + { + get + { + if (_contacts != null) return _contacts; + else return null; + } + } + + public static ObservableCollection ContactControls + { + get + { + if (_contactControls != null) return _contactControls; + else return null; + } + } + + public static async Task LoadContacts() + { + if(_contacts == null && ContactsLoading == false) + { + ContactsLoading = true; + _contactStore = await ContactManager.RequestStoreAsync(); + _contacts = new ObservableCollection(await _contactStore.FindContactsAsync()); + + Debug.WriteLine("Found " + _contacts.Count + " contacts"); + + _contactControls = new ObservableCollection(); + + foreach (Contact contact in _contacts) + { + ContactControl cc = new ContactControl(); + cc.AssociatedContact = contact; + cc.ContactName = contact.DisplayName; + if (contact.Phones.Count == 0) continue; + cc.ContactMainPhone = contact.Phones[0].Number; + List> additionalPhones = new List>(); + foreach (ContactPhone contactPhone in contact.Phones) + { + additionalPhones.Add(new Tuple(contactPhone.Kind.ToString(), contactPhone.Number)); + } + cc.AdditionalContactPhones = additionalPhones; + if (contact.SmallDisplayPicture != null) + //TODO: Fix wrong cast + cc.ContactPicture = contact.SmallDisplayPicture; + _contactControls.Add(cc); + } + } + + ContactsLoaded?.Invoke(null, EventArgs.Empty); + } + + public static async Task DeleteContact(Contact contact) + { + ContactStore cs = await ContactManager.RequestStoreAsync(); + ContactList cl = null; + try + { + cl = await cs.GetContactListAsync(contact.ContactListId); + } + catch + { + IReadOnlyList contactlists = await cs.FindContactListsAsync(); + foreach (ContactList _cl in contactlists) + { + try + { + if (_cl.GetContactAsync(contact.Id) != null) cl = _cl; + } + catch { } + } + } + if (cl == null) return; //For some reason the correct contact list can't be retrieved. It should be in Contact.ContactListId, but... + await cl.DeleteContactAsync(contact); + } + } +} diff --git a/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml index 7dcbcf7..c3c7278 100644 --- a/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml +++ b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml @@ -10,6 +10,12 @@ d:DesignWidth="400"> + + + + + + diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml index a7df8f1..7278034 100644 --- a/Dialer/UI/Controls/ContactControl.xaml +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -12,50 +12,17 @@ d:DesignHeight="80" d:DesignWidth="600"> - - + + + + + + + + + + diff --git a/Dialer/UI/Controls/ContactControl.xaml.cs b/Dialer/UI/Controls/ContactControl.xaml.cs index 40c375e..50e1619 100644 --- a/Dialer/UI/Controls/ContactControl.xaml.cs +++ b/Dialer/UI/Controls/ContactControl.xaml.cs @@ -1,29 +1,16 @@ using Dialer.Systems; -using Microsoft.UI.Xaml.Controls; +using Dialer.UI.Pages; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Timers; using Windows.ApplicationModel.Calls; -using Windows.Foundation; -using Windows.Foundation.Collections; +using Windows.ApplicationModel.Contacts; using Windows.Storage; using Windows.Storage.Streams; -using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Imaging; -using Windows.UI.Xaml.Navigation; - namespace Dialer.UI.Controls { @@ -32,6 +19,8 @@ public sealed partial class ContactControl : UserControl private List> additionalPhoneContacts; private ObservableCollection additionalPhoneContactPresenters; + public Contact AssociatedContact; + public string ContactName { get => ContactNameTB.Text; @@ -89,5 +78,11 @@ private void MainCallButton_Tapped(object sender, TappedRoutedEventArgs e) } catch { } } + + private async void FlyoutDeleteContact_Click(object sender, RoutedEventArgs e) + { + await ContactSystem.DeleteContact(AssociatedContact); + ContactsPage.CurrentInstance.RemoveContactControl(this); + } } } diff --git a/Dialer/UI/Pages/ContactsPage.xaml b/Dialer/UI/Pages/ContactsPage.xaml index 1b897aa..034ef47 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml +++ b/Dialer/UI/Pages/ContactsPage.xaml @@ -12,7 +12,7 @@ - + diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index b177d75..63cfcc0 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -1,32 +1,29 @@ -using Dialer.UI.Controls; +using Dialer.Systems; +using Dialer.UI.Controls; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using System.Threading.Tasks; using System.Timers; -using Windows.ApplicationModel.Contacts; -using Windows.Storage.Streams; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; namespace Dialer.UI.Pages { - public sealed partial class ContactsPage : Page { - - ObservableCollection ContactControls; + private Timer _hideHintTimer; + private ObservableCollection _contactControls; public static ContactsPage CurrentInstance; - private Timer HideHintTimer; - public ContactsPage() { InitializeComponent(); - ContactControls = new ObservableCollection(); + _contactControls = new ObservableCollection(); CurrentInstance = this; } @@ -35,43 +32,27 @@ protected async override void OnNavigatedTo(NavigationEventArgs e) base.OnNavigatedTo(e); SizeChanged += ContactsPage_SizeChanged; - //TODO: Improve loading by showing a percentage or number of contacts loaded? - //await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { - // LoadingGridProgressCount.Text = ""; - //}); - - LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; - - if(ContactControls.Count == 0) + await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { - ContactStore contactStore = await ContactManager.RequestStoreAsync(); - IReadOnlyList contacts = await contactStore.FindContactsAsync(); + LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; + }); - Debug.WriteLine("Found " + contacts.Count + " contacts"); + Aaa(); //Todo: This needs to be run in background, currently it blocks the UI (??) + } - foreach (Contact contact in contacts) - { - //TODO: Improve loading by showing a percentage or number of contacts loaded? - //await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { - // LoadingGridProgressCount.Text = "(" + ContactControls.Count + " out of " + contacts.Count + ")"; - //}); - ContactControl cc = new ContactControl(); - cc.ContactName = contact.DisplayName; - if (contact.Phones.Count == 0) continue; - cc.ContactMainPhone = contact.Phones[0].Number; - List> additionalPhones = new List>(); - foreach (ContactPhone contactPhone in contact.Phones) - { - additionalPhones.Add(new Tuple(contactPhone.Kind.ToString(), contactPhone.Number)); - } - cc.AdditionalContactPhones = additionalPhones; - if(contact.SmallDisplayPicture != null) - //TODO: Fix wrong cast - cc.ContactPicture = contact.SmallDisplayPicture; - ContactControls.Add(cc); - } + private Task Aaa() + { + if (ContactSystem.ContactControls == null) + { + ContactSystem.ContactsLoaded += (object sender, EventArgs e) => LoadDataCompleted(); } + else LoadDataCompleted(); + return Task.CompletedTask; + } + private void LoadDataCompleted() + { + _contactControls = ContactSystem.ContactControls; LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } @@ -82,18 +63,16 @@ private void ContactsPage_SizeChanged(object sender, Windows.UI.Xaml.SizeChanged public void NavigateToLetter(string letter) { - IEnumerable ContactsWithLetter = from contact in ContactControls where contact.ContactName.ToUpper().StartsWith(letter) select contact; - ScrollLetterHint.Text = letter; if(ScrollLetterGrid.Visibility == Windows.UI.Xaml.Visibility.Collapsed) ScrollLetterHintShow.Begin(); ScrollLetterGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; - if (HideHintTimer != null) + if (_hideHintTimer != null) { - HideHintTimer.Stop(); - HideHintTimer.Dispose(); + _hideHintTimer.Stop(); + _hideHintTimer.Dispose(); } - HideHintTimer = new Timer(1000); - HideHintTimer.Elapsed += async (object sender, ElapsedEventArgs e) => + _hideHintTimer = new Timer(1000); + _hideHintTimer.Elapsed += async (object sender, ElapsedEventArgs e) => { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { @@ -107,14 +86,23 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => }; }); }; - HideHintTimer.Start(); + + IEnumerable ContactsWithLetter = from contact in _contactControls where contact.ContactName.ToUpper().StartsWith(letter) select contact; //TODO: Fix for missing letter -> move to previous/next letter try { ContactsWithLetter.First().StartBringIntoView(); } catch { } + + _hideHintTimer.Start(); + Debug.WriteLine("Got request to navigate to letter " + letter); } + + public void RemoveContactControl(ContactControl cc) + { + _contactControls.Remove(cc); + } } } From 736081c6c07270d808b6951396343a303d748f74 Mon Sep 17 00:00:00 2001 From: Simone Franco Date: Thu, 5 Aug 2021 18:24:34 +0200 Subject: [PATCH 12/12] Somewhat ready for new release --- Dialer/App.xaml.cs | 2 +- Dialer/Systems/ContactSystem.cs | 20 +++++++----- .../AdditionalPhoneContactPresenter.xaml | 6 ---- Dialer/UI/Controls/ContactControl.xaml | 8 ++--- Dialer/UI/Controls/ContactControl.xaml.cs | 9 ++++++ Dialer/UI/Pages/ContactsPage.xaml.cs | 31 +++++++++++-------- 6 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Dialer/App.xaml.cs b/Dialer/App.xaml.cs index bef1382..bfaeeb4 100644 --- a/Dialer/App.xaml.cs +++ b/Dialer/App.xaml.cs @@ -71,7 +71,7 @@ private async Task InitializateSystems() ResourceLoader = ResourceLoader.GetForViewIndependentUse(); NotificationSystem.Initializate(); await CallSystem.Initializate(); - await ContactSystem.LoadContacts(); + ContactSystem.LoadContacts(); } protected override void OnActivated(IActivatedEventArgs args) diff --git a/Dialer/Systems/ContactSystem.cs b/Dialer/Systems/ContactSystem.cs index 0bbf7a4..4d50517 100644 --- a/Dialer/Systems/ContactSystem.cs +++ b/Dialer/Systems/ContactSystem.cs @@ -38,19 +38,19 @@ public static ObservableCollection ContactControls } } - public static async Task LoadContacts() + public static async void LoadContacts() { if(_contacts == null && ContactsLoading == false) { ContactsLoading = true; _contactStore = await ContactManager.RequestStoreAsync(); - _contacts = new ObservableCollection(await _contactStore.FindContactsAsync()); + ObservableCollection t_contacts = new ObservableCollection(await _contactStore.FindContactsAsync()); - Debug.WriteLine("Found " + _contacts.Count + " contacts"); + Debug.WriteLine("Found " + t_contacts.Count + " contacts"); - _contactControls = new ObservableCollection(); + ObservableCollection t_contactControls = new ObservableCollection(); - foreach (Contact contact in _contacts) + foreach (Contact contact in t_contacts) { ContactControl cc = new ContactControl(); cc.AssociatedContact = contact; @@ -66,11 +66,15 @@ public static async Task LoadContacts() if (contact.SmallDisplayPicture != null) //TODO: Fix wrong cast cc.ContactPicture = contact.SmallDisplayPicture; - _contactControls.Add(cc); + t_contactControls.Add(cc); } - } + _contacts = t_contacts; + _contactControls = t_contactControls; + + ContactsLoading = false; - ContactsLoaded?.Invoke(null, EventArgs.Empty); + ContactsLoaded?.Invoke(null, EventArgs.Empty); + } } public static async Task DeleteContact(Contact contact) diff --git a/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml index c3c7278..7dcbcf7 100644 --- a/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml +++ b/Dialer/UI/Controls/AdditionalPhoneContactPresenter.xaml @@ -10,12 +10,6 @@ d:DesignWidth="400"> - - - - - - diff --git a/Dialer/UI/Controls/ContactControl.xaml b/Dialer/UI/Controls/ContactControl.xaml index 7278034..7cffae2 100644 --- a/Dialer/UI/Controls/ContactControl.xaml +++ b/Dialer/UI/Controls/ContactControl.xaml @@ -15,12 +15,12 @@ - + - - + + - + diff --git a/Dialer/UI/Controls/ContactControl.xaml.cs b/Dialer/UI/Controls/ContactControl.xaml.cs index 50e1619..e44d52f 100644 --- a/Dialer/UI/Controls/ContactControl.xaml.cs +++ b/Dialer/UI/Controls/ContactControl.xaml.cs @@ -84,5 +84,14 @@ private async void FlyoutDeleteContact_Click(object sender, RoutedEventArgs e) await ContactSystem.DeleteContact(AssociatedContact); ContactsPage.CurrentInstance.RemoveContactControl(this); } + + private void FlyoutCallContact_Click(object sender, RoutedEventArgs e) + { + try + { + App.Current.CallSystem.DefaultLine?.DialWithOptions(new PhoneDialOptions() { Number = ContactMainPhone.ToString() }); + } + catch { } + } } } diff --git a/Dialer/UI/Pages/ContactsPage.xaml.cs b/Dialer/UI/Pages/ContactsPage.xaml.cs index 63cfcc0..cae28e9 100644 --- a/Dialer/UI/Pages/ContactsPage.xaml.cs +++ b/Dialer/UI/Pages/ContactsPage.xaml.cs @@ -27,33 +27,37 @@ public ContactsPage() CurrentInstance = this; } - protected async override void OnNavigatedTo(NavigationEventArgs e) + protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); SizeChanged += ContactsPage_SizeChanged; - await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => - { - LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; - }); + LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; - Aaa(); //Todo: This needs to be run in background, currently it blocks the UI (??) + Task.Run(() => + { + Aaa(); + }); //TODO: This still hangs the UI in some cases 🥲 } - private Task Aaa() + private void Aaa() { if (ContactSystem.ContactControls == null) { ContactSystem.ContactsLoaded += (object sender, EventArgs e) => LoadDataCompleted(); } else LoadDataCompleted(); - return Task.CompletedTask; } - private void LoadDataCompleted() + private async void LoadDataCompleted() { - _contactControls = ContactSystem.ContactControls; - LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; + await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => + { + ContactsItemsControl.ItemsSource = null; + _contactControls = ContactSystem.ContactControls; + ContactsItemsControl.ItemsSource = _contactControls; + LoadingGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed; + }); } private void ContactsPage_SizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e) @@ -89,11 +93,12 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => IEnumerable ContactsWithLetter = from contact in _contactControls where contact.ContactName.ToUpper().StartsWith(letter) select contact; - //TODO: Fix for missing letter -> move to previous/next letter try { ContactsWithLetter.First().StartBringIntoView(); - } catch { } + } catch { + //TODO: Fix for missing letter -> move to previous/next letter + } _hideHintTimer.Start();