This commit is contained in:
Paul Schneider 2016-09-21 04:02:40 +02:00
commit 9c4621fe74
49 changed files with 742 additions and 444 deletions

View file

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quill.snow.css" />
<style>
.standalone-container {
margin: 0;
width: 100%;
height: 100%;
}
#bubble-container {
width:100%;
height: 100%;
}
#bubble-container div.ql-editor {
margin-top:0;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<h1>Title</h1>
<div class="standalone-container">
<div id="bubble-container"><h1><strong>Hello Estimate!</strong></h1>
</div>
</div>
<script type="text/javascript" src="quill.min.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="showdown.js"></script>
<script type="text/javascript" src="to-markdown.js"></script>
<script type="text/javascript" src="md-helpers.js"></script>
<script type="text/javascript">
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
['clean'] // remove formatting button
];
var quill = new Quill('#bubble-container', {
modules: {
toolbar: toolbarOptions
},
placeholder: 'Composez votre texte ...',
theme: 'snow'
});
function getMD() {
return markdownize($('#bubble-container div.ql-editor').html())
}
quill.on('text-change', function (delta, oldDelta, source)
{
if (source === "user") {
$.get("file:validate?md=" + encodeURIComponent(getMD()));
}
});
</script>
</body>
</html>

View file

@ -88,7 +88,8 @@
<HintPath>..\..\packages\Xam.Plugin.Media.1.0.1\lib\MonoAndroid10\Media.Plugin.Abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, processorArchitecture=MSIL" />
<Reference Include="Mono.Android.Export, Version=1.0.6099.33544, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, processorArchitecture=MSIL" />
<Reference Include="Mono.Data.Sqlite" />
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@ -203,6 +204,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>MarkdownEditor.cshtml</DependentUpon>
</Compile>
<Compile Include="MarkdownViewRenderer.cs" />
<Compile Include="MarkdownWebViewClient.cs" />
<Compile Include="OAuth2\YaOAuth2Authenticator.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
@ -224,6 +226,9 @@
<None Include="packages.config" />
<None Include="Resources\AboutResources.txt" />
<AndroidAsset Include="Assets\AboutAssets.txt" />
<AndroidResource Include="Resources\layout\EditEstimate.axml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\icon.png" />
@ -301,6 +306,7 @@
<AndroidResource Include="Resources\drawable\nfqrcode.png" />
<AndroidResource Include="Resources\drawable\visuel_sexion.jpg" />
<AndroidResource Include="Resources\values\values-21\styles.xml" />
<AndroidResource Include="Resources\drawable\icon-anon.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\drawable-hdpi\" />

View file

@ -27,7 +27,8 @@ using Android.Webkit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Views;
using BookAStar.Helpers;
using BookAStar.Interfaces;
namespace BookAStar.Droid
{
@ -87,11 +88,11 @@ namespace BookAStar.Droid
{
var accStore = AccountStore.Create(this);
var accounts = accStore.FindAccountsForService(MainSettings.ApplicationName);
var accounts = accStore.FindAccountsForService(Constants.ApplicationName);
accStore.Delete(
accounts.Where(a => a.Username == userName).FirstOrDefault()
, MainSettings.ApplicationName);
, Constants.ApplicationName);
Toast.MakeText(this,
Resource.String.yavscIdentRemoved
, ToastLength.Short);
@ -160,7 +161,7 @@ namespace BookAStar.Droid
using (var reader = new StreamReader(response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
Log.Debug(MainSettings.ApplicationName, responseText);
Log.Debug(Constants.ApplicationName, responseText);
}
}
}
@ -180,7 +181,7 @@ namespace BookAStar.Droid
{
return await Task.Run(() => {
var manager = AccountStore.Create(this);
return manager.FindAccountsForService(MainSettings.ApplicationName);
return manager.FindAccountsForService(Constants.ApplicationName);
});
}
YaOAuth2Authenticator auth = new YaOAuth2Authenticator(
@ -215,7 +216,7 @@ namespace BookAStar.Droid
// get me
// var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, eventArgs.Account);
var request = new HttpRequestMessage(HttpMethod.Get, MainSettings.UserInfoUrl);
var request = new HttpRequestMessage(HttpMethod.Get, Constants.UserInfoUrl);
request.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", tokens.AccessToken);
@ -244,7 +245,7 @@ namespace BookAStar.Droid
};
MainSettings.SaveUser(newuser);
accStore.Save(acc, MainSettings.ApplicationName);
accStore.Save(acc, Constants.ApplicationName);
}
}
@ -331,34 +332,6 @@ namespace BookAStar.Droid
return m.InvokeJson(arg);
}
}
public Xamarin.Forms.View CreateMarkdownView(string markdown, Action<string> update)
{
var view = new Android.Webkit.WebView(Forms.Context);
var viewclient = new MarkdownWebViewClient(update);
view.SetWebViewClient(viewclient);
var mde = new MarkdownEditor();
if (markdown!=null)
{
var md = new MarkdownDeep.Markdown();
mde.Model = md.Transform(markdown);
}
var html = mde.GenerateString();
view.Settings.BuiltInZoomControls = true;
view.Settings.JavaScriptEnabled = true;
view.Settings.LoadsImagesAutomatically = true;
view.Settings.SetAppCacheEnabled(true);
view.Settings.AllowContentAccess = true;
view.Settings.AllowFileAccess = true;
view.Settings.AllowFileAccessFromFileURLs = true;
view.Settings.AllowUniversalAccessFromFileURLs = true;
view.Settings.BlockNetworkImage = false;
view.Settings.BlockNetworkLoads = false;
view.LoadDataWithBaseURL("file:///android_asset/",
html, "text/html", "utf-8",null);
return view.ToView();
}
}
}

View file

@ -17,7 +17,7 @@ using System.Linq;
using System.Text;
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorTemplatePreprocessor", "4.1.2.18")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("RazorTemplatePreprocessor", "4.2.0.680")]
public partial class MarkdownEditor : MarkdownEditorBase
{
@ -32,32 +32,30 @@ public string Model { get; set; }
public override void Execute()
{
WriteLiteral("<!DOCTYPE html>\r\n<html>\r\n<head>\r\n \r\n <meta");
WriteLiteral("<!DOCTYPE html>\r\n<html>\r\n<head>\r\n <meta");
WriteLiteral(" charset=\"utf-8\"");
WriteLiteral(">\r\n\r\n <link");
WriteLiteral(">\r\n <link");
WriteLiteral(" rel=\"stylesheet\"");
WriteLiteral(" href=\"quill.snow.css\"");
WriteLiteral(@" />
<style>
.standalone-container {
margin: 0;
width: 100%;
height: 100%;
}
#bubble-container {
width:100%;
height: 100%;
}
#bubble-container div.ql-editor {
margin-top:3em;
}
.hidden {
display: none;
}
@ -65,7 +63,6 @@ WriteLiteral(@" />
</head>
<body>
<div");
WriteLiteral(" class=\"standalone-container\"");
@ -77,31 +74,13 @@ WriteLiteral(" id=\"bubble-container\"");
WriteLiteral(">");
#line 33 "MarkdownEditor.cshtml"
#line 28 "MarkdownEditor.cshtml"
Write(Html.Write(Model));
#line default
#line hidden
WriteLiteral("</div>\r\n </div>\r\n <form><input");
WriteLiteral(" type=\"hidden\"");
WriteLiteral(" name=\"md\"");
WriteLiteral(" id=\"md\"");
WriteLiteral(" />\r\n <input");
WriteLiteral(" id=\"btnSubmit\"");
WriteLiteral(" type=\"button\"");
WriteLiteral(" value=\"Valider\"");
WriteLiteral(" class=\"hidden\"");
WriteLiteral(" /></form>\r\n <script");
WriteLiteral("</div>\r\n </div>\r\n \r\n <script");
WriteLiteral(" type=\"text/javascript\"");
@ -143,7 +122,7 @@ WriteLiteral(@">
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
['link', 'image'],
['clean'] // remove formatting button
];
@ -151,26 +130,19 @@ WriteLiteral(@">
modules: {
toolbar: toolbarOptions
},
placeholder: 'Composez votre texte ...',
theme: 'snow'
});
placeholder: 'Composez votre texte ...',
theme: 'snow'
});
function getMD() {
return markdownize($('#bubble-container div.ql-editor').html())
}
quill.on('text-change', function (delta, oldDelta, source)
{
if (source === ""user"") {
$('#md').val(getMD());
$('#btnSubmit').removeClass('hidden');
function getMD() {
return markdownize($('#bubble-container div.ql-editor').html())
}
});
$(document).ready(function () {
$('#btnSubmit').on('click', function () {
$.get(""file:validate?md="" + encodeURIComponent(getMD()),
function (data, stat, jqXHR) { $('#result').html(""Okay"") })
})
});
quill.on('text-change', function (delta, oldDelta, source)
{
if (source === ""user"") {
invokeCSharpAction(getMD());
}
});
</script>
</body>

View file

@ -2,25 +2,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="quill.snow.css" />
<style>
.standalone-container {
margin: 0;
width: 100%;
height: 100%;
}
#bubble-container {
width:100%;
height: 100%;
}
#bubble-container div.ql-editor {
margin-top:3em;
}
.hidden {
display: none;
}
@ -28,12 +24,10 @@
</head>
<body>
<div class="standalone-container">
<div id="bubble-container">@Html.Write(Model)</div>
</div>
<form><input type="hidden" name="md" id="md" />
<input id="btnSubmit" type="button" value="Valider" class="hidden" /></form>
<script type="text/javascript" src="quill.min.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="showdown.js"></script>
@ -48,7 +42,7 @@
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
['link', 'image'],
['clean'] // remove formatting button
];
@ -56,26 +50,19 @@
modules: {
toolbar: toolbarOptions
},
placeholder: 'Composez votre texte ...',
theme: 'snow'
});
placeholder: 'Composez votre texte ...',
theme: 'snow'
});
function getMD() {
return markdownize($('#bubble-container div.ql-editor').html())
}
quill.on('text-change', function (delta, oldDelta, source)
{
if (source === "user") {
$('#md').val(getMD());
$('#btnSubmit').removeClass('hidden');
function getMD() {
return markdownize($('#bubble-container div.ql-editor').html())
}
});
$(document).ready(function () {
$('#btnSubmit').on('click', function () {
$.get("file:validate?md=" + encodeURIComponent(getMD()),
function (data, stat, jqXHR) { $('#result').html("Okay") })
})
});
quill.on('text-change', function (delta, oldDelta, source)
{
if (source === "user") {
invokeCSharpAction(getMD());
}
});
</script>
</body>

View file

@ -0,0 +1,94 @@
using BookAStar.Views;
using Android.Webkit;
using Xamarin.Forms.Platform.Android;
using BookAStar.Droid;
using System;
using Java.Interop;
[assembly: Xamarin.Forms.ExportRenderer(typeof(MarkdownView), typeof(MarkdownViewRenderer))]
namespace BookAStar.Droid
{
public class JSBridge : Java.Lang.Object
{
readonly WeakReference<MarkdownViewRenderer> hybridWebViewRenderer;
public JSBridge(MarkdownViewRenderer hybridRenderer)
{
hybridWebViewRenderer = new WeakReference<MarkdownViewRenderer>(hybridRenderer);
}
[JavascriptInterface]
[Export("invokeAction")]
public void InvokeAction(string data)
{
MarkdownViewRenderer hybridRenderer;
if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer))
{
hybridRenderer.Element.Markdown=data;
}
}
}
public class MarkdownViewRenderer : ViewRenderer<MarkdownView, WebView>
{
private WebView editorView;
private MarkdownEditor editorTemplate = new MarkdownEditor();
private MarkdownDeep.Markdown markdown = new MarkdownDeep.Markdown();
const string JavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}";
private void SetMDEditorText(string text)
{
editorTemplate.Model = (text == null) ? null : markdown.Transform(text);
var html = editorTemplate.GenerateString();
editorView.LoadDataWithBaseURL("file:///android_asset/",
html, "text/html", "utf-8", null);
}
protected override void OnElementChanged(ElementChangedEventArgs<MarkdownView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
editorView = new WebView(Context);
editorView.Settings.BuiltInZoomControls = true;
editorView.Settings.JavaScriptEnabled = true;
editorView.Settings.LoadsImagesAutomatically = true;
editorView.Settings.SetAppCacheEnabled(true);
editorView.Settings.AllowContentAccess = true;
editorView.Settings.AllowFileAccess = true;
editorView.Settings.AllowFileAccessFromFileURLs = true;
editorView.Settings.AllowUniversalAccessFromFileURLs = true;
editorView.Settings.BlockNetworkImage = false;
editorView.Settings.BlockNetworkLoads = false;
editorView.Settings.DomStorageEnabled = true;
// editorView.SetMinimumHeight(300);
SetNativeControl(editorView);
}
if (e.OldElement != null)
{
// Unsubscribe
}
if (e.NewElement != null)
{
// Subscribe
var viewclient = new MarkdownWebViewClient(
md => { e.NewElement.Markdown = md; });
editorView.SetWebViewClient(viewclient);
Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");
SetMDEditorText(e.NewElement.Markdown);
InjectJS(JavaScriptFunction);
}
}
void InjectJS(string script)
{
if (Control != null)
{
Control.LoadUrl(string.Format("javascript: {0}", script));
}
}
}
}

