WIP estimate
This commit is contained in:
parent
4d7de134ce
commit
d67c932af2
43 changed files with 816 additions and 94 deletions
|
|
@ -2,6 +2,7 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<AndroidDesignerPreferredDevice>Nexus 4</AndroidDesignerPreferredDevice>
|
||||
<SelectedDevice>Android_Accelerated_x86</SelectedDevice>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ReferencePath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\</ReferencePath>
|
||||
|
|
|
|||
88
BookAStar/BookAStar.Droid/MarkdownRazorWebViewClient.cs
Normal file
88
BookAStar/BookAStar.Droid/MarkdownRazorWebViewClient.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
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;
|
||||
using Android.Webkit;
|
||||
using Java.Lang;
|
||||
using Java.IO;
|
||||
using Android.Content.Res;
|
||||
|
||||
namespace BookAStar.Droid
|
||||
{
|
||||
class MarkdownRazorWebViewClient : WebViewClient
|
||||
{
|
||||
Context context;
|
||||
public MarkdownRazorWebViewClient(Context context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
private WebResourceResponse getWebResourceResponseFromAssets(string name)
|
||||
{
|
||||
var desc =
|
||||
getActivity().Assets.OpenFd(name);
|
||||
var stream = desc.CreateInputStream();
|
||||
string encoding = null;
|
||||
string mimet = "text/html";
|
||||
if (name.EndsWith(".css"))
|
||||
{
|
||||
mimet = "text/css";
|
||||
encoding = "utf-8";
|
||||
}
|
||||
else if (name.EndsWith(".js"))
|
||||
{ mimet = "text/js";
|
||||
encoding = "utf-8";
|
||||
}
|
||||
else if (name.EndsWith(".ico"))
|
||||
{ mimet = "image/ico";
|
||||
encoding = "utf-8";
|
||||
}
|
||||
|
||||
return new WebResourceResponse(mimet, encoding, stream );
|
||||
|
||||
}
|
||||
private static Activity getActivity ()
|
||||
{
|
||||
return (Activity)App.PlateformSpecificInstance;
|
||||
}
|
||||
public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request)
|
||||
{
|
||||
|
||||
if (request.Url.Scheme=="file")
|
||||
{
|
||||
return getWebResourceResponseFromAssets(request.Url.Path);
|
||||
}
|
||||
if (request.Url.Scheme=="hybrid")
|
||||
{
|
||||
getActivity().RunOnUiThread(
|
||||
() => testGetContent(view));
|
||||
}
|
||||
return base.ShouldInterceptRequest(view, request);
|
||||
}
|
||||
|
||||
class ContentCallBack : Java.Lang.Object, IValueCallback
|
||||
{
|
||||
public string Result { get; private set; }
|
||||
public void OnReceiveValue(Java.Lang.Object value)
|
||||
{
|
||||
if (value == null) { Result = null; }
|
||||
else { Result = new string(((Java.Lang.String)value).ToCharArray()); }
|
||||
}
|
||||
}
|
||||
|
||||
void testGetContent(WebView view)
|
||||
{
|
||||
var cb = new ContentCallBack();
|
||||
view.EvaluateJavascript("$('#Content').val()", cb);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -3310,9 +3310,6 @@ namespace BookAStar.Droid
|
|||
// aapt resource value: 0x7f06004b
|
||||
public const int Description = 2131099723;
|
||||
|
||||
// aapt resource value: 0x7f060052
|
||||
public const int GoogleSenderId = 2131099730;
|
||||
|
||||
// aapt resource value: 0x7f06004d
|
||||
public const int Location = 2131099725;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,4 @@
|
|||
<string name="url">url</string>
|
||||
<string name="url_hint">url_hint</string>
|
||||
<string name="picture">picture</string>
|
||||
<string name="GoogleSenderId">AA325408689282</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -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