diff --git a/YavscLib/IGoogleCloudMobileDeclaration.cs b/YavscLib/IGoogleCloudMobileDeclaration.cs index 90f82c6b..b8b006b5 100644 --- a/YavscLib/IGoogleCloudMobileDeclaration.cs +++ b/YavscLib/IGoogleCloudMobileDeclaration.cs @@ -16,6 +16,8 @@ // along with yavsc. If not, see . // +using System; + namespace Yavsc.Models.Identity { public interface IGCMDeclaration @@ -25,7 +27,7 @@ namespace Yavsc.Models.Identity string Model { get; set; } string Platform { get; set; } string Version { get; set; } - + DateTime LatestActivityUpdate { get; set; } } public interface IGoogleCloudMobileDeclaration: IGCMDeclaration diff --git a/YavscLib/YavscLib.csproj b/YavscLib/YavscLib.csproj index 05d56efd..81d429c0 100644 --- a/YavscLib/YavscLib.csproj +++ b/YavscLib/YavscLib.csproj @@ -47,12 +47,15 @@ + + + diff --git a/ZicMoove/ZicMoove.Droid/MainActivity.cs b/ZicMoove/ZicMoove.Droid/MainActivity.cs index 702248eb..a47ae3ee 100644 --- a/ZicMoove/ZicMoove.Droid/MainActivity.cs +++ b/ZicMoove/ZicMoove.Droid/MainActivity.cs @@ -32,7 +32,6 @@ using XLabs.Platform.Services.Email; using XLabs.Platform.Services.Media; using XLabs.Serialization; using XLabs.Serialization.JsonNET; -using Yavsc.Helpers; using Yavsc.Models.Identity; namespace ZicMoove.Droid @@ -327,8 +326,8 @@ namespace ZicMoove.Droid { var auth = new YaOAuth2Authenticator( clientId: Constants.APIKey, - clientSecret: "blouh", - scope: "profile", + clientSecret: Constants.APISecret, + scope: Constants.Scope, authorizeUrl: new Uri(Constants.AuthorizeUrl), redirectUrl: new Uri(Constants.RedirectUrl), accessTokenUrl: new Uri(Constants.AccessTokenUrl)); @@ -401,43 +400,7 @@ namespace ZicMoove.Droid - public IGCMDeclaration GetDeviceInfo() - { - var devinfo = CrossDeviceInfo.Current; - return new GCMRegIdDeclaration - { - DeviceId = devinfo.Id, - GCMRegistrationId = MainSettings.GoogleRegId, - Model = devinfo.Model, - Platform = devinfo.Platform.ToString(), - Version = devinfo.Version - }; - } - - [Obsolete("Use RemoteEntity to manage entities from API")] - public TAnswer InvokeApi(string method, object arg) - { - using (var m = - new SimpleJsonPostMethod( - method, "Bearer " + - MainSettings.CurrentUser.YavscTokens.AccessToken - )) - { - return m.Invoke(arg); - } - } - - public object InvokeApi(string method, object arg) - { - using (var m = - new SimpleJsonPostMethod( - method, "Bearer " + - MainSettings.CurrentUser.YavscTokens.AccessToken - )) - { - return m.InvokeJson(arg); - } - } + public T Resolve() { diff --git a/ZicMoove/ZicMoove.Droid/Services/GcmRegistrationIntentService.cs b/ZicMoove/ZicMoove.Droid/Services/GcmRegistrationIntentService.cs index 42a81b4d..97626a0b 100644 --- a/ZicMoove/ZicMoove.Droid/Services/GcmRegistrationIntentService.cs +++ b/ZicMoove/ZicMoove.Droid/Services/GcmRegistrationIntentService.cs @@ -64,7 +64,7 @@ namespace ZicMoove.Droid } #endif - var senderid = MainSettings.GoogleSenderId; + var senderid = Constants.GoogleSenderId; var token = instanceID.GetToken ( senderid, GoogleCloudMessaging.InstanceIdScope, null); diff --git a/ZicMoove/ZicMoove.Droid/Services/MyGcmIntentService.cs b/ZicMoove/ZicMoove.Droid/Services/MyGcmIntentService.cs index 9fbd7c84..45e2e16e 100644 --- a/ZicMoove/ZicMoove.Droid/Services/MyGcmIntentService.cs +++ b/ZicMoove/ZicMoove.Droid/Services/MyGcmIntentService.cs @@ -112,8 +112,7 @@ namespace ZicMoove.Droid void SubscribeGCM () { Context context = this.ApplicationContext; - string senders = MainSettings.GoogleSenderId; - // Resources.GetString(GoogleSenderId); + string senders = Constants.GoogleSenderId; Intent intent = new Intent ("com.google.android.c2dm.intent.REGISTER"); intent.SetPackage ("com.google.android.gsf"); intent.PutExtra ("app", PendingIntent.GetBroadcast (context, 0, new Intent (), 0)); diff --git a/ZicMoove/ZicMoove.Droid/ZicMoove.Droid.csproj b/ZicMoove/ZicMoove.Droid/ZicMoove.Droid.csproj index 608b4ec3..1c08e1df 100644 --- a/ZicMoove/ZicMoove.Droid/ZicMoove.Droid.csproj +++ b/ZicMoove/ZicMoove.Droid/ZicMoove.Droid.csproj @@ -352,7 +352,6 @@ - diff --git a/ZicMoove/ZicMoove/App.xaml.cs b/ZicMoove/ZicMoove/App.xaml.cs index 3a83e21c..18dc82ae 100644 --- a/ZicMoove/ZicMoove/App.xaml.cs +++ b/ZicMoove/ZicMoove/App.xaml.cs @@ -32,6 +32,10 @@ namespace ZicMoove using System.Collections.Generic; using Model.Social; using Settings; + using Helpers; + using Model.Auth; + using Plugin.DeviceInfo; + using Yavsc.Models.Identity; public partial class App : Application // superclass new in 1.3 { @@ -67,12 +71,10 @@ namespace ZicMoove app.Startup += OnStartup; app.Suspended += OnSuspended; MainSettings.UserChanged += MainSettings_UserChanged; - CrossConnectivity.Current.ConnectivityChanged += (conSender, args) => - { App.IsConnected = args.IsConnected; }; + SetupHubConnection(); MainSettings_UserChanged(this, null); - - StartConnexion(); + StartConnexion(); } // omg @@ -334,22 +336,7 @@ namespace ZicMoove 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 - StartConnexion(); - } - - } - } - } + public static bool IsConnected { get { return CrossConnectivity.Current.IsConnected; } } private static HubConnection chatHubConnection = null; public static HubConnection ChatHubConnection { @@ -453,11 +440,57 @@ namespace ZicMoove public static void PostDeviceInfo() { - var info = PlatformSpecificInstance.GetDeviceInfo(); + var info = GetDeviceInfo(); if (!string.IsNullOrWhiteSpace(info.GCMRegistrationId)) - PlatformSpecificInstance.InvokeApi("gcm/register", info); + { + if (MainSettings.CurrentUser != null) + { + InvokeApi("gcm/register", info); + DataManager.Instance.Activities.Execute(null); + } + + } + } + public static IGCMDeclaration GetDeviceInfo() + { + var devinfo = CrossDeviceInfo.Current; + return new GCMRegIdDeclaration + { + DeviceId = devinfo.Id, + GCMRegistrationId = MainSettings.GoogleRegId, + Model = devinfo.Model, + Platform = devinfo.Platform.ToString(), + Version = devinfo.Version, + LatestActivityUpdate = DataManager.Instance.Activities.Aggregate( + (a,b)=> a.DateModified > b.DateModified ? a : b + ).DateModified + }; } + [Obsolete("Use RemoteEntity to manage entities from API")] + public async Task InvokeApi(string method, object arg) + { + using (var m = + new SimpleJsonPostMethod( + method, "Bearer " + + MainSettings.CurrentUser.YavscTokens.AccessToken + )) + { + return await m.Invoke(arg); + } + } + + public static object InvokeApi(string method, object arg) + { + using (var m = + new SimpleJsonPostMethod( + method, "Bearer " + + MainSettings.CurrentUser.YavscTokens.AccessToken + )) + { + return m.InvokeJson(arg); + } + } public static void ShowBookQuery (BookQuery query) { var page = new BookQueryPage diff --git a/ZicMoove/ZicMoove/Constants.cs b/ZicMoove/ZicMoove/Constants.cs index 2ba194cb..5e9d5ab5 100644 --- a/ZicMoove/ZicMoove/Constants.cs +++ b/ZicMoove/ZicMoove/Constants.cs @@ -11,7 +11,6 @@ namespace ZicMoove { public static readonly string AuthorizeUrl = YavscHomeUrl + "/authorize"; - public static readonly string RedirectUrl = YavscHomeUrl + "/oauth/success"; public static readonly string AccessTokenUrl = YavscHomeUrl + "/token"; public static readonly string YavscApiUrl = YavscHomeUrl + "/api"; diff --git a/ZicMoove/ZicMoove/Data/DataManager.cs b/ZicMoove/ZicMoove/Data/DataManager.cs index 9e29d827..8e9352d5 100644 --- a/ZicMoove/ZicMoove/Data/DataManager.cs +++ b/ZicMoove/ZicMoove/Data/DataManager.cs @@ -15,6 +15,7 @@ { // TODO estimatetemplate rating service product tag public RemoteEntityRO BookQueries { get; set; } + public RemoteEntityRO Activities { get; set; } public ChatUserCollection ChatUsers { get; set; } public EstimateEntity Estimates { get; set; } public RemoteEntity Blogspot { get; set; } @@ -47,7 +48,6 @@ BookQueries = new RemoteEntityRO("bookquery", q => q.Id); Estimates = new EstimateEntity(); 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); @@ -56,6 +56,7 @@ RemoteFiles = new RemoteFilesEntity (); BlackList = new RemoteEntity("blacklist",u => u.Id); ChatUsers = new ChatUserCollection(); + Activities = new RemoteEntityRO("activity",a=>a.Code); PrivateMessages.Load(); BookQueries.Load(); Estimates.Load(); @@ -67,6 +68,7 @@ RemoteFiles.Load(); BlackList.Load(); ChatUsers.Load(); + Activities.Load(); } } } diff --git a/ZicMoove/ZicMoove.Droid/Helpers/SimpleJsonPostMethod.cs b/ZicMoove/ZicMoove/Helpers/SimpleJsonPostMethod.cs similarity index 80% rename from ZicMoove/ZicMoove.Droid/Helpers/SimpleJsonPostMethod.cs rename to ZicMoove/ZicMoove/Helpers/SimpleJsonPostMethod.cs index c562a0fc..3ead7852 100644 --- a/ZicMoove/ZicMoove.Droid/Helpers/SimpleJsonPostMethod.cs +++ b/ZicMoove/ZicMoove/Helpers/SimpleJsonPostMethod.cs @@ -27,7 +27,7 @@ using System; using System.Diagnostics; using ZicMoove; -namespace Yavsc.Helpers +namespace ZicMoove.Helpers { /// /// Simple json post method. @@ -46,10 +46,9 @@ namespace Yavsc.Helpers request.Method = "POST"; request.Accept = "application/json"; request.ContentType = "application/json"; - request.SendChunked = true; - request.TransferEncoding = "UTF-8"; - if (authorizationHeader!=null) - request.Headers.Add($"Authorization: {authorizationHeader}"); + + if (authorizationHeader != null) + request.Headers["Authorization"] = authorizationHeader; } public static string BasePath { get; private set; } = Constants.YavscApiUrl; @@ -63,21 +62,20 @@ namespace Yavsc.Helpers /// Invoke the specified query. /// /// Query. - public TAnswer Invoke(object query) + public async Task Invoke(object query) { - using (Stream streamQuery = request.GetRequestStream()) { + using (Stream streamQuery = await request.GetRequestStreamAsync()) { using (StreamWriter writer = new StreamWriter(streamQuery)) { writer.Write (JsonConvert.SerializeObject(query)); }} TAnswer ans = default (TAnswer); - using (WebResponse response = request.GetResponse ()) { + using (WebResponse response = await request.GetResponseAsync ()) { using (Stream responseStream = response.GetResponseStream ()) { using (StreamReader rdr = new StreamReader (responseStream)) { ans = (TAnswer) JsonConvert.DeserializeObject (rdr.ReadToEnd ()); } } - response.Close(); } return ans; } @@ -88,31 +86,30 @@ namespace Yavsc.Helpers try { - using (Stream streamQuery = request.GetRequestStream()) + using (Stream streamQuery = await request.GetRequestStreamAsync()) { using (StreamWriter writer = new StreamWriter(streamQuery)) { writer.Write(JsonConvert.SerializeObject(query)); } } - using (WebResponse response = request.GetResponse()) + using (WebResponse response = await request.GetResponseAsync()) { using (Stream stream = response.GetResponseStream()) { if (stream.Length > 0) jsonDoc = await Task.Run(() => JsonObject.Load(stream)); } - response.Close(); } } catch (WebException ex) { // TODO err logging - Debug.Print($"Web request failed: {request.ToString()}\n" + ex.ToString()); + Debug.WriteLine($"Web request failed: {request.ToString()}\n" + ex.ToString()); } catch (Exception ex) { - Debug.Print($"Web request failed: {request.ToString()}\n" + ex.ToString()); + Debug.WriteLine($"Web request failed: {request.ToString()}\n" + ex.ToString()); } return jsonDoc; diff --git a/ZicMoove/ZicMoove/Interfaces/IPlatform.cs b/ZicMoove/ZicMoove/Interfaces/IPlatform.cs index 0f81713f..04955a36 100644 --- a/ZicMoove/ZicMoove/Interfaces/IPlatform.cs +++ b/ZicMoove/ZicMoove/Interfaces/IPlatform.cs @@ -17,12 +17,6 @@ namespace ZicMoove.Interfaces void AddAccount(); void RevokeAccount(string userName); - - IGCMDeclaration GetDeviceInfo(); - - TAnswer InvokeApi(string method, object arg); - - object InvokeApi(string method, object arg); } } diff --git a/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs b/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs index 46743dc2..cb9c2163 100644 --- a/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs +++ b/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs @@ -15,6 +15,9 @@ namespace ZicMoove.Model.Auth public string GCMRegistrationId { get; set; } + public DateTime LatestActivityUpdate + { get; set; } + public string Model { get; set; } diff --git a/ZicMoove/ZicMoove/Model/Manager.cs b/ZicMoove/ZicMoove/Model/Manager.cs deleted file mode 100644 index c4fefb7c..00000000 --- a/ZicMoove/ZicMoove/Model/Manager.cs +++ /dev/null @@ -1,63 +0,0 @@ -using ZicMoove.Model.Social; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Windows.Input; - -namespace ZicMoove -{ - [Obsolete("Use Helpers.DataManager")] - public static class Manager - { - static Manager () - { - } - - public static ICommand RefreshBookQueries; - // TODO WIP TEST rop this - private static Location[] _places = new Location[] { - new Location { Latitude = 48.8626458, Longitude = 2.2065559, Address = "2 bd Aristide Briand - Suresnes" }, - new Location{ Latitude =48.8632757, Longitude =2.2023099, Address ="Théatre Jean Villard - Suresnes" }, - new Location{ Latitude =48.8647120, Longitude =2.2054588,Address = "Place de la Paix - Suresnes" }, - new Location{ Latitude =48.8640133, Longitude =2.2056573, Address ="Restaurant" }, - new Location{ Latitude =48.8634839, Longitude =2.2064137,Address = "Square" }, - new Location{ Latitude =48.8653649, Longitude =2.2014945,Address = "Stade de foot" }, - }; - // TODO WIP TEST rop this - private static ObservableCollection _your_events = new ObservableCollection { - new LocalizedEvent { - - Title = "Yavsc Party", - Description = "Lancement en fanfare de la version 1.0 de ZicMoove, l'appli des fétards", - ProviderId = "paul", - ProviderName = "Yavsc Fondation", - EventWebPage = "http://lua.pschneider.fr/", - Location = _places[0] - }, - new LocalizedEvent { - Title = "Evenement de test", - Description = "Blah bli lo qui est errare, ma no. Blou test allo 3!", - ProviderId = "provid3", - ProviderName = "Prov Entreprise 3", - EventWebPage = "http://lua.pschneider.fr/events/test3", - Location = _places[1] - }, - new LocalizedEvent { - Title = "DjFx feat XamCoder, en Concert gratuit", - Description = "Hip Hop à Suresnes", - ProviderId = "brahim", - ProviderName = "Totem Production", - EventWebPage = "http://lua.pschneider.fr/events/totem", - Location = _places[2] - } - }; - // TODO WIP TEST rop this - public static ObservableCollection Events { - get { - return _your_events; - } - } - - } -} - diff --git a/ZicMoove/ZicMoove/Model/Workflow/Activity.cs b/ZicMoove/ZicMoove/Model/Workflow/Activity.cs new file mode 100644 index 00000000..61ce0918 --- /dev/null +++ b/ZicMoove/ZicMoove/Model/Workflow/Activity.cs @@ -0,0 +1,65 @@ +using System; +using YavscLib; + +namespace ZicMoove.Model.Workflow +{ + public class Activity : IActivity + { + public string Code + { + get; set; + } + + public DateTime DateCreated + { + get; set; + } + + public DateTime DateModified + { + get; set; + } + + public string ModeratorGroupName + { + get; set; + } + + public string Name + { + get; set; + } + + public string ParentCode + { + get; set; + } + + public string Photo + { + get; set; + } + + public int Rate + { + get; set; + } + + public string SettingsClassName + { + get; set; + } + + public string UserCreated + { + get; set; + } + + public string UserModified + { + get; set; + } + + public CommandForm[] Forms { get; set; } + } +} diff --git a/ZicMoove/ZicMoove/Model/Workflow/CommandForm.cs b/ZicMoove/ZicMoove/Model/Workflow/CommandForm.cs new file mode 100644 index 00000000..cdc87566 --- /dev/null +++ b/ZicMoove/ZicMoove/Model/Workflow/CommandForm.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YavscLib; + +namespace ZicMoove.Model.Workflow +{ + public class CommandForm : ICommandForm + { + public string Action + { + get; set; + } + + public string ActivityCode + { + get; set; + } + + public long Id + { + get; set; + } + + public string Title + { + get; set; + } + } +} diff --git a/ZicMoove/ZicMoove/Settings/MainSettings.cs b/ZicMoove/ZicMoove/Settings/MainSettings.cs index 6fc5e995..12598d7c 100644 --- a/ZicMoove/ZicMoove/Settings/MainSettings.cs +++ b/ZicMoove/ZicMoove/Settings/MainSettings.cs @@ -43,7 +43,6 @@ namespace ZicMoove.Settings string.Empty; private static readonly bool PushNotificationsDefault = false; - public static readonly string GoogleSenderId = "325408689282"; private const string MusicalKey = "musical_prefs"; private const string EnvironKey = "environ_prefs"; diff --git a/ZicMoove/ZicMoove/ZicMoove.csproj b/ZicMoove/ZicMoove/ZicMoove.csproj index c97f3230..1ff7c62f 100644 --- a/ZicMoove/ZicMoove/ZicMoove.csproj +++ b/ZicMoove/ZicMoove/ZicMoove.csproj @@ -67,6 +67,7 @@ + @@ -77,6 +78,8 @@ + + SearchPage.xaml @@ -180,7 +183,6 @@ - @@ -300,6 +302,12 @@ ..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll + + ..\..\packages\Xam.Plugin.DeviceInfo.2.0.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.DeviceInfo.dll + + + ..\..\packages\Xam.Plugin.DeviceInfo.2.0.2\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.DeviceInfo.Abstractions.dll + ..\..\packages\Xam.Plugin.Geolocator.3.0.4\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Geolocator.dll @@ -328,6 +336,9 @@ ..\..\packages\SQLite.Net-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll True + + ..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Json.dll + ..\..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8+wpa81\System.Net.Http.Extensions.dll True