Commit d2c6b627 authored by Sylvain Berfini's avatar Sylvain Berfini

Added setting for message vibration + fixes for received messages

parent 1d1d86c8
......@@ -792,8 +792,13 @@ namespace Linphone.Model
Logger.Msg("[LinphoneManager] Message received from " + sipAddress + ": " + message.GetText());
//Vibrate
VibrationDevice vibrator = VibrationDevice.GetDefault();
vibrator.Vibrate(TimeSpan.FromSeconds(1));
ChatSettingsManager settings = new ChatSettingsManager();
settings.Load();
if ((bool)settings.VibrateOnIncomingMessage)
{
VibrationDevice vibrator = VibrationDevice.GetDefault();
vibrator.Vibrate(TimeSpan.FromSeconds(1));
}
if (MessageListener != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation() != null && MessageListener.GetSipAddressAssociatedWithDisplayConversation().Equals(sipAddress))
{
......@@ -801,26 +806,23 @@ namespace Linphone.Model
}
else
{
DateTime date = new DateTime();
date = date.AddYears(1969); //Timestamp is calculated from 01/01/1970, and DateTime is initialized to 01/01/0001.
date = date.AddSeconds(message.GetTime());
date = date.Add(TimeZoneInfo.Local.GetUtcOffset(date));
long timestamp = (date.Ticks / TimeSpan.TicksPerSecond);
//TODO: Temp hack to remove
string url = message.GetExternalBodyUrl();
url = url.Replace("\"", "");
BaseModel.UIDispatcher.BeginInvoke(() =>
{
DateTime date = new DateTime();
date = date.AddYears(1969); //Timestamp is calculated from 01/01/1970, and DateTime is initialized to 01/01/0001.
date = date.AddSeconds(message.GetTime());
date = date.Add(TimeZoneInfo.Local.GetUtcOffset(date));
long timestamp = (date.Ticks / TimeSpan.TicksPerSecond);
ChatMessage msg = new ChatMessage { Message = message.GetText(), ImageURL = url, MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = timestamp };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges();
//TODO: Temp hack to remove
string url = message.GetExternalBodyUrl();
url = url.Replace("\"", "");
//Update tile
UpdateLiveTile();
ChatMessage msg = new ChatMessage { Message = message.GetText(), ImageURL = url, MarkedAsRead = false, IsIncoming = true, LocalContact = sipAddress, RemoteContact = "", Timestamp = timestamp };
DatabaseManager.Instance.Messages.InsertOnSubmit(msg);
DatabaseManager.Instance.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
//Displays the message as a popup
BaseModel.UIDispatcher.BeginInvoke(() =>
{
//Displays the message as a popup
if (MessageReceivedNotification != null)
{
MessageReceivedNotification.Hide();
......@@ -838,6 +840,9 @@ namespace Linphone.Model
};
messageNotif.Child = MessageReceivedNotification;
messageNotif.IsOpen = true;
//Update tile
UpdateLiveTile();
});
}
}
......
......@@ -4,6 +4,7 @@ using Microsoft.Phone.Net.NetworkInformation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.IsolatedStorage;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
......@@ -1197,4 +1198,67 @@ namespace Linphone.Model
}
#endregion
}
/// <summary>
/// Utility class to handle chat settings.
/// </summary>
public class ChatSettingsManager : SettingsManager, ISettingsManager
{
IsolatedStorageSettings _settings;
#region Constants settings names
private const string VibrateOnIncomingMessageKeyName = "VibrateOnIncomingMessage";
#endregion
#region Implementation of the ISettingsManager interface
/// <summary>
/// Loads the call settings.
/// </summary>
public void Load()
{
_settings = IsolatedStorageSettings.ApplicationSettings;
string value;
if (_settings.Contains(VibrateOnIncomingMessageKeyName))
value = ((bool)_settings[VibrateOnIncomingMessageKeyName]).ToString();
else
value = true.ToString();
dict[VibrateOnIncomingMessageKeyName] = value;
}
/// <summary>
/// Saves the call settings.
/// </summary>
public void Save()
{
if (ValueChanged(VibrateOnIncomingMessageKeyName))
{
bool value = Convert.ToBoolean(GetNew(VibrateOnIncomingMessageKeyName));
if (_settings.Contains(VibrateOnIncomingMessageKeyName))
_settings[VibrateOnIncomingMessageKeyName] = value;
else
_settings.Add(VibrateOnIncomingMessageKeyName, value);
_settings.Save();
}
}
#endregion
#region Accessors
/// <summary>
/// DTMFs using RFC2833 setting (bool).
/// </summary>
public bool? VibrateOnIncomingMessage
{
get
{
return Convert.ToBoolean(Get(VibrateOnIncomingMessageKeyName));
}
set
{
Set(VibrateOnIncomingMessageKeyName, value.ToString());
}
}
#endregion
}
}
......@@ -1047,6 +1047,15 @@ namespace Linphone.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Vibrate on incoming message.
/// </summary>
public static string VibratorSetting {
get {
return ResourceManager.GetString("VibratorSetting", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to video.
/// </summary>
......
......@@ -470,4 +470,7 @@ http://www.linphone.org/m/help
<data name="DisplayName" xml:space="preserve">
<value>Display name</value>
</data>
<data name="VibratorSetting" xml:space="preserve">
<value>Vibrate on incoming message</value>
</data>
</root>
\ No newline at end of file
......@@ -69,7 +69,7 @@
</ScrollViewer>
</phone:PivotItem>
<!--Pivot item two-->
<!--Pivot item Call-->
<phone:PivotItem Header="{Binding Path=LocalizedResources.CallMenu, Source={StaticResource LocalizedStrings}}">
<StackPanel Orientation="Vertical">
<toolkit:ToggleSwitch
......@@ -82,6 +82,16 @@
</toolkit:ToggleSwitch>
</StackPanel>
</phone:PivotItem>
<!--Pivot item Chat-->
<phone:PivotItem Header="{Binding Path=LocalizedResources.ChatMenu, Source={StaticResource LocalizedStrings}}">
<StackPanel Orientation="Vertical">
<toolkit:ToggleSwitch
x:Name="vibrator"
Header="{Binding Path=LocalizedResources.VibratorSetting, Source={StaticResource LocalizedStrings}}">
</toolkit:ToggleSwitch>
</StackPanel>
</phone:PivotItem>
</phone:Pivot>
</Grid>
......
......@@ -15,6 +15,7 @@ namespace Linphone.Views
{
private CallSettingsManager _callSettings = new CallSettingsManager();
private NetworkSettingsManager _networkSettings = new NetworkSettingsManager();
private ChatSettingsManager _chatSettings = new ChatSettingsManager();
/// <summary>
/// Public constructor.
......@@ -26,8 +27,10 @@ namespace Linphone.Views
_callSettings.Load();
_networkSettings.Load();
_chatSettings.Load();
rfc2833.IsChecked = _callSettings.SendDTFMsRFC2833;
sipInfo.IsChecked = _callSettings.SendDTFMsSIPInfo;
vibrator.IsChecked = _chatSettings.VibrateOnIncomingMessage;
List<string> tunnelModes = new List<string>
{
......@@ -63,12 +66,16 @@ namespace Linphone.Views
_callSettings.SendDTFMsRFC2833 = rfc2833.IsChecked;
_callSettings.SendDTFMsSIPInfo = sipInfo.IsChecked;
_callSettings.Save();
_networkSettings.TunnelMode = tunnelMode.SelectedItem.ToString();
_networkSettings.TunnelServer = tunnelServer.Text;
_networkSettings.TunnelPort = tunnelPort.Text;
_networkSettings.Transport = Transport.SelectedItem.ToString();
_networkSettings.Save();
_chatSettings.VibrateOnIncomingMessage = vibrator.IsChecked;
_chatSettings.Save();
NavigationService.GoBack();
}
......
......@@ -120,6 +120,8 @@ namespace Linphone.Views
NewChat.Visibility = Visibility.Visible;
NewChatSipAddress.Focus();
}
scrollToBottom();
}
private void MessageBox_TextChanged(object sender, string text)
......
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