From e1c73f0dd477392eb41bfbf195b17b9256772c52 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 3 Jan 2017 13:53:06 +0100 Subject: [PATCH] Fixes the GCM notification intent to view the Book query that was notified --- BookAStar/BookAStar.Droid/MainActivity.cs | 4 +- .../Services/GcmListenerService.cs | 19 ++- .../Services/MyGcmIntentService.cs | 22 ++- BookAStar/BookAStar/App.xaml.cs | 12 +- BookAStar/BookAStar/BookAStar.csproj | 5 +- BookAStar/BookAStar/Data/DataManager.cs | 5 +- .../BookQuery.cs} | 8 +- .../Model/Booking/MusicalPreference.cs | 12 ++ .../Model/Booking/MusicalTendency.cs | 13 ++ .../BookAStar/Model/Social/LocationType.cs | 10 ++ .../Model/Social/Messaging/BookQuery.cs | 1 - .../BookAStar/Model/Workflow/Estimate.cs | 10 +- .../Pages/EstimatePages/BookQueryPage.xaml.cs | 10 +- BookAStar/BookAStar/Pages/HomePage.xaml | 143 +++++++++--------- BookAStar/BookAStar/Pages/HomePage.xaml.cs | 7 +- BookAStar/BookAStar/Settings/MainSettings.cs | 23 +-- .../EstimateAndBilling/BookQueryViewModel.cs | 6 +- .../EditEstimateViewModel.cs | 10 +- .../Searching/SearchingAnArtistViewModel.cs | 6 +- 19 files changed, 193 insertions(+), 133 deletions(-) rename BookAStar/BookAStar/Model/{BookQueryData.cs => Booking/BookQuery.cs} (72%) create mode 100644 BookAStar/BookAStar/Model/Booking/MusicalPreference.cs create mode 100644 BookAStar/BookAStar/Model/Booking/MusicalTendency.cs create mode 100644 BookAStar/BookAStar/Model/Social/LocationType.cs diff --git a/BookAStar/BookAStar.Droid/MainActivity.cs b/BookAStar/BookAStar.Droid/MainActivity.cs index 97d2098e..dc310313 100644 --- a/BookAStar/BookAStar.Droid/MainActivity.cs +++ b/BookAStar/BookAStar.Droid/MainActivity.cs @@ -251,8 +251,8 @@ namespace BookAStar.Droid { Task.Run(async () => { - App.ShowBookQuery( - await DataManager.Instance.BookQueries.Get(queryId)); + var query = DataManager.Instance.BookQueries.LocalGet(queryId); + App.ShowBookQuery(query); }); } } diff --git a/BookAStar/BookAStar.Droid/Services/GcmListenerService.cs b/BookAStar/BookAStar.Droid/Services/GcmListenerService.cs index 98a21fc8..83df3daa 100644 --- a/BookAStar/BookAStar.Droid/Services/GcmListenerService.cs +++ b/BookAStar/BookAStar.Droid/Services/GcmListenerService.cs @@ -9,6 +9,9 @@ namespace BookAStar.Droid.Services using Model.Social; using Newtonsoft.Json; using Model; + using Model.Social; + using Data; + using System.Linq; namespace ClientApp { @@ -52,13 +55,20 @@ namespace BookAStar.Droid.Services var cid = long.Parse(data.GetString("Id")); var clientJson = data.GetString("Client"); var client = JsonConvert.DeserializeObject(clientJson); - var bq = new BookQueryData + var bq = new BookQuery { Id = cid, Location = location, Client = client, Reason = data.GetString("Reason") }; + var dateString = data.GetString("EventDate"); + DateTime evDate; + if (DateTime.TryParse(dateString, out evDate)) + { + bq.EventDate = evDate; + } + SendBookQueryNotification(bq); } else @@ -84,9 +94,12 @@ namespace BookAStar.Droid.Services notificationManager.Notify(0, notificationBuilder.Build()); } - void SendBookQueryNotification(BookQueryData bquery) + void SendBookQueryNotification(BookQuery bquery) { - var bookquerynotifications = MainSettings.AddBookQueryNotification(bquery); + DataManager.Instance.BookQueries.Merge(bquery); + var bookquerynotifications = DataManager.Instance.BookQueries.Where( + q=> ! q.Read && q.EventDate > DateTime.Now + ).ToArray(); var count = bookquerynotifications.Length; var multiple = count > 1; var title = diff --git a/BookAStar/BookAStar.Droid/Services/MyGcmIntentService.cs b/BookAStar/BookAStar.Droid/Services/MyGcmIntentService.cs index b6ed58f1..66d63577 100644 --- a/BookAStar/BookAStar.Droid/Services/MyGcmIntentService.cs +++ b/BookAStar/BookAStar.Droid/Services/MyGcmIntentService.cs @@ -7,7 +7,6 @@ using Android.Widget; namespace BookAStar.Droid { - [Service] public class MyGcmIntentService : IntentService { @@ -31,6 +30,7 @@ namespace BookAStar.Droid intent.SetClass(context, typeof(MyGcmIntentService)); context.StartService(intent); } + static object locker = new object(); protected override void OnHandleIntent(Intent intent) @@ -74,16 +74,28 @@ namespace BookAStar.Droid void SendNotification (string message) { - var intent = new Intent (this, typeof(MainActivity)); + /* Bundle valuesForActivity = new Bundle(); + valuesForActivity.PutInt("count", count); */ + + var intent = new Intent (this, typeof(MainActivity)); intent.AddFlags (ActivityFlags.ClearTop); var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot); + // Construct a back stack for cross-task navigation: + TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this); + stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity))); + stackBuilder.AddNextIntent(intent); + + // Create the PendingIntent with the back stack: + PendingIntent resultPendingIntent = + stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent); - var notificationBuilder = new Notification.Builder(this) + var notificationBuilder = new Notification.Builder(this) + .SetAutoCancel(true) .SetSmallIcon (Resource.Drawable.icon) .SetContentTitle ("GCM Message") .SetContentText (message) - .SetAutoCancel (true) - .SetContentIntent (pendingIntent); + .SetContentIntent(resultPendingIntent) // Start 2nd activity when the intent is clicked. + ; var notificationManager = (NotificationManager) GetSystemService(Context.NotificationService); notificationManager.Notify (0, notificationBuilder.Build()); diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index 6c3147c9..6a84b530 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -30,6 +30,7 @@ namespace BookAStar using ViewModels; using Pages.Chat; using System.Collections.Generic; + using Model.Social; public partial class App : Application // superclass new in 1.3 { @@ -196,9 +197,8 @@ namespace BookAStar ChatPage chatPage; - private void ShowPage(Page page) + public static void ShowPage(Page page) { - if (Navigation.NavigationStack.Contains(page)) { if (Navigation.NavigationStack.Last() == page) return; @@ -443,11 +443,11 @@ namespace BookAStar PlatformSpecificInstance.InvokeApi("gcm/register", info); } - public static void ShowBookQuery (BookQueryData query) + public static void ShowBookQuery (BookQuery query) { - var page = ViewFactory.CreatePage((b, p) => p.BindingContext = new BookQueryViewModel(query)); - App.Current.MainPage.Navigation.PushAsync(page as Page); + var page = new BookQueryPage + { BindingContext = new BookQueryViewModel(query) }; + ShowPage(page); } } } diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index d67b6e9d..1687641c 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -57,11 +57,14 @@ + + + SearchPage.xaml @@ -161,7 +164,7 @@ - + diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index 025e15b3..5f324332 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -9,11 +9,12 @@ using ViewModels; using Model.Access; using ViewModels.Messaging; + using Model.Social; public class DataManager { // TODO estimatetemplate rating service product tag - public RemoteEntityRO BookQueries { get; set; } + public RemoteEntityRO BookQueries { get; set; } public ChatUserCollection ChatUsers { get; set; } public EstimateEntity Estimates { get; set; } public RemoteEntity Blogspot { get; set; } @@ -41,7 +42,7 @@ public DataManager() { - BookQueries = new RemoteEntityRO("bookquery", q => q.Id); + BookQueries = new RemoteEntityRO("bookquery", q => q.Id); Estimates = new EstimateEntity(); Blogspot = new RemoteEntity("blog", x=>x.Id); diff --git a/BookAStar/BookAStar/Model/BookQueryData.cs b/BookAStar/BookAStar/Model/Booking/BookQuery.cs similarity index 72% rename from BookAStar/BookAStar/Model/BookQueryData.cs rename to BookAStar/BookAStar/Model/Booking/BookQuery.cs index eb10dc88..67721c49 100644 --- a/BookAStar/BookAStar/Model/BookQueryData.cs +++ b/BookAStar/BookAStar/Model/Booking/BookQuery.cs @@ -1,10 +1,9 @@ -using BookAStar.Interfaces; -using BookAStar.Model.Social; + using System; -namespace BookAStar.Model +namespace BookAStar.Model.Social { - public class BookQueryData + public class BookQuery { public ClientProviderInfo Client { get; set; } public Location Location { get; set; } @@ -12,5 +11,6 @@ namespace BookAStar.Model public DateTime EventDate { get; set; } public decimal? Previsionnal { get; set; } public string Reason { get; set; } + public bool Read { get; set; } } } diff --git a/BookAStar/BookAStar/Model/Booking/MusicalPreference.cs b/BookAStar/BookAStar/Model/Booking/MusicalPreference.cs new file mode 100644 index 00000000..f5d7e6a1 --- /dev/null +++ b/BookAStar/BookAStar/Model/Booking/MusicalPreference.cs @@ -0,0 +1,12 @@ + +namespace BookAStar.Model.Social +{ + + public class MusicalPreference : MusicalTendency { + + public long OwnerId { get; set; } + public int Rate { get; set; } + + } + +} diff --git a/BookAStar/BookAStar/Model/Booking/MusicalTendency.cs b/BookAStar/BookAStar/Model/Booking/MusicalTendency.cs new file mode 100644 index 00000000..9fc9ab74 --- /dev/null +++ b/BookAStar/BookAStar/Model/Booking/MusicalTendency.cs @@ -0,0 +1,13 @@ + +namespace BookAStar.Model.Social +{ + + public class MusicalTendency { + + public long Id {get; set; } + + public string Name { get ; set; } + + } + +} diff --git a/BookAStar/BookAStar/Model/Social/LocationType.cs b/BookAStar/BookAStar/Model/Social/LocationType.cs new file mode 100644 index 00000000..3cea380c --- /dev/null +++ b/BookAStar/BookAStar/Model/Social/LocationType.cs @@ -0,0 +1,10 @@ + +namespace BookAStar.Model.Social +{ + public class LocationType + { + public long Id { get; set; } + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/BookAStar/BookAStar/Model/Social/Messaging/BookQuery.cs b/BookAStar/BookAStar/Model/Social/Messaging/BookQuery.cs index d51c2267..725757bd 100644 --- a/BookAStar/BookAStar/Model/Social/Messaging/BookQuery.cs +++ b/BookAStar/BookAStar/Model/Social/Messaging/BookQuery.cs @@ -7,7 +7,6 @@ namespace BookAStar.Model.Workflow.Messaging /// /// Query, for a date, with a given perfomer, at this given place. /// - public class BookQuery { /// /// The command identifier diff --git a/BookAStar/BookAStar/Model/Workflow/Estimate.cs b/BookAStar/BookAStar/Model/Workflow/Estimate.cs index 14e37cb6..ec3a3f4d 100644 --- a/BookAStar/BookAStar/Model/Workflow/Estimate.cs +++ b/BookAStar/BookAStar/Model/Workflow/Estimate.cs @@ -1,6 +1,4 @@ -using BookAStar.Data; -using BookAStar.Helpers; -using BookAStar.Model.Interfaces; + using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -8,6 +6,10 @@ using System.Linq; namespace BookAStar.Model.Workflow { + using Data; + using Interfaces; + using Social; + public partial class Estimate : IEstimate { public long Id { get; set; } @@ -62,7 +64,7 @@ namespace BookAStar.Model.Workflow } public string ClientId { get; set; } [JsonIgnore] - public BookQueryData Query + public BookQuery Query { get { diff --git a/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs b/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs index d97efab5..3c4e4b7f 100644 --- a/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EstimatePages/BookQueryPage.xaml.cs @@ -7,14 +7,14 @@ namespace BookAStar.Pages { using Data; using EstimatePages; - using Model; + using Model.Social; using Model.Workflow; using ViewModels.EstimateAndBilling; public partial class BookQueryPage : ContentPage { - public BookQueryData BookQuery + public BookQuery BookQuery { get { @@ -32,14 +32,14 @@ namespace BookAStar.Pages var pin = new Pin { Type = PinType.SavedPin, - Position = new Position( - lat, lon), + Position = new Xamarin.Forms.Maps.Position + (lat, lon), Label = BookQuery.Client.UserName, Address = BookQuery.Location.Address }; map.Pins.Add(pin); map.MoveToRegion(MapSpan.FromCenterAndRadius( - new Position(lat, lon), Distance.FromMeters(100))); + new Xamarin.Forms.Maps.Position(lat, lon), Distance.FromMeters(100))); } } diff --git a/BookAStar/BookAStar/Pages/HomePage.xaml b/BookAStar/BookAStar/Pages/HomePage.xaml index 47624f55..d366c5b2 100644 --- a/BookAStar/BookAStar/Pages/HomePage.xaml +++ b/BookAStar/BookAStar/Pages/HomePage.xaml @@ -1,9 +1,10 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:local="clr-namespace:BookAStar;assembly=BookAStar" + x:Class="BookAStar.Pages.HomePage" + Style="{StaticResource PageStyle}" + Title="Accueil">