WIP estimate
This commit is contained in:
parent
4d7de134ce
commit
d67c932af2
43 changed files with 816 additions and 94 deletions
|
|
@ -1,14 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace BookAStar.Droid.Services
|
||||
{
|
||||
|
|
@ -16,37 +6,122 @@ namespace BookAStar.Droid.Services
|
|||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Gms.Gcm;
|
||||
using Android.Util;
|
||||
using Model.Social;
|
||||
using Newtonsoft.Json;
|
||||
using Model;
|
||||
|
||||
namespace ClientApp
|
||||
{
|
||||
[Service(Exported = false), IntentFilter(new[] { "com.google.android.c2dm.intent.RECEIVE" })]
|
||||
public class MyGcmListenerService : GcmListenerService
|
||||
{
|
||||
public override void OnMessageReceived(string from, Bundle data)
|
||||
private Notification.Builder notificationBuilder;
|
||||
|
||||
NotificationManager notificationManager;
|
||||
|
||||
public override void OnCreate()
|
||||
{
|
||||
var message = data.GetString("message");
|
||||
Log.Debug("MyGcmListenerService", "From: " + from);
|
||||
Log.Debug("MyGcmListenerService", "Message: " + message);
|
||||
SendNotification(message);
|
||||
base.OnCreate();
|
||||
notificationBuilder = new Notification.Builder(this)
|
||||
.SetSmallIcon(Resource.Drawable.icon)
|
||||
.SetAutoCancel(true);
|
||||
notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
|
||||
|
||||
}
|
||||
|
||||
void SendNotification(string message)
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
notificationManager.Dispose();
|
||||
notificationManager = null;
|
||||
notificationBuilder.Dispose();
|
||||
notificationBuilder = null;
|
||||
}
|
||||
|
||||
public override void OnMessageReceived(string from, Bundle data)
|
||||
{
|
||||
var topic = data.GetString("Topic");
|
||||
if (topic == "BookQuery")
|
||||
{
|
||||
DateTime startdate,enddate;
|
||||
|
||||
var sdatestr = data.GetString("StartDate");
|
||||
DateTime.TryParse(sdatestr, out startdate);
|
||||
|
||||
var enddatestr = data.GetString("EndDate");
|
||||
DateTime.TryParse(enddatestr, out enddate);
|
||||
|
||||
var locationJson = data.GetString("Location");
|
||||
var location = JsonConvert.DeserializeObject<Location>(locationJson);
|
||||
var cid = long.Parse(data.GetString("CommandId"));
|
||||
var bq = new BookQueryData
|
||||
{
|
||||
Title = data.GetString("Title"),
|
||||
Description = data.GetString("Description"),
|
||||
Comment = data.GetString("Comment"),
|
||||
StartDate = startdate,
|
||||
EndDate = enddate,
|
||||
CommandId = cid,
|
||||
Address = location
|
||||
};
|
||||
|
||||
SendBookQueryNotification(bq);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(topic);
|
||||
}
|
||||
}
|
||||
|
||||
void SendNotification(string title, string message)
|
||||
{
|
||||
var intent = new Intent(this, typeof(MainActivity));
|
||||
intent.AddFlags(ActivityFlags.ClearTop);
|
||||
|
||||
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
|
||||
|
||||
var notificationBuilder = new Notification.Builder(this)
|
||||
.SetSmallIcon(Resource.Drawable.icon)
|
||||
.SetContentTitle("GCM Message")
|
||||
.SetContentTitle(title)
|
||||
.SetContentText(message)
|
||||
.SetAutoCancel(true)
|
||||
.SetContentIntent(pendingIntent);
|
||||
|
||||
var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
|
||||
notificationManager.Notify(0, notificationBuilder.Build());
|
||||
}
|
||||
|
||||
void SendBookQueryNotification(BookQueryData bquery)
|
||||
{
|
||||
var bookquerynotifications = MainSettings.AddBookQueryNotification(bquery);
|
||||
var count = bookquerynotifications.Length;
|
||||
var multiple = count > 1;
|
||||
var title =
|
||||
multiple ? $"{count} demandes" : bquery.Title;
|
||||
var message = bquery.Description;
|
||||
|
||||
var intent = new Intent(this, typeof(MainActivity));
|
||||
intent.AddFlags(ActivityFlags.ClearTop);
|
||||
intent.PutExtra("BookQueryId", bquery.CommandId);
|
||||
|
||||
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
|
||||
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
|
||||
int maxil = 5;
|
||||
for (int cn = 0; cn < count && cn < maxil; cn++)
|
||||
{
|
||||
inboxStyle.AddLine(bookquerynotifications[cn].Description);
|
||||
}
|
||||
if (count > maxil)
|
||||
inboxStyle.SetSummaryText($"Plus {count - maxil} autres");
|
||||
else inboxStyle.SetSummaryText((string)null);
|
||||
notificationBuilder.SetContentTitle(title).SetContentText(message)
|
||||
.SetStyle(inboxStyle)
|
||||
.SetContentIntent(pendingIntent);
|
||||
|
||||
var notification = notificationBuilder.Build();
|
||||
notificationManager.Notify(bookQueryNotificationId, notification );
|
||||
}
|
||||
|
||||
int bookQueryNotificationId=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue