Skip to content

Commit

Permalink
Merge pull request #15 from Softeq/feature/new-release
Browse files Browse the repository at this point in the history
Feature/new release
  • Loading branch information
vadimpylsky authored Dec 18, 2018
2 parents 885b5ab + a623041 commit 3697cf7
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 116 deletions.
27 changes: 20 additions & 7 deletions Softeq.XToolkit.WhiteLabel.Droid/ActivityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,18 +74,32 @@ public abstract class ActivityBase<TViewModel> : ActivityBase
{
private const string ShouldRestoreStateKey = "shouldRestore";
private readonly IJsonSerializer _jsonSerializer;
private Lazy<TViewModel> _viewModel;
private Lazy<TViewModel> _viewModelLazy;

protected ActivityBase()
{
Bindings = new List<Binding>();
_jsonSerializer = Dependencies.JsonSerializer;
_viewModel = new Lazy<TViewModel>(() => Dependencies.IocContainer.Resolve<IBackStackManager>()
.GetExistingOrCreateViewModel<TViewModel>());
_viewModelLazy = new Lazy<TViewModel>(() =>
{
var backStack = Dependencies.IocContainer.Resolve<IBackStackManager>();
return backStack.GetExistingOrCreateViewModel<TViewModel>();
});
}

protected List<Binding> 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)
{
Expand Down Expand Up @@ -128,7 +141,7 @@ protected override void OnDestroy()
{
if (IsFinishing)
{
_viewModel = null;
_viewModelLazy = null;
base.OnDestroy();
Dispose();
}
Expand Down Expand Up @@ -197,6 +210,6 @@ public abstract class ActivityBase<TViewModel, TInterface> : ActivityBase<TViewM
private TViewModel _viewModel;

protected override TViewModel ViewModel =>
_viewModel ?? (_viewModel = (TViewModel) Dependencies.IocContainer.Resolve<TInterface>());
_viewModel ?? (_viewModel = (TViewModel)Dependencies.IocContainer.Resolve<TInterface>());
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -92,7 +110,7 @@ private float CalculateTextStartYPoint()

private float CalculateTextSize()
{
return Bounds.Height() * TextSizePercentage / 100;
return _placeholderBounds.Height() * TextSizePercentage / 100;
}

public class AvatarStyles
Expand Down
12 changes: 12 additions & 0 deletions Softeq.XToolkit.WhiteLabel.Droid/Controls/NavigationBarView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Softeq.XToolkit.WhiteLabel.Droid/Navigation/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

namespace Softeq.XToolkit.WhiteLabel.Droid.Navigation
{
public static class Constants
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Softeq.XToolkit.WhiteLabel.Droid/Navigation/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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> {type};
var typeList = new List<Type> { type };

if (typeInfo.IsInterface)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</RelativeLayout>
</merge>
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:minWidth="25px"
android:minHeight="25px"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/control_navigation_bar_container"
android:background="@drawable/core_nav_bar_background">
<ImageButton
android:layout_width="54dp"
android:layout_height="match_parent"
android:scaleType="center"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:id="@+id/control_navigation_bar_left_button"
android:background="@android:color/transparent" />
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:text="Text"
android:ellipsize="end"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CoreNavigationBarTextStyle"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:id="@+id/control_navigation_bar_title" />
<ImageView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@android:color/transparent"
android:id="@+id/control_navigation_bar_center_image" />
</RelativeLayout>
<LinearLayout
android:background="@drawable/core_nav_bar_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="54dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:scaleType="center"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:id="@+id/control_navigation_bar_right_button" />
<Button
android:layout_width="wrap_content"
android:id="@+id/control_navigation_bar_left_button"
android:background="@android:color/transparent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:text="Text"
android:ellipsize="end"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CoreNavigationBarTextStyle"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:id="@+id/control_navigation_bar_title" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_marginRight="12dp"
android:id="@+id/control_navigation_bar_right_text_button"
style="@style/CoreNavigationButtonStyle"/>
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageButton
android:layout_width="54dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:scaleType="center"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:id="@+id/control_navigation_bar_right_button" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:layout_marginRight="12dp"
android:id="@+id/control_navigation_bar_right_text_button"
style="@style/CoreNavigationButtonStyle"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@android:color/transparent"
android:id="@+id/control_navigation_bar_center_image" />
</RelativeLayout>
5 changes: 5 additions & 0 deletions Softeq.XToolkit.WhiteLabel.Droid/Resources/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<color name="core_navigation_bar_text_color">#000000</color>
<color name="core_notification_bg_color">#000000</color>
<color name="core_notification_text_color">#000000</color>
<color name="core_progress_indicator_color">#000000</color>

<style name="CoreNavigationBarTextStyle">
<item name="android:textSize">20sp</item>
Expand All @@ -22,4 +23,8 @@
<item name="android:windowAnimationStyle">@null</item>
</style>

<style name="ProgressBarStyle" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorAccent">@color/core_progress_indicator_color</item>
</style>

</resources>
Loading

0 comments on commit 3697cf7

Please sign in to comment.