diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 7a1f87148..468b158b0 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -125,8 +125,6 @@ - - diff --git a/src/Android/MainApplication.cs b/src/Android/MainApplication.cs index 0205b926d..54cdeb23f 100644 --- a/src/Android/MainApplication.cs +++ b/src/Android/MainApplication.cs @@ -127,7 +127,6 @@ namespace Bit.Android container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); @@ -137,7 +136,6 @@ namespace Bit.Android container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); // Repositories diff --git a/src/Android/Services/MemoryService.cs b/src/Android/Services/MemoryService.cs deleted file mode 100644 index bf4c30b6c..000000000 --- a/src/Android/Services/MemoryService.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using Android.Content; -using Bit.App.Abstractions; -using Plugin.CurrentActivity; -using Xamarin.Forms; - -namespace Bit.Android.Services -{ - public class MemoryService : IMemoryService - { - public MemoryInfo GetInfo() - { - return MemoryHelper.GetMemoryInfo(CrossCurrentActivity.Current.Activity); - } - - public void Check() - { - MemoryHelper.MemoryCheck(CrossCurrentActivity.Current.Activity); - } - - public static class MemoryHelper - { - public static void MemoryCheck(Context context) - { - Console.WriteLine("MemoryHelper.MemoryCheck.{0} - {1}", "Start", context.ToString()); - var maxMemory = Java.Lang.Runtime.GetRuntime().MaxMemory(); - var freeMemory = Java.Lang.Runtime.GetRuntime().FreeMemory(); - var percentUsed = (maxMemory - freeMemory) / (double)maxMemory; - Console.WriteLine("Free memory: {0:N}", freeMemory); - Console.WriteLine("Max memory: {0:N}", maxMemory); - Console.WriteLine("% used: {0:P}", percentUsed); - Console.WriteLine("MemoryHelper.MemoryCheck.{0} {3:P} {1} out of {2}", "End", freeMemory, maxMemory, percentUsed); - } - - public static MemoryInfo GetMemoryInfo(Context context) - { - var retVal = new MemoryInfo(); - retVal.MaxMemory = Java.Lang.Runtime.GetRuntime().MaxMemory(); - retVal.FreeMemory = Java.Lang.Runtime.GetRuntime().FreeMemory(); - retVal.TotalMemory = Java.Lang.Runtime.GetRuntime().TotalMemory(); - return retVal; - } - } - } -} diff --git a/src/Android/Services/ReflectionService.cs b/src/Android/Services/ReflectionService.cs deleted file mode 100644 index 4685f4c13..000000000 --- a/src/Android/Services/ReflectionService.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Reflection; -using Bit.App.Abstractions; -using Bit.App.Controls; -using Xamarin.Forms; - -namespace Bit.Android.Services -{ - public class ReflectionService : IReflectionService - { - public Func GetVisualElementOnSizeRequest(ExtendedTableView tableView) - { - var handle = typeof(VisualElement).GetMethod( - "OnSizeRequest", - BindingFlags.Instance | BindingFlags.NonPublic, - null, - new Type[] { typeof(double), typeof(double) }, - null)?.MethodHandle; - - if(!handle.HasValue) - { - throw new ArgumentNullException("handle could not be found."); - } - - var pointer = handle.Value.GetFunctionPointer(); - if(pointer == null) - { - throw new ArgumentNullException("pointer could not be found."); - } - - return (Func)Activator.CreateInstance(typeof(Func), tableView, pointer); - } - } -} diff --git a/src/App/Abstractions/Services/IMemoryService.cs b/src/App/Abstractions/Services/IMemoryService.cs deleted file mode 100644 index 5f5c939e9..000000000 --- a/src/App/Abstractions/Services/IMemoryService.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Bit.App.Abstractions -{ - public interface IMemoryService - { - MemoryInfo GetInfo(); - void Check(); - } - - public class MemoryInfo - { - public long FreeMemory { get; set; } - public long MaxMemory { get; set; } - public long TotalMemory { get; set; } - public long UsedMemory => TotalMemory - FreeMemory; - - public double HeapUsage() - { - return UsedMemory / (double)TotalMemory; - } - - public double Usage() - { - return UsedMemory / (double)MaxMemory; - } - } -} diff --git a/src/App/Abstractions/Services/IReflectionService.cs b/src/App/Abstractions/Services/IReflectionService.cs deleted file mode 100644 index eae6232a8..000000000 --- a/src/App/Abstractions/Services/IReflectionService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Bit.App.Controls; -using Xamarin.Forms; - -namespace Bit.App.Abstractions -{ - public interface IReflectionService - { - Func GetVisualElementOnSizeRequest(ExtendedTableView tableView); - } -} diff --git a/src/App/Controls/ExtendedTableView.cs b/src/App/Controls/ExtendedTableView.cs index e300b19a6..0c646f739 100644 --- a/src/App/Controls/ExtendedTableView.cs +++ b/src/App/Controls/ExtendedTableView.cs @@ -1,6 +1,8 @@ using Xamarin.Forms; using XLabs.Ioc; using Bit.App.Abstractions; +using System; +using System.Reflection; namespace Bit.App.Controls { @@ -45,12 +47,35 @@ namespace Bit.App.Controls { if(!VerticalOptions.Expands && Device.RuntimePlatform != Device.UWP) { - var reflectionService = Resolver.Resolve(); - var baseBaseOnSizeRequest = reflectionService.GetVisualElementOnSizeRequest(this); - return baseBaseOnSizeRequest(widthConstraint, heightConstraint); + var baseOnSizeRequest = GetVisualElementOnSizeRequest(); + return baseOnSizeRequest(widthConstraint, heightConstraint); } return base.OnSizeRequest(widthConstraint, heightConstraint); } + + private Func GetVisualElementOnSizeRequest() + { + var handle = typeof(VisualElement).GetMethod( + "OnSizeRequest", + BindingFlags.Instance | BindingFlags.NonPublic, + null, + new Type[] { typeof(double), typeof(double) }, + null)?.MethodHandle; + + if(!handle.HasValue) + { + throw new ArgumentNullException("handle could not be found."); + } + + var pointer = handle.Value.GetFunctionPointer(); + if(pointer == null) + { + throw new ArgumentNullException("pointer could not be found."); + } + + return (Func)Activator.CreateInstance( + typeof(Func), this, pointer); + } } } diff --git a/src/App/Controls/MemoryContentView.cs b/src/App/Controls/MemoryContentView.cs deleted file mode 100644 index b6d34e25d..000000000 --- a/src/App/Controls/MemoryContentView.cs +++ /dev/null @@ -1,108 +0,0 @@ -using Bit.App.Abstractions; -using System; -using Xamarin.Forms; -using XLabs.Ioc; - -namespace Bit.App.Controls -{ - public class MemoryContentView : ContentView - { - private readonly IMemoryService _memoryService; - - public MemoryContentView() - { - _memoryService = Resolver.Resolve(); - - var grid = new Grid - { - Padding = 5, - BackgroundColor = Color.White, - RowDefinitions = new RowDefinitionCollection - { - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto }, - new RowDefinition { Height = GridLength.Auto } - }, - ColumnDefinitions = new ColumnDefinitionCollection - { - new ColumnDefinition { Width = GridLength.Star }, - new ColumnDefinition { Width = GridLength.Star } - } - }; - - grid.Children.Add(new Label { Text = "Used Memory:" }, 0, 0); - grid.Children.Add(new Label { Text = "Free Memory:" }, 0, 1); - grid.Children.Add(new Label { Text = "Heap Memory:" }, 0, 2); - grid.Children.Add(new Label { Text = "Max Memory:" }, 0, 3); - grid.Children.Add(new Label { Text = "% Used Heap:" }, 0, 4); - grid.Children.Add(new Label { Text = "% Used Max:" }, 0, 5); - - UsedMemory = new Label { Text = "Used Memory:", HorizontalTextAlignment = TextAlignment.End }; - FreeMemory = new Label { Text = "Free Memory:", HorizontalTextAlignment = TextAlignment.End }; - HeapMemory = new Label { Text = "Heap Memory:", HorizontalTextAlignment = TextAlignment.End }; - MaxMemory = new Label { Text = "Max Memory:", HorizontalTextAlignment = TextAlignment.End }; - HeapUsage = new Label { Text = "% Used Heap:", HorizontalTextAlignment = TextAlignment.End }; - TotalUsage = new Label { Text = "% Used Max:", HorizontalTextAlignment = TextAlignment.End }; - - grid.Children.Add(UsedMemory, 1, 0); - grid.Children.Add(FreeMemory, 1, 1); - grid.Children.Add(HeapMemory, 1, 2); - grid.Children.Add(MaxMemory, 1, 3); - grid.Children.Add(HeapUsage, 1, 4); - grid.Children.Add(TotalUsage, 1, 5); - - var button = new ExtendedButton { Text = "Refresh", BackgroundColor = Color.Transparent }; - button.Clicked += Button_Clicked; - grid.Children.Add(button, 0, 6); - Grid.SetColumnSpan(button, 2); - - Content = grid; - - RefreshScreen(); - } - - private void Button_Clicked(object sender, EventArgs e) - { - RefreshScreen(); - } - - public Label UsedMemory { get; set; } - public Label FreeMemory { get; set; } - public Label HeapMemory { get; set; } - public Label MaxMemory { get; set; } - public Label HeapUsage { get; set; } - public Label TotalUsage { get; set; } - - void RefreshScreen() - { - UsedMemory.Text = FreeMemory.Text = HeapMemory.Text = MaxMemory.Text = - HeapUsage.Text = TotalUsage.Text = string.Empty; - - UsedMemory.TextColor = FreeMemory.TextColor = HeapMemory.TextColor = - MaxMemory.TextColor = HeapUsage.TextColor = TotalUsage.TextColor = Color.Black; - - if(_memoryService != null) - { - var info = _memoryService.GetInfo(); - if(info != null) - { - UsedMemory.Text = string.Format("{0:N} mb", Math.Round(info.UsedMemory / 1024 / 1024D, 2)); - FreeMemory.Text = string.Format("{0:N} mb", Math.Round(info.FreeMemory / 1024 / 1024D, 2)); - HeapMemory.Text = string.Format("{0:N} mb", Math.Round(info.TotalMemory / 1024 / 1024D, 2)); - MaxMemory.Text = string.Format("{0:N} mb", Math.Round(info.MaxMemory / 1024 / 1024D, 2)); - HeapUsage.Text = string.Format("{0:P}", info.HeapUsage()); - TotalUsage.Text = string.Format("{0:P}", info.Usage()); - - if(info.Usage() > 0.8) - { - FreeMemory.TextColor = UsedMemory.TextColor = TotalUsage.TextColor = Color.Red; - } - } - } - } - } -} diff --git a/src/UWP/App.xaml.cs b/src/UWP/App.xaml.cs index 9a0472516..8c5f82e18 100644 --- a/src/UWP/App.xaml.cs +++ b/src/UWP/App.xaml.cs @@ -114,7 +114,6 @@ namespace Bit.UWP container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); // Repositories container.RegisterSingleton(); diff --git a/src/UWP/Services/ReflectionService.cs b/src/UWP/Services/ReflectionService.cs deleted file mode 100644 index d1d47f83c..000000000 --- a/src/UWP/Services/ReflectionService.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Reflection; -using Bit.App.Abstractions; -using Bit.App.Controls; -using Xamarin.Forms; - -namespace Bit.UWP.Services -{ - public class ReflectionService : IReflectionService - { - public Func GetVisualElementOnSizeRequest(ExtendedTableView tableView) - { - // TODO - throw new NotImplementedException(); - } - } -} diff --git a/src/UWP/UWP.csproj b/src/UWP/UWP.csproj index 10df3653e..74692f481 100644 --- a/src/UWP/UWP.csproj +++ b/src/UWP/UWP.csproj @@ -106,7 +106,6 @@ - diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 9d34bd7cf..29cf40e07 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -249,7 +249,6 @@ namespace Bit.iOS container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); diff --git a/src/iOS/Services/ReflectionService.cs b/src/iOS/Services/ReflectionService.cs deleted file mode 100644 index 142721485..000000000 --- a/src/iOS/Services/ReflectionService.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Reflection; -using Bit.App.Abstractions; -using Bit.App.Controls; -using Xamarin.Forms; - -namespace Bit.iOS.Services -{ - public class ReflectionService : IReflectionService - { - public Func GetVisualElementOnSizeRequest(ExtendedTableView tableView) - { - var handle = typeof(VisualElement).GetMethod( - "OnSizeRequest", - BindingFlags.Instance | BindingFlags.NonPublic, - null, - new Type[] { typeof(double), typeof(double) }, - null)?.MethodHandle; - - if(!handle.HasValue) - { - throw new ArgumentNullException("handle could not be found."); - } - - var pointer = handle.Value.GetFunctionPointer(); - if(pointer == null) - { - throw new ArgumentNullException("pointer could not be found."); - } - - return (Func)Activator.CreateInstance(typeof(Func), tableView, pointer); - } - } -} diff --git a/src/iOS/iOS.csproj b/src/iOS/iOS.csproj index f20ccbe0b..9b60de8f4 100644 --- a/src/iOS/iOS.csproj +++ b/src/iOS/iOS.csproj @@ -238,7 +238,6 @@ -