Commit da93b3bf authored by Sylvain Berfini's avatar Sylvain Berfini

Display missed calls on Tile when in background

parent b533824e
......@@ -69,6 +69,11 @@ namespace Linphone.Agents
{
Debug.WriteLine("[IncomingCallAgent] Incoming call processing is now complete.");
BackgroundManager.Instance.OopServer.CallController.IncomingCallViewDismissed = null;
TileManager.Instance.UpdateCount(BackgroundManager.Instance.OopServer.LinphoneCore.GetMissedCallsCount());
BackgroundManager.Instance.OopServer.LinphoneCore.SetNetworkReachable(false); // To prevent the core from unregister
BackgroundManager.Instance.OopServer.LinphoneCoreFactory.Destroy();
base.NotifyComplete();
}
......
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace Linphone.Agents
{
......@@ -12,6 +14,9 @@ namespace Linphone.Agents
/// </summary>
public class TileManager
{
private string TileCountKey = "TileCount";
private IsolatedStorageSettings settings;
private static TileManager singleton;
/// <summary>
/// Static instance to access the class.
......@@ -32,14 +37,32 @@ namespace Linphone.Agents
/// </summary>
public TileManager()
{
settings = IsolatedStorageSettings.ApplicationSettings;
}
/// <summary>
/// Displays the number of missed call and unread messages on the live tile and on the lock screen
/// Update the count to display on the Tile, and update the Tile with the new count
/// </summary>
/// <param name="missedCalls">Number of missed calls + number of unread messages</param>
public void UpdateTileWithMissedCallsAndUnreadMessages(int count)
/// <param name="toAdd"></param>
public void UpdateCount(int toAdd)
{
int count = 0;
try
{
count = (int)settings[TileCountKey];
count += toAdd;
settings[TileCountKey] = count;
}
catch (KeyNotFoundException)
{
settings.Add(TileCountKey, toAdd);
count = toAdd;
}
settings.Save();
UpdateTile(count);
}
private void UpdateTile(int count)
{
ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
if (tile != null)
......@@ -55,7 +78,16 @@ namespace Linphone.Agents
/// </summary>
public void RemoveCountOnTile()
{
UpdateTileWithMissedCallsAndUnreadMessages(0);
try
{
settings[TileCountKey] = 0;
}
catch (KeyNotFoundException)
{
settings.Add(TileCountKey, 0);
}
settings.Save();
UpdateTile(0);
}
}
}
......@@ -160,6 +160,7 @@ namespace Linphone.Model
/// </summary>
public void ConnectBackgroundProcessToInterface()
{
TileManager.Instance.RemoveCountOnTile();
if (BackgroundProcessConnected)
{
Debug.WriteLine("[LinphoneManager] Background process already connected to interface");
......@@ -828,8 +829,6 @@ namespace Linphone.Model
BaseModel.UIDispatcher.BeginInvoke(() =>
{
Logger.Msg("[LinphoneManager] Call released\r\n");
//Update tile
UpdateLiveTile();
});
}
else if (state == LinphoneCallState.UpdatedByRemote)
......@@ -928,7 +927,6 @@ namespace Linphone.Model
/// </summary>
public void MessageReceived(LinphoneChatMessage message)
{
BaseModel.UIDispatcher.BeginInvoke(() =>
{
string sipAddress = message.GetFrom().AsStringUriOnly().Replace("sip:", "");
......@@ -988,9 +986,6 @@ namespace Linphone.Model
};
MessageReceivedNotification.Show();
//Update tile
UpdateLiveTile();
}
});
}
......@@ -1019,16 +1014,6 @@ namespace Linphone.Model
}
#endregion
/// <summary>
/// Updates the app tile to display the number of missed calls and unread chats.
/// </summary>
public void UpdateLiveTile()
{
int missedCalls = LinphoneCore.GetMissedCallsCount();
int unreadChats = (from message in DatabaseManager.Instance.Messages where message.MarkedAsRead == false select message).ToList().Count;
TileManager.Instance.UpdateTileWithMissedCallsAndUnreadMessages(missedCalls + unreadChats);
}
#region Contact Lookup
private ContactManager ContactManager
{
......
......@@ -205,7 +205,6 @@ namespace Linphone.Views
scrollToBottom();
DatabaseManager.Instance.SubmitChanges();
LinphoneManager.Instance.UpdateLiveTile();
}
/// <summary>
......
......@@ -124,7 +124,6 @@ namespace Linphone.Views
ClearApplicationBar();
SetupAppBarForEmptySelection();
LinphoneManager.Instance.UpdateLiveTile();
}
private void newChat_Click_1(object sender, EventArgs e)
......
......@@ -43,7 +43,6 @@ namespace Linphone.Views
await LinphoneManager.Instance.InitLinphoneCore();
LinphoneManager.Instance.LinphoneCore.ResetMissedCallsCount();
LinphoneManager.Instance.UpdateLiveTile();
List<CallLog> callsHistory = LinphoneManager.Instance.GetCallsHistory();
Calls.ItemsSource = callsHistory;
......
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