From 54652e639b7363e8499116c71fd35d88c062f885 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 18 May 2016 23:55:30 -0400 Subject: [PATCH] positioning. extended switch cell. --- src/Android/Android.csproj | 1 + .../Controls/ExtendedSwitchCellRenderer.cs | 42 +++++++++++++++++++ src/App/App.csproj | 1 + src/App/Controls/ExtendedSwitchCell.cs | 16 +++++++ src/App/Controls/FormEntryCell.cs | 3 +- src/App/Controls/FormPickerCell.cs | 3 +- src/App/Controls/LabeledValueCell.cs | 2 +- src/App/Pages/SettingsPage.cs | 24 ++++++----- .../Controls/ExtendedSwitchCellRenderer.cs | 25 +++++++++++ src/iOS/iOS.csproj | 1 + 10 files changed, 103 insertions(+), 15 deletions(-) create mode 100644 src/Android/Controls/ExtendedSwitchCellRenderer.cs create mode 100644 src/App/Controls/ExtendedSwitchCell.cs create mode 100644 src/iOS/Controls/ExtendedSwitchCellRenderer.cs diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj index 2fc4a5038..8564acf68 100644 --- a/src/Android/Android.csproj +++ b/src/Android/Android.csproj @@ -197,6 +197,7 @@ + diff --git a/src/Android/Controls/ExtendedSwitchCellRenderer.cs b/src/Android/Controls/ExtendedSwitchCellRenderer.cs new file mode 100644 index 000000000..e091e5d34 --- /dev/null +++ b/src/Android/Controls/ExtendedSwitchCellRenderer.cs @@ -0,0 +1,42 @@ +using Android.Content; +using System.ComponentModel; +using Android.Views; +using Bit.Android.Controls; +using Bit.App.Controls; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; +using AView = Android.Views.View; + +[assembly: ExportRenderer(typeof(ExtendedSwitchCell), typeof(ExtendedSwitchCellRenderer))] +namespace Bit.Android.Controls +{ + public class ExtendedSwitchCellRenderer : SwitchCellRenderer + { + protected AView View { get; private set; } + + protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context) + { + var View = base.GetCellCore(item, convertView, parent, context); + var extendedCell = (ExtendedSwitchCell)item; + + if(View != null) + { + View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid()); + } + + return View; + } + + protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args) + { + base.OnCellPropertyChanged(sender, args); + + var cell = (ExtendedSwitchCell)Cell; + + if(args.PropertyName == ExtendedSwitchCell.BackgroundColorProperty.PropertyName) + { + View.SetBackgroundColor(cell.BackgroundColor.ToAndroid()); + } + } + } +} diff --git a/src/App/App.csproj b/src/App/App.csproj index fcb66e696..4f15384fc 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -52,6 +52,7 @@ + diff --git a/src/App/Controls/ExtendedSwitchCell.cs b/src/App/Controls/ExtendedSwitchCell.cs new file mode 100644 index 000000000..513495dfa --- /dev/null +++ b/src/App/Controls/ExtendedSwitchCell.cs @@ -0,0 +1,16 @@ +using Xamarin.Forms; + +namespace Bit.App.Controls +{ + public class ExtendedSwitchCell : SwitchCell + { + public static readonly BindableProperty BackgroundColorProperty = + BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedSwitchCell), Color.White); + + public Color BackgroundColor + { + get { return (Color)GetValue(BackgroundColorProperty); } + set { SetValue(BackgroundColorProperty, value); } + } + } +} diff --git a/src/App/Controls/FormEntryCell.cs b/src/App/Controls/FormEntryCell.cs index 73e6ffed3..c1c3e4b4d 100644 --- a/src/App/Controls/FormEntryCell.cs +++ b/src/App/Controls/FormEntryCell.cs @@ -18,8 +18,7 @@ namespace Bit.App.Controls { Keyboard = entryKeyboard, HasBorder = false, - VerticalOptions = LayoutOptions.CenterAndExpand, - Margin = new Thickness(0, 5, 0, 0) + VerticalOptions = LayoutOptions.CenterAndExpand }; var stackLayout = new StackLayout diff --git a/src/App/Controls/FormPickerCell.cs b/src/App/Controls/FormPickerCell.cs index d5e65c815..b6574681b 100644 --- a/src/App/Controls/FormPickerCell.cs +++ b/src/App/Controls/FormPickerCell.cs @@ -19,8 +19,7 @@ namespace Bit.App.Controls Picker = new ExtendedPicker { HasBorder = false, - VerticalOptions = LayoutOptions.CenterAndExpand, - Margin = new Thickness(0, 5, 0, 0) + VerticalOptions = LayoutOptions.CenterAndExpand }; foreach(var item in pickerItems) diff --git a/src/App/Controls/LabeledValueCell.cs b/src/App/Controls/LabeledValueCell.cs index d7db9eba6..45e2df161 100644 --- a/src/App/Controls/LabeledValueCell.cs +++ b/src/App/Controls/LabeledValueCell.cs @@ -40,7 +40,7 @@ namespace Bit.App.Controls Text = valueText, LineBreakMode = LineBreakMode.TailTruncation, VerticalOptions = LayoutOptions.CenterAndExpand, - Margin = new Thickness(0, 5, 0, 0) + TextColor = Color.FromHex("333333") }; labelValueStackLayout.Children.Add(Value); diff --git a/src/App/Pages/SettingsPage.cs b/src/App/Pages/SettingsPage.cs index 75ef7109c..ce64de6bd 100644 --- a/src/App/Pages/SettingsPage.cs +++ b/src/App/Pages/SettingsPage.cs @@ -23,40 +23,44 @@ namespace Bit.App.Pages private void Init() { - var touchIdCell = new SwitchCell + var touchIdCell = new ExtendedSwitchCell { Text = "Use Touch ID" }; - touchIdCell.Tapped += TouchIdCell_Tapped; + touchIdCell.OnChanged += TouchIdCell_Changed; - var lockOnExitCell = new SwitchCell + var lockOnExitCell = new ExtendedSwitchCell { Text = "Lock Immediately On Exit" }; - lockOnExitCell.Tapped += LockOnExitCell_Tapped; + lockOnExitCell.OnChanged += LockOnExitCell_Changed; var changeMasterPasswordCell = new ExtendedTextCell { - Text = "Change Master Password" + Text = "Change Master Password", + TextColor = Color.FromHex("333333") }; changeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped; var foldersCell = new ExtendedTextCell { Text = "Folders", - ShowDisclousure = true + ShowDisclousure = true, + TextColor = Color.FromHex("333333") }; foldersCell.Tapped += FoldersCell_Tapped; var lockCell = new ExtendedTextCell { - Text = "Lock" + Text = "Lock", + TextColor = Color.FromHex("333333") }; lockCell.Tapped += LockCell_Tapped; var logOutCell = new ExtendedTextCell { - Text = "Log Out" + Text = "Log Out", + TextColor = Color.FromHex("333333") }; logOutCell.Tapped += LogOutCell_Tapped; @@ -109,7 +113,7 @@ namespace Bit.App.Pages Application.Current.MainPage = new LoginNavigationPage(); } - private void LockOnExitCell_Tapped(object sender, EventArgs e) + private void LockOnExitCell_Changed(object sender, EventArgs e) { } @@ -124,7 +128,7 @@ namespace Bit.App.Pages Device.OpenUri(new Uri("https://vault.bitwarden.com")); } - private void TouchIdCell_Tapped(object sender, EventArgs e) + private void TouchIdCell_Changed(object sender, EventArgs e) { } diff --git a/src/iOS/Controls/ExtendedSwitchCellRenderer.cs b/src/iOS/Controls/ExtendedSwitchCellRenderer.cs new file mode 100644 index 000000000..1a5b5ece8 --- /dev/null +++ b/src/iOS/Controls/ExtendedSwitchCellRenderer.cs @@ -0,0 +1,25 @@ +using Bit.App.Controls; +using Bit.iOS.Controls; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(ExtendedSwitchCell), typeof(ExtendedSwitchCellRenderer))] +namespace Bit.iOS.Controls +{ + public class ExtendedSwitchCellRenderer : SwitchCellRenderer + { + public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) + { + var extendedCell = (ExtendedSwitchCell)item; + var cell = base.GetCell(item, reusableCell, tv); + + if(cell != null) + { + cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor(); + } + + return cell; + } + } +} diff --git a/src/iOS/iOS.csproj b/src/iOS/iOS.csproj index f3e4d97fc..bf7f45cf9 100644 --- a/src/iOS/iOS.csproj +++ b/src/iOS/iOS.csproj @@ -102,6 +102,7 @@ +