From 435c084fe2607116b750e27784e3d896405e9c27 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 5 Oct 2016 01:20:06 +0200 Subject: [PATCH] Bug Fixes & Layout --- BookAStar/BookAStar.Droid/CompatXFormsApp.cs | 5 +- BookAStar/BookAStar.Droid/MainActivity.cs | 32 ++++--- .../BookAStar.Droid/MarkdownViewRenderer.cs | 80 +++++++++++------ .../Resources/Resource.Designer.cs | 7 +- .../Resources/layout/Toolbar.axml | 11 ++- BookAStar/BookAStar/App.xaml.cs | 87 ++++++++++++++----- BookAStar/BookAStar/Model/Auth/User.cs | 2 + .../BookAStar/Pages/AccountChooserPage.xaml | 7 -- .../BookAStar/Pages/EditEstimatePage.xaml | 18 ++-- .../BookAStar/Pages/EditEstimatePage.xaml.cs | 9 +- BookAStar/BookAStar/Views/MarkdownView.cs | 15 ++-- 11 files changed, 181 insertions(+), 92 deletions(-) diff --git a/BookAStar/BookAStar.Droid/CompatXFormsApp.cs b/BookAStar/BookAStar.Droid/CompatXFormsApp.cs index c8bdfb90..e121c021 100644 --- a/BookAStar/BookAStar.Droid/CompatXFormsApp.cs +++ b/BookAStar/BookAStar.Droid/CompatXFormsApp.cs @@ -297,6 +297,7 @@ namespace XLabs.Forms base.OnStop(); } + } /// @@ -334,8 +335,10 @@ namespace XLabs.Forms this.AppContext.Stop += (o, e) => this.OnClosing(); this.AppContext.Pause += (o, e) => this.OnSuspended(); this.AppContext.Resume += (o, e) => this.OnResumed(); + this.AppDataDirectory = Environment.ExternalStorageDirectory.AbsolutePath; - + this.Orientation = AppContext.RequestedOrientation == Android.Content.PM.ScreenOrientation.Portrait ? + Enums.Orientation.Portrait : Enums.Orientation.None; if (initServices) { DependencyService.Register(); diff --git a/BookAStar/BookAStar.Droid/MainActivity.cs b/BookAStar/BookAStar.Droid/MainActivity.cs index b410b27f..60b52570 100644 --- a/BookAStar/BookAStar.Droid/MainActivity.cs +++ b/BookAStar/BookAStar.Droid/MainActivity.cs @@ -55,8 +55,8 @@ namespace BookAStar.Droid ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); - - global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never); + SetPersistent(true); + // global::Xamarin.Forms.Forms.SetTitleBarVisibility(Xamarin.Forms.AndroidTitleBarVisibility.Never); //var tb = FindViewById(ToolbarResource); // FIXME tb is null @@ -73,7 +73,8 @@ namespace BookAStar.Droid IXFormsApp app =null; if (!Resolver.IsSet) { - this.SetIoc(); + var xfapp = new XFormsCompatAppDroid(); + this.SetIoc(xfapp); } else { @@ -93,8 +94,8 @@ namespace BookAStar.Droid } }; - - LoadApplication(new BookAStar.App(this)); + var fapp = new BookAStar.App(this); + LoadApplication(fapp); // TabLayoutResource = Resource.Layout.Tabbar; // ToolbarResource = Resource.Layout.Toolbar; /* @@ -108,11 +109,10 @@ namespace BookAStar.Droid } - private void SetIoc() + private SimpleContainer SetIoc(XFormsCompatAppDroid app) { var resolverContainer = new SimpleContainer(); - var app = new XFormsCompatAppDroid(); app.Init(this); @@ -133,6 +133,7 @@ namespace BookAStar.Droid t => new SQLiteSimpleCache(new SQLitePlatformAndroid(), new SQLiteConnectionString(pathToDatabase, true), t.Resolve())); Resolver.SetResolver(resolverContainer.GetResolver()); + return resolverContainer; } public bool EnablePushNotifications(bool enable) @@ -425,18 +426,25 @@ namespace BookAStar.Droid public T Resolve() { - - throw new NotImplementedException(); + return (T) Resolver.Resolve(typeof(T)); } public object Resolve(Type t) { - throw new NotImplementedException(); + return Resolver.Resolve(t); } - public void Init(App context, bool initServices = true) + protected override void OnSaveInstanceState(Bundle outState) + { + base.OnSaveInstanceState(outState); + } + public override void OnStateNotSaved() + { + base.OnStateNotSaved(); + } + public override void OnRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) { - throw new NotImplementedException(); + base.OnRestoreInstanceState(savedInstanceState, persistentState); } } } diff --git a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs index 217afc8c..f811ac02 100644 --- a/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs +++ b/BookAStar/BookAStar.Droid/MarkdownViewRenderer.cs @@ -6,6 +6,7 @@ using BookAStar.Droid; using System; using Java.Interop; using System.ComponentModel; +using Android.Views; [assembly: Xamarin.Forms.ExportRenderer(typeof(MarkdownView), typeof(MarkdownViewRenderer))] namespace BookAStar.Droid @@ -27,9 +28,13 @@ namespace BookAStar.Droid if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer)) { - hybridRenderer.Element.Markdown=data; + hybridRenderer.Element.Markdown = data; + MarkdownViewRenderer.OnPageFinished(hybridRenderer.Element, + hybridRenderer.EditorView); } } + + } public class MarkdownViewRenderer : ViewRenderer @@ -39,12 +44,30 @@ namespace BookAStar.Droid private MarkdownDeep.Markdown markdown = new MarkdownDeep.Markdown(); const string JavaScriptFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}"; + public WebView EditorView + { + get + { + return editorView; + } + } + + public static async void OnPageFinished(MarkdownView xview, WebView view) + { + int i = 10; + while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered + await System.Threading.Tasks.Task.Delay(100); + xview.BatchBegin(); + xview.HeightRequest = view.ContentHeight; + xview.BatchCommit(); + } private void SetMDEditorText(string text) { editorTemplate.Model = (text == null) ? null : markdown.Transform(text); var html = editorTemplate.GenerateString(); - editorView.LoadDataWithBaseURL("file:///android_asset/", + EditorView.LoadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null); + OnPageFinished(Element, editorView); } protected override void OnElementChanged(ElementChangedEventArgs e) @@ -63,7 +86,7 @@ namespace BookAStar.Droid // Subscribe var viewclient = new MarkdownWebViewClient( md => { e.NewElement.Markdown = md; }); - editorView.SetWebViewClient(viewclient); + EditorView.SetWebViewClient(viewclient); Control.AddJavascriptInterface(new JSBridge(this), "jsBridge"); SetMDEditorText(e.NewElement.Markdown); InjectJS(JavaScriptFunction); @@ -81,33 +104,40 @@ namespace BookAStar.Droid private WebView CreateNativeControl() { 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.Settings.BuiltInZoomControls = false; + 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); - return editorView; + return EditorView; } - - protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) + // FIXME no impact... + protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (e.PropertyName == "Markdown") - { - SetMDEditorText(((MarkdownView)Element).Markdown); - } - base.OnElementPropertyChanged(sender, e); + MeasureSpecMode widthMode = MeasureSpec.GetMode(widthMeasureSpec); + MeasureSpecMode heightMode = MeasureSpec.GetMode(heightMeasureSpec); + int widthSize = MeasureSpec.GetSize(widthMeasureSpec); + int heightSize = MeasureSpec.GetSize(heightMeasureSpec); + int pxHeight = (int)ContextExtensions.ToPixels(Context, Element.HeightRequest); + int pxWidth = (int)ContextExtensions.ToPixels(Context, Element.WidthRequest); + var measuredWidth = widthMode != MeasureSpecMode.Exactly ? (widthMode != MeasureSpecMode.AtMost ? pxHeight : Math.Min(pxHeight, widthSize)) : widthSize; + var measuredHeight = heightMode != MeasureSpecMode.Exactly ? (heightMode != MeasureSpecMode.AtMost ? pxWidth : Math.Min(pxWidth, heightSize)) : heightSize; + SetMeasuredDimension(measuredWidth, measuredHeight< Element.HeightRequest ? (int) Element.HeightRequest : measuredHeight); } - - protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) + /* + protected override void OnLayout(bool changed, int left, int top, int right, int bottom) { - base.OnMeasure(widthMeasureSpec, editorView.ContentHeight); + Element.Layout(new Xamarin.Forms.Rectangle(0, 0, ContextExtensions.FromPixels(Context, right - left), ContextExtensions.FromPixels(Context, bottom - top))); + base.OnLayout(changed, left, top, right, bottom); } + */ } } \ No newline at end of file diff --git a/BookAStar/BookAStar.Droid/Resources/Resource.Designer.cs b/BookAStar/BookAStar.Droid/Resources/Resource.Designer.cs index b2617ce9..c68e3864 100644 --- a/BookAStar/BookAStar.Droid/Resources/Resource.Designer.cs +++ b/BookAStar/BookAStar.Droid/Resources/Resource.Designer.cs @@ -4952,8 +4952,8 @@ namespace BookAStar.Droid // aapt resource value: 0x7f0c00b3 public const int subtitles = 2131493043; - // aapt resource value: 0x7f0c00b6 - public const int surface_view = 2131493046; + // aapt resource value: 0x7f0c00b5 + public const int surface_view = 2131493045; // aapt resource value: 0x7f0c0019 public const int tabMode = 2131492889; @@ -4985,9 +4985,6 @@ namespace BookAStar.Droid // aapt resource value: 0x7f0c0053 public const int title_template = 2131492947; - // aapt resource value: 0x7f0c00b5 - public const int toolbar = 2131493045; - // aapt resource value: 0x7f0c003d public const int top = 2131492925; diff --git a/BookAStar/BookAStar.Droid/Resources/layout/Toolbar.axml b/BookAStar/BookAStar.Droid/Resources/layout/Toolbar.axml index 8225229f..5e2b4cbb 100644 --- a/BookAStar/BookAStar.Droid/Resources/layout/Toolbar.axml +++ b/BookAStar/BookAStar.Droid/Resources/layout/Toolbar.axml @@ -1,8 +1,13 @@ - \ No newline at end of file + android:popupTheme="@style/ThemeOverlay.AppCompat.Light" + tools:context=".MainActivity" + app:layout_scrollFlags="scroll|enterAlways" +/> \ No newline at end of file diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index b0bbba9d..8f13c2ee 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -1,14 +1,8 @@ -using BookAStar.Helpers; -using BookAStar.Interfaces; +using BookAStar.Interfaces; using BookAStar.Model; -using BookAStar.Model.Workflow; using BookAStar.Pages; using BookAStar.ViewModels; using System; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; using Xamarin.Forms; using XLabs.Forms.Mvvm; using XLabs.Forms.Pages; @@ -17,6 +11,8 @@ using XLabs.Ioc; using XLabs.Platform.Mvvm; using XLabs.Platform.Services; using XLabs.Settings; +using XLabs; +using XLabs.Enums; /* Glyphish icons from @@ -56,14 +52,59 @@ namespace BookAStar return; } Configure(app); - app.Closing += (o, e) => Debug.WriteLine("Application Closing"); - app.Error += (o, e) => Debug.WriteLine("Application Error"); - app.Initialize += (o, e) => Debug.WriteLine("Application Initialized"); - app.Resumed += (o, e) => Debug.WriteLine("Application Resumed"); - app.Rotation += (o, e) => Debug.WriteLine("Application Rotated"); - app.Startup += (o, e) => Debug.WriteLine("Application Startup"); - app.Suspended += (o, e) => Debug.WriteLine("Application Suspended"); + app.Closing += OnClosing; + app.Error += OnError; + app.Initialize += OnInitialize; + app.Resumed += OnAppResumed; + app.Rotation += OnRotation; + app.Startup += OnStartup; + app.Suspended += OnSuspended; } + + // omg + private void OnError(object sender, EventArgs e) + { + + } + + // Called on rotation after OnSuspended + private void OnClosing(object sender, EventArgs e) + { + + } + + // FIXME Not called + private void OnInitialize(object sender, EventArgs e) + { + + } + + // called on app startup, not on rotation + private void OnStartup(object sender, EventArgs e) + { + // TODO special starup pages as + // notification details or wizard setup page + } + + // Called on rotation + private void OnSuspended(object sender, EventArgs e) + { + // TODO the navigation stack persistence (save) + } + + // called on app startup, after OnStartup, not on rotation + private void OnAppResumed(object sender, EventArgs e) + { + // TODO the navigation stack persistence (restore) + base.OnResume(); + } + + // FIXME Not called ... see OnSuspended + private void OnRotation(object sender, EventArgs e) + { + // TODO the navigation stack persistence (restore?) + } + public static GenericConfigSettingsMgr ConfigManager { protected set; get; } private void Configure(IXFormsApp app) @@ -84,13 +125,19 @@ namespace BookAStar public App(IPlatform instance) { + // This declaration became obsolete by introduction + // of the XLabs App that + // refers this instance with + // its application context property + // and is obtained using the `Resolver` PlatformSpecificInstance = instance; + // Xaml InitializeComponent(); + // Static properties construction Init(); + // Builds the Main page BuildMainPage(); - - NavigationPage.SetHasNavigationBar(MainPage, false); - NavigationPage.SetHasBackButton(MainPage, false); + } BookQueriesPage bQueriesPage; @@ -149,13 +196,11 @@ namespace BookAStar navPage.ToolbarItems.Add(tiSetts); */ this.MainPage = masterDetail; - Resolver.Resolve() .Register(t => new NavigationService(masterDetail.Detail.Navigation)) ; } - public void PostDeviceInfo() { var res = PlatformSpecificInstance.InvokeApi( @@ -171,7 +216,7 @@ namespace BookAStar } // TODO système de persistance de l'état de l'appli - + /* /// /// Shows a page asynchronously by locating the default constructor, creating the page, /// the pushing it onto the navigation stack. @@ -192,7 +237,7 @@ namespace BookAStar await parentPage.Navigation.PushAsync(page); break; } - } + }*/ } } diff --git a/BookAStar/BookAStar/Model/Auth/User.cs b/BookAStar/BookAStar/Model/Auth/User.cs index 78de9113..bc501e48 100644 --- a/BookAStar/BookAStar/Model/Auth/User.cs +++ b/BookAStar/BookAStar/Model/Auth/User.cs @@ -1,4 +1,5 @@ using BookAStar.Helpers; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -80,6 +81,7 @@ namespace BookAStar.Model.Auth.Account OnPropertyChanged("Avatar"); } } + [JsonIgnore] public ImageSource AvatarSource { get diff --git a/BookAStar/BookAStar/Pages/AccountChooserPage.xaml b/BookAStar/BookAStar/Pages/AccountChooserPage.xaml index 48608c3e..14d8eac2 100644 --- a/BookAStar/BookAStar/Pages/AccountChooserPage.xaml +++ b/BookAStar/BookAStar/Pages/AccountChooserPage.xaml @@ -24,7 +24,6 @@ - @@ -34,12 +33,6 @@ - - - - - - diff --git a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml index d3027868..bf4d86fe 100644 --- a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml +++ b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml @@ -15,18 +15,20 @@ + - - - - + + + + - + @@ -50,4 +51,5 @@ + \ No newline at end of file diff --git a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs index 57fe8aaa..8bba1227 100644 --- a/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs +++ b/BookAStar/BookAStar/Pages/EditEstimatePage.xaml.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using Xamarin.Forms; +using Xamarin.Forms.Internals; using XLabs.Forms.Services; using XLabs.Ioc; using XLabs.Platform.Services; @@ -28,14 +29,16 @@ namespace BookAStar.Pages { base.OnBindingContextChanged(); // FIXME WAZA - if (BindingContext != null) - mdview.Markdown = ((EstimateViewModel)BindingContext).Description; + if (BindingContext != null) { + mdview.Markdown = ((EstimateViewModel)BindingContext).Description; + } } protected void OnDescriptionChanged (object sender, EventArgs e) { // FIXME Why the Binding don't work? ((EstimateViewModel)BindingContext).Description = mdview.Markdown; + InvalidateMeasure(); } protected void OnNewCommanLine(object sender, EventArgs e) @@ -43,7 +46,7 @@ namespace BookAStar.Pages var com = new BillingLine(); Resolver.Resolve().NavigateTo( true, - new object[] { new BillingLineViewModel((Estimate)this.BindingContext,com) } ); + new object[] { new BillingLineViewModel(((EstimateViewModel)this.BindingContext).Data,com) } ); } } diff --git a/BookAStar/BookAStar/Views/MarkdownView.cs b/BookAStar/BookAStar/Views/MarkdownView.cs index 3875e68f..50417671 100644 --- a/BookAStar/BookAStar/Views/MarkdownView.cs +++ b/BookAStar/BookAStar/Views/MarkdownView.cs @@ -23,20 +23,21 @@ namespace BookAStar.Views { return markdown; } - set { + set + { if (markdown != value) - if (Edited != null) + { + markdown = value; + if (Modified != null) { - markdown = value; - Edited.Invoke(this, new EventArgs()); + Modified.Invoke(this, new EventArgs()); return; } - - markdown = value; + } } } - public event EventHandler Edited; + public event EventHandler Modified; protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint) {