Commit f3588db8 authored by Sylvain Berfini's avatar Sylvain Berfini

Notification is displayed when a chat message arrives and the user is not on the chat view

parent 06267e85
<UserControl x:Class="Linphone.Controls.MessageReceivedNotification"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="800" d:DesignWidth="480">
<Grid x:Name="ContentPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Border BorderBrush="White" BorderThickness="5" Margin="0,10,0,0" VerticalAlignment="Top" Grid.Row="0">
<StackPanel Background="{StaticResource PhoneAccentBrush}">
<TextBlock x:Name="Sender" Text="Sylvain Berfini" Margin="22,20,22,0" Style="{StaticResource PhoneTextTitle2Style}"/>
<TextBlock x:Name="Message" Text="Hello world!" Margin="22,20,22,0" Style="{StaticResource PhoneTextTitle3Style}"/>
<StackPanel Margin="12,20,12,0" Orientation="Horizontal">
<Button x:Name="Close" Click="Close_Click" Content="{Binding Path=LocalizedResources.Close, Source={StaticResource LocalizedStrings}}" Width="180" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
<Button x:Name="Show" Click="Show_Click" Margin="86,0,0,0" Content="{Binding Path=LocalizedResources.Show, Source={StaticResource LocalizedStrings}}" Width="180" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
</StackPanel>
</StackPanel>
</Border>
<StackPanel Background="{StaticResource PhoneChromeBrush}" Height="614" Opacity="0.5" Grid.Row="1"></StackPanel>
</Grid>
</UserControl>
\ No newline at end of file
using System;
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.Shell;
using Linphone.Model;
using System.Windows.Controls.Primitives;
namespace Linphone.Controls
{
/// <summary>
/// Custom message box to dispaly incoming messages
/// </summary>
public partial class MessageReceivedNotification : UserControl
{
private Popup _popup;
private ChatMessage _message;
/// <summary>
/// Getter for Popup.IsOpen
/// </summary>
public bool IsVisible
{
get
{
return _popup.IsOpen;
}
}
/// <summary>
/// Public constructor
/// </summary>
public MessageReceivedNotification(Popup popup, ChatMessage message)
{
InitializeComponent();
_popup = popup;
_message = message;
Message.Text = message.Message;
Sender.Text = message.Contact;
BaseModel.CurrentPage.ApplicationBar.IsVisible = false;
}
/// <summary>
/// Closes the popup.
/// </summary>
public void Hide()
{
BaseModel.CurrentPage.ApplicationBar.IsVisible = true;
_popup.IsOpen = false;
}
private void Close_Click(object sender, RoutedEventArgs e)
{
Hide();
}
/// <summary>
/// Delegate for show button clicked event.
/// </summary>
public delegate void ShowClickedEventHandler(object sender, ChatMessage message);
/// <summary>
/// Handler for show button clicked event.
/// </summary>
public event ShowClickedEventHandler ShowClicked;
private void Show_Click(object sender, RoutedEventArgs e)
{
Hide();
if (ShowClicked != null)
ShowClicked(this, _message);
}
}
}
......@@ -103,6 +103,9 @@
<Compile Include="Controls\ContactAction.xaml.cs">
<DependentUpon>ContactAction.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\MessageReceivedNotification.xaml.cs">
<DependentUpon>MessageReceivedNotification.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\OutgoingChatBubble.xaml.cs">
<DependentUpon>OutgoingChatBubble.xaml</DependentUpon>
</Compile>
......@@ -294,6 +297,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\MessageReceivedNotification.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\OutgoingChatBubble.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......
......@@ -30,6 +30,9 @@ namespace Linphone
void PauseStateChanged(LinphoneCall call, bool isCallPaused);
}
/// <summary>
/// Listener called when a call is updated by the correspondent.
/// </summary>
public interface CallUpdatedByRemoteListener
{
/// <summary>
......@@ -73,6 +76,11 @@ namespace Linphone
/// </summary>
public BasePage Page { get; set; }
/// <summary>
/// Page currently displayed.
/// </summary>
public static BasePage CurrentPage { get; set; }
/// <summary>
/// Dispatcher used to run tasks on the UI thread.
/// </summary>
......@@ -142,6 +150,7 @@ namespace Linphone
public virtual void OnNavigatedTo(NavigationEventArgs nea)
{
LinphoneManager.Instance.CallListener = this;
CurrentPage = this.Page;
UIDispatcher = this.Page.Dispatcher;
}
......
using Linphone.Agents;
using Linphone.Controls;
using Linphone.Core;
using Linphone.Core.OutOfProcess;
using Linphone.Resources;
using Linphone.Views;
using Microsoft.Phone.Net.NetworkInformation;
using Microsoft.Phone.Networking.Voip;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
......@@ -13,6 +13,8 @@ using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Xml.Linq;
using Windows.Phone.Media.Capture;
using Windows.Phone.Media.Devices;
......@@ -760,6 +762,11 @@ namespace Linphone.Model
/// </summary>
public MessageReceivedListener MessageListener { get; set; }
/// <summary>
/// Custom message box to display incoming messages when not in chat view
/// </summary>
public MessageReceivedNotification MessageReceivedNotification { get; set; }
/// <summary>
/// Callback for LinphoneCoreListener
/// </summary>
......@@ -768,7 +775,7 @@ namespace Linphone.Model
string sipAddress = message.GetFrom().AsStringUriOnly().Replace("sip:", "");
Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.GetText());
if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
{
MessageListener.MessageReceived(message);
}
......@@ -785,6 +792,28 @@ namespace Linphone.Model
ChatMessage msg = new ChatMessage { Message = message.GetText(), ImageURL = url, MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = (date.Ticks / TimeSpan.TicksPerSecond) };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
//Displays the message as a popup
BaseModel.UIDispatcher.BeginInvoke(() =>
{
if (MessageReceivedNotification != null)
{
MessageReceivedNotification.Hide();
}
Popup messageNotif = new Popup();
messageNotif.Width = Application.Current.Host.Content.ActualWidth;
messageNotif.Height = Application.Current.Host.Content.ActualHeight;
messageNotif.VerticalOffset = 25;
MessageReceivedNotification = new MessageReceivedNotification(messageNotif, msg);
MessageReceivedNotification.ShowClicked += (sender, chatMessage) =>
{
BaseModel.CurrentPage.NavigationService.Navigate(new Uri("/Views/Chat.xaml?sip=" + chatMessage.Contact, UriKind.RelativeOrAbsolute));
};
messageNotif.Child = MessageReceivedNotification;
messageNotif.IsOpen = true;
});
}
}
#endregion
......
......@@ -210,6 +210,15 @@ namespace Linphone.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Close.
/// </summary>
public static string Close {
get {
return ResourceManager.GetString("Close", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Codecs.
/// </summary>
......@@ -687,6 +696,15 @@ namespace Linphone.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Show.
/// </summary>
public static string Show {
get {
return ResourceManager.GetString("Show", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Show.
/// </summary>
......
......@@ -437,4 +437,10 @@ http://www.linphone.org/m/help
<data name="Uploading" xml:space="preserve">
<value>Uploading...</value>
</data>
<data name="Close" xml:space="preserve">
<value>Close</value>
</data>
<data name="Show" xml:space="preserve">
<value>Show</value>
</data>
</root>
\ No newline at end of file
using Linphone.Controls;
using Linphone.Model;
using Microsoft.Phone.Controls;
using System;
using System.Windows;
using System.Windows.Navigation;
......@@ -66,6 +68,20 @@ namespace Linphone
StatusBar = null;
this.ViewModel.OnNavigatedFrom(nee);
}
}
/// <summary>
/// Can cancel back action if custom popup is open to close it
/// </summary>
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (LinphoneManager.Instance.MessageReceivedNotification != null && LinphoneManager.Instance.MessageReceivedNotification.IsVisible)
{
LinphoneManager.Instance.MessageReceivedNotification.Hide();
e.Cancel = true;
}
base.OnBackKeyPress(e);
}
}
}
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