From eb39c7fb4b8483fa59386e46977a776b1dac0140 Mon Sep 17 00:00:00 2001 From: Yauheni Pakala Date: Tue, 18 Dec 2018 12:22:42 +0300 Subject: [PATCH 1/3] Add some fixes --- .../ActivityBase.cs | 24 +++- .../Controls/AvatarPlaceholderDrawable.cs | 30 ++++- .../Controls/NavigationBarView.cs | 12 ++ .../Resources/layout/control_busy_overlay.xml | 3 +- .../layout/control_navigation_bar.xml | 105 +++++++++--------- .../Resources/values/styles.xml | 5 + .../Softeq.XToolkit.WhiteLabel.Droid.csproj | 18 +-- .../ImagePicker/SimpleImagePicker.cs | 4 + .../Helpers/AvatarPlaceholderBuilder.cs | 6 +- .../Softeq.XToolkit.WhiteLabel.csproj | 1 - .../ViewModels/FullScreenImageViewModel.cs | 20 ++-- 11 files changed, 140 insertions(+), 88 deletions(-) diff --git a/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs b/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs index f00944122..4c7f5d525 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs @@ -75,18 +75,32 @@ public abstract class ActivityBase : ActivityBase { private const string ShouldRestoreStateKey = "shouldRestore"; private readonly IJsonSerializer _jsonSerializer; - private Lazy _viewModel; + private Lazy _viewModelLazy; protected ActivityBase() { Bindings = new List(); _jsonSerializer = Dependencies.JsonSerializer; - _viewModel = new Lazy(() => Dependencies.IocContainer.Resolve() - .GetExistingOrCreateViewModel()); + _viewModel = new Lazy(() => + { + var backStack = Dependencies.IocContainer.Resolve(); + return backStack.GetExistingOrCreateViewModel(); + }); } protected List Bindings { get; } - protected virtual TViewModel ViewModel => _viewModel.Value; + + protected virtual TViewModel ViewModel + { + get + { + if (Handle == IntPtr.Zero) + { + throw new Exception("Don't forget to detach last ViewModel bindings."); + } + return _viewModelLazy.Value; + } + } protected override void OnCreate(Bundle savedInstanceState) { @@ -128,7 +142,7 @@ protected override void OnDestroy() { if (IsFinishing) { - _viewModel = null; + _viewModelLazy = null; base.OnDestroy(); Dispose(); } diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Controls/AvatarPlaceholderDrawable.cs b/Softeq.XToolkit.WhiteLabel.Droid/Controls/AvatarPlaceholderDrawable.cs index 7439928b9..b0588b151 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Controls/AvatarPlaceholderDrawable.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/Controls/AvatarPlaceholderDrawable.cs @@ -1,9 +1,12 @@ // Developed by Softeq Development Corporation // http://www.softeq.com +using System; using System.Drawing; using Android.Graphics; using Android.Graphics.Drawables; +using Plugin.CurrentActivity; +using Softeq.XToolkit.Common.Droid.Extensions; using Softeq.XToolkit.WhiteLabel.Helpers; using Color = Android.Graphics.Color; @@ -16,7 +19,8 @@ public class AvatarPlaceholderDrawable : Drawable private readonly Paint _textPaint; private readonly Paint _backgroundPaint; private readonly string _avatarText; - + private readonly int _size; + private RectF _placeholderBounds; private float _textStartXPoint; private float _textStartYPoint; @@ -42,21 +46,35 @@ public AvatarPlaceholderDrawable(string name, AvatarStyles styles) }; _backgroundPaint.SetStyle(Paint.Style.Fill); _backgroundPaint.Color = Color.ParseColor(info.Color); + _size = Math.Min(styles.Size.Width, styles.Size.Height); } public override void Draw(Canvas canvas) { if (_placeholderBounds == null) { - _placeholderBounds = new RectF(0, 0, canvas.Width, canvas.Height); + var centerPoint = new Android.Graphics.PointF(canvas.Width / 2f, canvas.Height / 2f); + var context = CrossCurrentActivity.Current.AppContext; + var width = context.ToPixels(_size); + var sizeInPixels = new SizeF(width, width); + var x = centerPoint.X - sizeInPixels.Width / 2f; + var y = centerPoint.Y - sizeInPixels.Height / 2f; + + _placeholderBounds = new RectF( + x, + y, + x + sizeInPixels.Width, + y + sizeInPixels.Height); + SetAvatarTextValues(); } canvas.DrawCircle( - _placeholderBounds.CenterX(), - _placeholderBounds.CenterY(), - _placeholderBounds.Width() / 2, + canvas.Width / 2f, + canvas.Height / 2f, + _placeholderBounds.Width() / 2f, _backgroundPaint); + canvas.DrawText(_avatarText, _textStartXPoint, _textStartYPoint, _textPaint); } @@ -92,7 +110,7 @@ private float CalculateTextStartYPoint() private float CalculateTextSize() { - return Bounds.Height() * TextSizePercentage / 100; + return _placeholderBounds.Height() * TextSizePercentage / 100; } public class AvatarStyles diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Controls/NavigationBarView.cs b/Softeq.XToolkit.WhiteLabel.Droid/Controls/NavigationBarView.cs index ade74daa4..b84fb564b 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Controls/NavigationBarView.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/Controls/NavigationBarView.cs @@ -4,6 +4,7 @@ using System; using System.Windows.Input; using Android.Content; +using Android.Graphics.Drawables; using Android.Runtime; using Android.Util; using Android.Views; @@ -69,6 +70,17 @@ public void SetRightButton(int resourceId, ICommand command) } } + public void SetRightButton(Drawable drawable, ICommand command) + { + _rightButton.SetImageDrawable(drawable); + _rightButton.Visibility = ViewStates.Visible; + + if (command != null) + { + _rightButton.SetCommand(nameof(_rightButton.Click), command); + } + } + public void SetRightButton(string label, ICommand command) { RightTextButton.Text = label; diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_busy_overlay.xml b/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_busy_overlay.xml index 12ffb81c4..868ecd0ea 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_busy_overlay.xml +++ b/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_busy_overlay.xml @@ -12,6 +12,7 @@ android:minHeight="50dp" android:minWidth="50dp" android:indeterminate="true" - android:layout_centerInParent="true" /> + android:layout_centerInParent="true" + android:theme="@style/ProgressBarStyle" /> \ No newline at end of file diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_navigation_bar.xml b/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_navigation_bar.xml index 12aea126f..03702d259 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_navigation_bar.xml +++ b/Softeq.XToolkit.WhiteLabel.Droid/Resources/layout/control_navigation_bar.xml @@ -1,68 +1,67 @@  - - - - - - - + -