Commit a6fa5f81 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Search for contact in incall view to display as many information as possible

parent b88562b1
No preview for this file type
using Microsoft.Phone.UserData; using Microsoft.Phone.UserData;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Linphone.Model namespace Linphone.Model
{ {
public class ContactFoundEventArgs : EventArgs
{
public Contact ContactFound;
public String PhoneNumber;
public String PhoneLabel;
public ContactFoundEventArgs(Contact contact, String number, String label = null)
{
ContactFound = contact;
PhoneNumber = number;
PhoneLabel = label;
}
}
public class ContactManager public class ContactManager
{ {
private static ContactManager singleton; private static ContactManager singleton;
...@@ -22,6 +36,10 @@ namespace Linphone.Model ...@@ -22,6 +36,10 @@ namespace Linphone.Model
} }
private List<AlphaKeyGroup<Contact>> _contacts; private List<AlphaKeyGroup<Contact>> _contacts;
private String tempNumberForContactLookup;
public delegate void ContactFoundEventHandler(object sender, ContactFoundEventArgs e);
public event ContactFoundEventHandler ContactFound;
public ContactManager() public ContactManager()
{ {
...@@ -41,5 +59,33 @@ namespace Linphone.Model ...@@ -41,5 +59,33 @@ namespace Linphone.Model
{ {
return _contacts; return _contacts;
} }
public void FindContactByNumber(String number)
{
Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
tempNumberForContactLookup = number;
contacts.SearchCompleted += contact_SearchCompleted;
contacts.SearchAsync(tempNumberForContactLookup, FilterKind.PhoneNumber, "Search by phone number");
}
private void contact_SearchCompleted(object sender, Microsoft.Phone.UserData.ContactsSearchEventArgs e)
{
Contact result = e.Results.FirstOrDefault();
if (result != null)
{
String label = null;
foreach (ContactPhoneNumber phone in result.PhoneNumbers)
{
// We know this contact has this phone number stored.
// That's why we strip the phone number from the 3 first characters (maybe international prefix): to facilitate the label search
if (phone.PhoneNumber.EndsWith(tempNumberForContactLookup.Substring(3)))
{
label = phone.Kind.ToString();
}
}
ContactFound(this, new ContactFoundEventArgs(result, tempNumberForContactLookup, label));
}
}
} }
} }
...@@ -52,14 +52,12 @@ ...@@ -52,14 +52,12 @@
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
x:Name="Contact" x:Name="Contact"
Text="Ghislain MARY"
Margin="12,0,12,0" Margin="12,0,12,0"
FontSize="60"/> FontSize="60"/>
<TextBlock <TextBlock
Grid.Row="2" Grid.Row="2"
x:Name="Number" x:Name="Number"
Text="Mobile : 06 28 21 43 51"
Margin="12,0,12,0" Margin="12,0,12,0"
FontSize="25"/> FontSize="25"/>
......
using System; using Linphone.Model;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls; using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell; using System;
using System.Windows.Media; using System.Windows;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace Linphone.Views namespace Linphone.Views
{ {
...@@ -30,7 +25,26 @@ namespace Linphone.Views ...@@ -30,7 +25,26 @@ namespace Linphone.Views
{ {
if (NavigationContext.QueryString.ContainsKey("sip")) if (NavigationContext.QueryString.ContainsKey("sip"))
{ {
String calledNumber = NavigationContext.QueryString["sip"];
// While we dunno if the number matches a contact one, we consider it won't and we display the phone number as username
Contact.Text = calledNumber;
ContactManager cm = ContactManager.Instance;
cm.ContactFound += cm_ContactFound;
cm.FindContactByNumber(calledNumber);
}
}
private void cm_ContactFound(object sender, ContactFoundEventArgs e)
{
Contact.Text = e.ContactFound.DisplayName;
if (e.PhoneLabel != null)
{
Number.Text = e.PhoneLabel + " : " + e.PhoneNumber;
}
else
{
Number.Text = e.PhoneNumber;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment