diff --git a/BookAStar/BookAStar.Droid/Resources/drawable/exclam.png b/BookAStar/BookAStar.Droid/Resources/drawable/exclam.png new file mode 100644 index 00000000..0fc3f26a Binary files /dev/null and b/BookAStar/BookAStar.Droid/Resources/drawable/exclam.png differ diff --git a/BookAStar/BookAStar.Droid/Resources/drawable/nicubunu-Peer-to-peer.png b/BookAStar/BookAStar.Droid/Resources/drawable/nicubunu-Peer-to-peer.png new file mode 100644 index 00000000..b920c64d Binary files /dev/null and b/BookAStar/BookAStar.Droid/Resources/drawable/nicubunu-Peer-to-peer.png differ diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index cb690f7e..98337fed 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -12,12 +12,15 @@ using XLabs.Enums; namespace BookAStar { + using System.Threading.Tasks; using Data; using Interfaces; using Model; using Model.UI; using Pages; + using Plugin.Connectivity; using ViewModels; + using Microsoft.AspNet.SignalR.Client; public partial class App : Application // superclass new in 1.3 { @@ -70,7 +73,10 @@ namespace BookAStar // Called Once, at app init private void OnInitialize(object sender, EventArgs e) { - + CrossConnectivity.Current.ConnectivityChanged += (conSender, args) => + { + App.IsConnected = args.IsConnected; + }; } // called on app startup, not on rotation @@ -225,6 +231,44 @@ namespace BookAStar } public static INavigationService NavigationService { protected set; get; } + public static bool isConnected; + public static bool IsConnected { get { return isConnected; } + private set + { + if (isConnected != value) + { + isConnected = value; + if (isConnected) + { + // TODO Start all cloud related stuff + + + } + } + } + } + + // Start the Hub connection + private async void StartHubConnection () + { + chatHubConnection = new HubConnection(Constants.SignalRHubsUrl); + if (MainSettings.CurrentUser != null) + chatHubConnection.Headers.Add("Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken); + chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); + chatHubProxy.On("AddMessage", (n, m) => { + Messages.Add(string.Format("{0} says: {1}", n, m)); + }); + await chatHubConnection.Start(); + } + private HubConnection chatHubConnection=null; + private IHubProxy chatHubProxy = null; + public static Task HasSomeCloud { + get + { + return CrossConnectivity.Current.IsReachable(Constants.YavscHomeUrl, Constants.CloudTimeout); + } + } + public void PostDeviceInfo() { var res = PlatformSpecificInstance.InvokeApi( diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index 75f2f26a..588e1398 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -49,7 +49,10 @@ + + + @@ -97,7 +100,7 @@ EventDetail.xaml - + @@ -218,6 +221,12 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll + + ..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.dll + + + ..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll + ..\..\packages\Xam.Plugins.Settings.2.5.1.0\lib\portable-net45+wp80+win8+wpa81\Plugin.Settings.dll True diff --git a/BookAStar/BookAStar/Constants.cs b/BookAStar/BookAStar/Constants.cs index 922a84d7..70234d49 100644 --- a/BookAStar/BookAStar/Constants.cs +++ b/BookAStar/BookAStar/Constants.cs @@ -19,11 +19,13 @@ namespace BookAStar public static readonly string UserInfoUrl = YavscApiUrl + "/me"; public static readonly string BlogUrl = YavscApiUrl + "/blogs"; public static readonly string FsUrl = YavscApiUrl + "/fs"; - public static readonly string SignalRHubsUrl = YavscHomeUrl + "/signalr/hubs"; + public static readonly string SignalRHubsUrl = YavscHomeUrl + "/api/signalr/hubs"; #endregion #region Permissions ids public static int AllowBeATarget = 1; #endregion + + public static int CloudTimeout = 400; } } diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index 1a478437..4c67559e 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -5,6 +5,7 @@ using Model.Workflow; using Model.UI; using ViewModels; + using Model.Social; public class DataManager { @@ -19,7 +20,7 @@ /// internal LocalEntity EstimationCache { get; set; } internal LocalEntity EstimateLinesTemplates { get; set; } - + internal LocalEntity PrivateMessages { get; set; } protected static DataManager current ; public static DataManager Current @@ -34,18 +35,16 @@ public DataManager() { - BookQueries = new RemoteEntityRO("bookquery", - q => q.Id); - Estimates = new RemoteEntity("estimate", - x => x.Id); - Blogspot = new RemoteEntity("blog", - x=>x.Id); + BookQueries = new RemoteEntityRO("bookquery", q => q.Id); + Estimates = new RemoteEntity("estimate", x => x.Id); + Blogspot = new RemoteEntity("blog", x=>x.Id); Contacts = new LocalEntity(c => c.UserId); AppState = new LocalEntity(s => s.Position); - EstimationCache = new LocalEntity( - e => e.Query.Id); - EstimateLinesTemplates = new LocalEntity( - l => l.Description); + EstimationCache = new LocalEntity(e => e.Query.Id); + EstimateLinesTemplates = new LocalEntity(l => l.Description); + PrivateMessages = new LocalEntity(m=> m.GetHashCode()); + + PrivateMessages.Load(); BookQueries.Load(); Estimates.Load(); Blogspot.Load(); diff --git a/BookAStar/BookAStar/Data/LocaLEntity.cs b/BookAStar/BookAStar/Data/LocaLEntity.cs index 05ee3d58..56d800ce 100644 --- a/BookAStar/BookAStar/Data/LocaLEntity.cs +++ b/BookAStar/BookAStar/Data/LocaLEntity.cs @@ -14,7 +14,9 @@ namespace BookAStar.Data public LocalEntity(Func getKey) : base() { - if (getKey == null) throw new InvalidOperationException(); + if (getKey == null) + // choose please, because of the genesis + throw new InvalidOperationException ("A key must be defined"); GetKey = getKey; IList l = this; } diff --git a/BookAStar/BookAStar/Images/Notifications/exclam.png b/BookAStar/BookAStar/Images/Notifications/exclam.png new file mode 100644 index 00000000..0fc3f26a Binary files /dev/null and b/BookAStar/BookAStar/Images/Notifications/exclam.png differ diff --git a/BookAStar/BookAStar/Images/Notifications/exclam_inv.png b/BookAStar/BookAStar/Images/Notifications/exclam_inv.png new file mode 100644 index 00000000..0dac252a Binary files /dev/null and b/BookAStar/BookAStar/Images/Notifications/exclam_inv.png differ diff --git a/BookAStar/BookAStar/Model/Social/Messaging/ChatStatus.cs b/BookAStar/BookAStar/Model/Social/Messaging/ChatStatus.cs new file mode 100644 index 00000000..0f8dcaba --- /dev/null +++ b/BookAStar/BookAStar/Model/Social/Messaging/ChatStatus.cs @@ -0,0 +1,10 @@ +namespace BookAStar.Model.Workflow.Messaging +{ + public enum ChatStatus + { + OnLine, + Away, + OffLine + } +} + diff --git a/BookAStar/BookAStar/Model/Social/PrivateMessage.cs b/BookAStar/BookAStar/Model/Social/PrivateMessage.cs new file mode 100644 index 00000000..1fa633fd --- /dev/null +++ b/BookAStar/BookAStar/Model/Social/PrivateMessage.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookAStar.Model.Social +{ + class PrivateMessage + { + public DateTime Date { get; set; } + public string SenderId { get; set; } + public string Message { get; set; } + } +} diff --git a/BookAStar/BookAStar/Pages/ChatPage.xaml b/BookAStar/BookAStar/Pages/ChatPage.xaml index f53cc3f6..0a15c6b3 100644 --- a/BookAStar/BookAStar/Pages/ChatPage.xaml +++ b/BookAStar/BookAStar/Pages/ChatPage.xaml @@ -1,9 +1,10 @@  - - + + - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/BookAStar/BookAStar/Pages/ChatPage.xaml.cs b/BookAStar/BookAStar/Pages/ChatPage.xaml.cs index cab895da..0d4ecc76 100644 --- a/BookAStar/BookAStar/Pages/ChatPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/ChatPage.xaml.cs @@ -6,7 +6,7 @@ using Xamarin.Forms; namespace BookAStar.Pages { - public partial class ChatPage : ContentPage + public partial class ChatPage : TabbedPage { public ObservableCollection Messages { get; set; } public string ChatUser { get; set; } @@ -42,7 +42,9 @@ namespace BookAStar.Pages { IsBusy = true; chatHubConnection = new HubConnection(Constants.SignalRHubsUrl); + chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub"); + chatHubProxy.On("AddMessage", (n, m) => { Messages.Add(string.Format("{0} says: {1}", n, m)); }); diff --git a/BookAStar/BookAStar/Settings/ChatSettings.cs b/BookAStar/BookAStar/Settings/ChatSettings.cs new file mode 100644 index 00000000..4e50073c --- /dev/null +++ b/BookAStar/BookAStar/Settings/ChatSettings.cs @@ -0,0 +1,80 @@ +using BookAStar.Model.Workflow.Messaging; +using Plugin.Settings; +using Plugin.Settings.Abstractions; +using System.Collections.Generic; + +namespace BookAStar.Settings +{ + public static class ChatSettings + { + public static ISettings AppSettings + { + get + { + return CrossSettings.Current; + } + } + private const string statusKey = "chat.status"; + private const string ignoreListKey = "chat.ignoreList"; + private const string denyAnonymousAccessKey = "chat.denyAnonymousAccess"; + private const string denyTouristAccessKey = "chat.denyTouristAccess"; + + public static ChatStatus Status + { + get + { + return AppSettings.GetValueOrDefault(statusKey, ChatStatus.OffLine); + } + set + { + AppSettings.AddOrUpdateValue(statusKey, value); + } + } + public static List IgnoreList + { + get + { + return AppSettings.GetValueOrDefault>(ignoreListKey); + } + } + public static void Ignore(string userId) + { + var ignoreList = IgnoreList; + ignoreList.Add(userId); + AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList); + } + public static void UnIgnore(string userId) + { + var ignoreList = IgnoreList; + ignoreList.Remove(userId); + AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList); + } + public static void UnIgnoreAll() + { + var ignoreList = new List(); + AppSettings.AddOrUpdateValue(ignoreListKey, ignoreList); + } + public static bool DenyAnonymousAccess + { + get + { + return AppSettings.GetValueOrDefault(denyAnonymousAccessKey); + } + set + { + AppSettings.AddOrUpdateValue(denyAnonymousAccessKey, value); + } + } + public static bool DenyTouristAccess + { + get + { + return AppSettings.GetValueOrDefault(denyTouristAccessKey); + } + set + { + AppSettings.AddOrUpdateValue(denyTouristAccessKey, value); + } + } + } +} diff --git a/BookAStar/BookAStar/Helpers/MainSettings.cs b/BookAStar/BookAStar/Settings/MainSettings.cs similarity index 100% rename from BookAStar/BookAStar/Helpers/MainSettings.cs rename to BookAStar/BookAStar/Settings/MainSettings.cs