Fixes the GCM notification intent

to view the Book query that was notified
This commit is contained in:
Paul Schneider 2017-01-03 13:53:06 +01:00
commit 54b0c2af0d
19 changed files with 193 additions and 133 deletions

View file

@ -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<ClientProviderInfo>(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 =

View file

@ -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);
var notificationBuilder = new Notification.Builder(this)
// Create the PendingIntent with the back stack:
PendingIntent resultPendingIntent =
stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);
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());