diff --git a/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs b/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs index f00944122..0225f1ef1 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs @@ -12,7 +12,6 @@ using Softeq.XToolkit.Bindings; using Softeq.XToolkit.Bindings.Extensions; using Softeq.XToolkit.Common.Interfaces; -using Softeq.XToolkit.Permissions; using Softeq.XToolkit.WhiteLabel.Droid.Navigation; using Softeq.XToolkit.WhiteLabel.Droid.ViewComponents; using Softeq.XToolkit.WhiteLabel.Mvvm; @@ -75,18 +74,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()); + _viewModelLazy = 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 +141,7 @@ protected override void OnDestroy() { if (IsFinishing) { - _viewModel = null; + _viewModelLazy = null; base.OnDestroy(); Dispose(); } @@ -197,6 +210,6 @@ public abstract class ActivityBase : ActivityBase - _viewModel ?? (_viewModel = (TViewModel) Dependencies.IocContainer.Resolve()); + _viewModel ?? (_viewModel = (TViewModel)Dependencies.IocContainer.Resolve()); } } \ No newline at end of file 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/Navigation/Constants.cs b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/Constants.cs index 9536a9291..58df6c199 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Navigation/Constants.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/Constants.cs @@ -1,3 +1,6 @@ +// Developed by Softeq Development Corporation +// http://www.softeq.com + namespace Softeq.XToolkit.WhiteLabel.Droid.Navigation { public static class Constants diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Navigation/RootFrameFragmentBase.cs b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/RootFrameFragmentBase.cs index 9b26c42a8..9e43d5b80 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Navigation/RootFrameFragmentBase.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/RootFrameFragmentBase.cs @@ -1,7 +1,6 @@ // Developed by Softeq Development Corporation // http://www.softeq.com -using System; using Android.OS; using Android.Views; using Softeq.XToolkit.WhiteLabel.Mvvm; diff --git a/Softeq.XToolkit.WhiteLabel.Droid/Navigation/ViewLocator.cs b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/ViewLocator.cs index 69b6c7a2b..80f9b072d 100644 --- a/Softeq.XToolkit.WhiteLabel.Droid/Navigation/ViewLocator.cs +++ b/Softeq.XToolkit.WhiteLabel.Droid/Navigation/ViewLocator.cs @@ -28,7 +28,7 @@ public object GetView(ViewModelBase viewModel, ViewType viewType) var targetType = GetTargetType(viewModel.GetType(), viewType); var inst = Activator.CreateInstance(targetType); var method = inst.GetType().GetMethod("SetExistingViewModel"); - method.Invoke(inst, new[] {viewModel}); + method.Invoke(inst, new[] { viewModel }); return inst; } @@ -37,7 +37,7 @@ public object GetView(IViewModelBase viewModel, ViewType viewType) var targetType = GetTargetType(viewModel.GetType(), viewType); var inst = Activator.CreateInstance(targetType); var method = inst.GetType().GetMethod("SetExistingViewModel"); - method.Invoke(inst, new[] {viewModel}); + method.Invoke(inst, new[] { viewModel }); return inst; } @@ -47,11 +47,11 @@ public Type GetTargetType(string viewModelTypeName, ViewType viewType) targetTypeName = targetTypeName.Replace("ViewModel", viewType.ToString()); var targeType = Type.GetType(targetTypeName) - ?? AssemblySource.FindTypeByNames(new[] {targetTypeName}); + ?? AssemblySource.FindTypeByNames(new[] { targetTypeName }); if (targeType == null) { - throw new DllNotFoundException("can't find target type"); + throw new DllNotFoundException($"Can't find target type: {targetTypeName}"); } return targeType; @@ -76,7 +76,7 @@ public void TryInjectParameters(object viewModel, object parameter, string param private PropertyInfo GetPropertyCaseInsensitive(Type type, string propertyName) { var typeInfo = type.GetTypeInfo(); - var typeList = new List {type}; + var typeList = new List { type }; if (typeInfo.IsInterface) { 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 @@  - - - - - - - + -