Commit 91800e2d authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added action to contact view + handling email addresses

parent 786fe244
No preview for this file type
......@@ -26,13 +26,14 @@
<TextBlock
x:Name="phone"
FontSize="35"
FontSize="25"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Foreground="{StaticResource PhoneAccentBrush}"/>
</StackPanel>
<Button
x:Name="button"
Grid.Column="1"
BorderThickness="0"
HorizontalAlignment="Right"
......
......@@ -41,20 +41,30 @@ namespace Linphone.Controls
}
}
private String _phone;
public String Phone
private String _numberOrAddress;
public String NumberOrAddress
{
get
{
return _phone;
return _numberOrAddress;
}
set
{
_phone = value;
_numberOrAddress = value;
phone.Text = value;
}
}
public RoutedEventHandler Click
{
set
{
button.Click += value;
button.Tag = NumberOrAddress;
}
get { return null; }
}
public ContactAction()
{
InitializeComponent();
......
......@@ -65,20 +65,36 @@ namespace Linphone.Model
return _contacts;
}
/// <summary>
/// Searches if there is a contact for whom the phone number of the email address is stored
/// </summary>
/// <param name="numberOrAddress"></param>
public void FindContact(String numberOrAddress)
{
if (numberOrAddress.Contains('@'))
{
FindContactByEmail(numberOrAddress);
}
else
{
FindContactByNumber(numberOrAddress);
}
}
/// <summary>
/// Searches if a there is a contact for whom the phone number is stored
/// </summary>
/// <param name="number">phone number to use to filter the contacts</param>
public void FindContactByNumber(String number)
private void FindContactByNumber(String number)
{
Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
tempNumberForContactLookup = number;
contacts.SearchCompleted += contact_SearchCompleted;
contacts.SearchCompleted += contact_PhoneSearchCompleted;
contacts.SearchAsync(tempNumberForContactLookup, FilterKind.PhoneNumber, "Search by phone number");
}
private void contact_SearchCompleted(object sender, Microsoft.Phone.UserData.ContactsSearchEventArgs e)
private void contact_PhoneSearchCompleted(object sender, Microsoft.Phone.UserData.ContactsSearchEventArgs e)
{
Contact result = e.Results.FirstOrDefault();
if (result != null)
......@@ -96,5 +112,35 @@ namespace Linphone.Model
ContactFound(this, new ContactFoundEventArgs(result, tempNumberForContactLookup, label));
}
}
/// <summary>
/// Searches if a there is a contact for whom the phone number is stored
/// </summary>
/// <param name="number">phone number to use to filter the contacts</param>
private void FindContactByEmail(String email)
{
Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
tempNumberForContactLookup = email;
contacts.SearchCompleted += contact_EmailSearchCompleted;
contacts.SearchAsync(tempNumberForContactLookup, FilterKind.EmailAddress, "Search by email address");
}
private void contact_EmailSearchCompleted(object sender, Microsoft.Phone.UserData.ContactsSearchEventArgs e)
{
Contact result = e.Results.FirstOrDefault();
if (result != null)
{
String label = null;
foreach (ContactEmailAddress email in result.EmailAddresses)
{
if (email.EmailAddress.Equals(tempNumberForContactLookup))
{
label = email.Kind.ToString();
}
}
ContactFound(this, new ContactFoundEventArgs(result, tempNumberForContactLookup, label));
}
}
}
}
......@@ -23,7 +23,7 @@
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<!--<TextBlock Text="" Style="{StaticResource PhoneTextNormalStyle}"/>-->
<TextBlock x:Name="contactName" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
<TextBlock x:Name="contactName" TextWrapping="Wrap" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
......
......@@ -38,6 +38,7 @@ namespace Linphone.Views
contactPicture.Height = 150;
contactPicture.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
contactPicture.Source = PictureDecoder.DecodeJpeg(imgStream);
contactPicture.Margin = new Thickness(0,0,0,15);
actions.Children.Add(contactPicture);
}
......@@ -46,9 +47,31 @@ namespace Linphone.Views
ContactAction entry = new ContactAction();
entry.Action = "/Assets/AppBar/feature.phone.png";
entry.Label = phone.Kind.ToString();
entry.Phone = phone.PhoneNumber;
entry.NumberOrAddress = phone.PhoneNumber;
entry.Click += action_Click_1;
actions.Children.Add(entry);
}
foreach (ContactEmailAddress email in contact.EmailAddresses)
{
ContactAction entry = new ContactAction();
entry.Action = "/Assets/AppBar/feature.phone.png";
entry.Label = email.Kind.ToString();
entry.NumberOrAddress = email.EmailAddress;
entry.Click += action_Click_1;
actions.Children.Add(entry);
}
}
private void SetAddressGoToDialerAndCall(String address)
{
NavigationService.Navigate(new Uri("/Views/Dialer.xaml?sip=" + address, UriKind.RelativeOrAbsolute));
}
private void action_Click_1(object sender, EventArgs e)
{
String numberOrAddress = (sender as Button).Tag.ToString();
SetAddressGoToDialerAndCall(numberOrAddress);
}
}
}
\ No newline at end of file
......@@ -33,7 +33,8 @@ namespace Linphone
{
LinphoneManager.Instance.EnableDebug(SettingsManager.isDebugEnabled);
if (NavigationContext.QueryString.ContainsKey("sip"))
// Check for the navigation direction to avoid going to incall view when coming back from incall view
if (NavigationContext.QueryString.ContainsKey("sip") && e.NavigationMode != NavigationMode.Back)
{
String sipAddressToCall = NavigationContext.QueryString["sip"];
sipAddress.Text = sipAddressToCall;
......
......@@ -31,7 +31,7 @@ namespace Linphone.Views
ContactManager cm = ContactManager.Instance;
cm.ContactFound += cm_ContactFound;
cm.FindContactByNumber(calledNumber);
cm.FindContact(calledNumber);
}
}
......
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