Commit 42f1a2e6 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fix timer crash in incall view + bis function

parent d5a61343
......@@ -89,8 +89,14 @@ namespace Linphone
Platform::String^ GetRemoteUserAgent();
Platform::String^ GetRemoteContact();
/// <summary>
/// Uses the CallContext object (native VoipPhoneCall) to get the DateTimeOffset at which the call started
/// </summary>
Platform::Object^ GetCallStartTimeFromContext();
/// <summary>
/// Gets the CallContext object (native VoipPhoneCall)
/// </summary>
property Platform::Object^ CallContext
{
Platform::Object^ get();
......
......@@ -250,7 +250,6 @@ namespace Linphone.Model
if ((server.LinphoneCoreFactory != null) && (server.LinphoneCore != null))
{
// Reconnect the listeners when coming back from background mode
Debug.WriteLine("[LinphoneManager] LinphoneCore alread created, skipping");
Logger.Msg("[LinphoneManager] LinphoneCore alread created, skipping");
server.LinphoneCore.CoreListener = this;
......@@ -258,6 +257,7 @@ namespace Linphone.Model
return;
}
Logger.Msg("[LinphoneManager] Creating LinphoneCore");
InstallConfig();
server.LinphoneCoreFactory.CreateLinphoneCore(this, GetConfigPath(), "Assets/linphonerc-factory");
ConfigureLogger();
......@@ -303,6 +303,26 @@ namespace Linphone.Model
#region CallLogs
private List<CallLogs> _history;
/// <summary>
/// Gets the latest called address or number
/// </summary>
/// <returns>null if there isn't any</returns>
public string GetLastCalledNumber()
{
foreach (LinphoneCallLog log in LinphoneManager.Instance.LinphoneCore.GetCallLogs())
{
string to = log.GetTo().GetDisplayName();
if (to.Length == 0)
to = log.GetTo().AsStringUriOnly();
if (log.GetDirection() == CallDirection.Outgoing)
{
return to;
}
}
return null;
}
/// <summary>
/// Get the calls' history.
/// </summary>
......@@ -551,6 +571,7 @@ namespace Linphone.Model
}
else if (state == LinphoneCallState.Released)
{
Logger.Msg("[LinphoneManager] Call released");
BaseModel.UIDispatcher.BeginInvoke(() =>
{
TileManager.Instance.UpdateTileWithMissedCalls(LinphoneCore.GetMissedCallsCount());
......
......@@ -54,6 +54,11 @@ namespace Linphone
{
LinphoneManager.Instance.NewOutgoingCall(addressBox.Text);
}
else
{
string lastDialedNumber = LinphoneManager.Instance.GetLastCalledNumber();
addressBox.Text = lastDialedNumber == null ? "" : lastDialedNumber;
}
}
private void Numpad_Click_1(object sender, RoutedEventArgs e)
......
......@@ -26,6 +26,7 @@ namespace Linphone.Views
private const string pauseOff = "/Assets/AppBar/pause.png";
private Timer timer;
private DateTimeOffset startTime;
/// <summary>
/// Public constructor.
......@@ -106,6 +107,10 @@ namespace Linphone.Views
private void hangUp_Click(object sender, RoutedEventArgs e)
{
if (timer != null)
{
timer.Dispose();
}
LinphoneManager.Instance.EndCurrentCall();
}
......@@ -165,16 +170,26 @@ namespace Linphone.Views
private void timerTick(Object state)
{
LinphoneCall call = LinphoneManager.Instance.LinphoneCore.GetCurrentCall();
DateTimeOffset startTime = (DateTimeOffset)call.GetCallStartTimeFromContext();
DateTimeOffset now = DateTimeOffset.Now;
TimeSpan elapsed = now.Subtract(startTime);
var ss = elapsed.Seconds;
var mm = elapsed.Minutes;
Status.Dispatcher.BeginInvoke(delegate()
try
{
Status.Text = mm.ToString("00") + ":" + ss.ToString("00");
});
LinphoneCall call = LinphoneManager.Instance.LinphoneCore.GetCurrentCall();
if (call == null)
{
timer.Dispose();
return;
}
startTime = (DateTimeOffset)call.GetCallStartTimeFromContext();
DateTimeOffset now = DateTimeOffset.Now;
TimeSpan elapsed = now.Subtract(startTime);
var ss = elapsed.Seconds;
var mm = elapsed.Minutes;
Status.Dispatcher.BeginInvoke(delegate()
{
Status.Text = mm.ToString("00") + ":" + ss.ToString("00");
});
} catch {
timer.Dispose();
}
}
private void dialpad_Click_1(object sender, RoutedEventArgs 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