View file

@ -16,6 +16,7 @@ using Android.Content.Res;
namespace BookAStar.Droid
{
class MarkdownWebViewClient : WebViewClient
{
Action<string> update;
@ -25,7 +26,7 @@ namespace BookAStar.Droid
}
private static Activity getActivity ()
{
return (Activity)App.PlateformSpecificInstance;
return (Activity)App.PlatformSpecificInstance;
}
public string Markdown { get; private set; }
public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request)
@ -34,6 +35,8 @@ namespace BookAStar.Droid
{
if (request.Url.Path=="/android_asset/validate")
{
// TODO Better,
// by inspecting the form entries from the view
Markdown = request.Url.GetQueryParameter("md");
update(Markdown);
return new WebResourceResponse("application/json", "utf-8" ,200, "Ok", null, null);
@ -41,5 +44,6 @@ namespace BookAStar.Droid
}
return base.ShouldInterceptRequest(view, request);
}
}
}

View file

@ -13,7 +13,7 @@ using Android.App;
[assembly: AssemblyProduct("BookAStar.Droid")]
[assembly: AssemblyCopyright("Copyright © Paul Albert Schneider 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyCulture("fr")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:

View file

@ -3232,64 +3232,67 @@ namespace BookAStar.Droid
public const int design_navigation_menu_item = 2130903076;
// aapt resource value: 0x7f030025
public const int mr_chooser_dialog = 2130903077;
public const int EditEstimate = 2130903077;
// aapt resource value: 0x7f030026
public const int mr_chooser_list_item = 2130903078;
public const int mr_chooser_dialog = 2130903078;
// aapt resource value: 0x7f030027
public const int mr_controller_material_dialog_b = 2130903079;
public const int mr_chooser_list_item = 2130903079;
// aapt resource value: 0x7f030028
public const int mr_controller_volume_item = 2130903080;
public const int mr_controller_material_dialog_b = 2130903080;
// aapt resource value: 0x7f030029
public const int mr_playback_control = 2130903081;
public const int mr_controller_volume_item = 2130903081;
// aapt resource value: 0x7f03002a
public const int mr_volume_control = 2130903082;
public const int mr_playback_control = 2130903082;
// aapt resource value: 0x7f03002b
public const int notification_media_action = 2130903083;
public const int mr_volume_control = 2130903083;
// aapt resource value: 0x7f03002c
public const int notification_media_cancel_action = 2130903084;
public const int notification_media_action = 2130903084;
// aapt resource value: 0x7f03002d
public const int notification_template_big_media = 2130903085;
public const int notification_media_cancel_action = 2130903085;
// aapt resource value: 0x7f03002e
public const int notification_template_big_media_narrow = 2130903086;
public const int notification_template_big_media = 2130903086;
// aapt resource value: 0x7f03002f
public const int notification_template_lines = 2130903087;
public const int notification_template_big_media_narrow = 2130903087;
// aapt resource value: 0x7f030030
public const int notification_template_media = 2130903088;
public const int notification_template_lines = 2130903088;
// aapt resource value: 0x7f030031
public const int notification_template_part_chronometer = 2130903089;
public const int notification_template_media = 2130903089;
// aapt resource value: 0x7f030032
public const int notification_template_part_time = 2130903090;
public const int notification_template_part_chronometer = 2130903090;
// aapt resource value: 0x7f030033
public const int select_dialog_item_material = 2130903091;
public const int notification_template_part_time = 2130903091;
// aapt resource value: 0x7f030034
public const int select_dialog_multichoice_material = 2130903092;
public const int select_dialog_item_material = 2130903092;
// aapt resource value: 0x7f030035
public const int select_dialog_singlechoice_material = 2130903093;
public const int select_dialog_multichoice_material = 2130903093;
// aapt resource value: 0x7f030036
public const int support_simple_spinner_dropdown_item = 2130903094;
public const int select_dialog_singlechoice_material = 2130903094;
// aapt resource value: 0x7f030037
public const int Tabbar = 2130903095;
public const int support_simple_spinner_dropdown_item = 2130903095;
// aapt resource value: 0x7f030038
public const int Toolbar = 2130903096;
public const int Tabbar = 2130903096;
// aapt resource value: 0x7f030039
public const int Toolbar = 2130903097;
static Layout()
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />