1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-17 08:43:21 +00:00

ios app extension theming

This commit is contained in:
Kyle Spearrin
2019-07-01 15:12:40 -04:00
parent 73b5d1b3f1
commit 225db6397d
26 changed files with 284 additions and 155 deletions

View File

@@ -0,0 +1,27 @@
using Bit.iOS.Core.Utilities;
using UIKit;
namespace Bit.iOS.Core.Controllers
{
public class ExtendedUITableViewCell : UITableViewCell
{
public ExtendedUITableViewCell()
{
BackgroundColor = ThemeHelpers.BackgroundColor;
if(!ThemeHelpers.LightTheme)
{
SelectionStyle = UITableViewCellSelectionStyle.None;
}
}
public ExtendedUITableViewCell(UITableViewCellStyle style, string reusedId)
: base(style, reusedId)
{
BackgroundColor = ThemeHelpers.BackgroundColor;
if(!ThemeHelpers.LightTheme)
{
SelectionStyle = UITableViewCellSelectionStyle.None;
}
}
}
}

View File

@@ -1,3 +1,4 @@
using Bit.iOS.Core.Utilities;
using System;
using UIKit;
@@ -8,5 +9,36 @@ namespace Bit.iOS.Core.Controllers
public ExtendedUITableViewController(IntPtr handle)
: base(handle)
{ }
public override void ViewWillAppear(bool animated)
{
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
base.ViewWillAppear(animated);
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
if(View != null)
{
View.BackgroundColor = ThemeHelpers.BackgroundColor;
}
if(TableView != null)
{
TableView.BackgroundColor = ThemeHelpers.BackgroundColor;
TableView.SeparatorColor = ThemeHelpers.SeparatorColor;
}
if(NavigationController?.NavigationBar != null)
{
NavigationController.NavigationBar.BarTintColor = ThemeHelpers.NavBarBackgroundColor;
NavigationController.NavigationBar.BackgroundColor = ThemeHelpers.NavBarBackgroundColor;
NavigationController.NavigationBar.TintColor = ThemeHelpers.NavBarTextColor;
NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes
{
ForegroundColor = ThemeHelpers.NavBarTextColor
};
}
}
}
}

View File

@@ -0,0 +1,25 @@
using Bit.iOS.Core.Utilities;
using System;
using UIKit;
namespace Bit.iOS.Core.Views
{
public abstract class ExtendedUITableViewSource : UITableViewSource
{
public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
{
if(headerView != null && headerView is UITableViewHeaderFooterView hv && hv.TextLabel != null)
{
hv.TextLabel.TextColor = ThemeHelpers.MutedColor;
}
}
public override void WillDisplayFooterView(UITableView tableView, UIView footerView, nint section)
{
if(footerView != null && footerView is UITableViewHeaderFooterView fv && fv.TextLabel != null)
{
fv.TextLabel.TextColor = ThemeHelpers.MutedColor;
}
}
}
}

View File

@@ -1,3 +1,4 @@
using Bit.iOS.Core.Utilities;
using System;
using UIKit;
@@ -8,5 +9,31 @@ namespace Bit.iOS.Core.Controllers
public ExtendedUIViewController(IntPtr handle)
: base(handle)
{ }
public override void ViewWillAppear(bool animated)
{
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
base.ViewWillAppear(animated);
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
if(View != null)
{
View.BackgroundColor = ThemeHelpers.BackgroundColor;
}
if(NavigationController?.NavigationBar != null)
{
NavigationController.NavigationBar.BarTintColor = ThemeHelpers.NavBarBackgroundColor;
NavigationController.NavigationBar.BackgroundColor = ThemeHelpers.NavBarBackgroundColor;
NavigationController.NavigationBar.TintColor = ThemeHelpers.NavBarTextColor;
NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes
{
ForegroundColor = ThemeHelpers.NavBarTextColor
};
}
}
}
}

View File

@@ -41,13 +41,6 @@ namespace Bit.iOS.Core.Controllers
public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell(
AppResources.MasterPassword);
public override void ViewWillAppear(bool animated)
{
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
base.ViewWillAppear(animated);
}
public override void ViewDidLoad()
{
_lockService = ServiceContainer.Resolve<ILockService>("lockService");
@@ -66,7 +59,6 @@ namespace Bit.iOS.Core.Controllers
BaseNavItem.Title = _pinLock ? AppResources.VerifyPIN : AppResources.VerifyMasterPassword;
BaseCancelButton.Title = AppResources.Cancel;
BaseSubmitButton.Title = AppResources.Submit;
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
var descriptor = UIFontDescriptor.PreferredBody;
@@ -238,7 +230,7 @@ namespace Bit.iOS.Core.Controllers
PresentViewController(alert, true, null);
}
public class TableSource : UITableViewSource
public class TableSource : ExtendedUITableViewSource
{
private LockPasswordViewController _controller;
@@ -260,13 +252,13 @@ namespace Bit.iOS.Core.Controllers
{
if(indexPath.Row == 0)
{
var cell = new UITableViewCell();
cell.TextLabel.TextColor = new UIColor(red: 0.24f, green: 0.55f, blue: 0.74f, alpha: 1.0f);
var cell = new ExtendedUITableViewCell();
cell.TextLabel.TextColor = ThemeHelpers.PrimaryColor;
cell.TextLabel.Text = AppResources.UseFingerprintToUnlock;
return cell;
}
}
return new UITableViewCell();
return new ExtendedUITableViewCell();
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)

View File

@@ -30,7 +30,7 @@ namespace Bit.iOS.Core.Controllers
public FormEntryTableViewCell NameCell { get; set; } = new FormEntryTableViewCell(AppResources.Name);
public FormEntryTableViewCell UsernameCell { get; set; } = new FormEntryTableViewCell(AppResources.Username);
public FormEntryTableViewCell PasswordCell { get; set; } = new FormEntryTableViewCell(AppResources.Password);
public UITableViewCell GeneratePasswordCell { get; set; } = new UITableViewCell(
public UITableViewCell GeneratePasswordCell { get; set; } = new ExtendedUITableViewCell(
UITableViewCellStyle.Subtitle, "GeneratePasswordCell");
public FormEntryTableViewCell UriCell { get; set; } = new FormEntryTableViewCell(AppResources.URI);
public SwitchTableViewCell FavoriteCell { get; set; } = new SwitchTableViewCell(AppResources.Favorite);
@@ -43,13 +43,6 @@ namespace Bit.iOS.Core.Controllers
public abstract UIBarButtonItem BaseSaveButton { get; }
public abstract Action Success { get; }
public override void ViewWillAppear(bool animated)
{
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
base.ViewWillAppear(animated);
}
public override void ViewDidLoad()
{
_cipherService = ServiceContainer.Resolve<ICipherService>("cipherService");
@@ -58,7 +51,7 @@ namespace Bit.iOS.Core.Controllers
BaseNavItem.Title = AppResources.AddItem;
BaseCancelButton.Title = AppResources.Cancel;
BaseSaveButton.Title = AppResources.Save;
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
View.BackgroundColor = ThemeHelpers.BackgroundColor;
NameCell.TextField.Text = Context?.Uri?.Host ?? string.Empty;
NameCell.TextField.ReturnKeyType = UIReturnKeyType.Next;
@@ -87,6 +80,8 @@ namespace Bit.iOS.Core.Controllers
};
GeneratePasswordCell.TextLabel.Text = AppResources.GeneratePassword;
GeneratePasswordCell.TextLabel.TextColor = GeneratePasswordCell.TextLabel.TintColor =
ThemeHelpers.TextColor;
GeneratePasswordCell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
UriCell.TextField.Text = Context?.UrlString ?? string.Empty;
@@ -206,7 +201,7 @@ namespace Bit.iOS.Core.Controllers
AppResources.InternetConnectionRequiredMessage, AppResources.Ok);
}
public class TableSource : UITableViewSource
public class TableSource : ExtendedUITableViewSource
{
private LoginAddViewController _controller;
@@ -256,7 +251,7 @@ namespace Bit.iOS.Core.Controllers
return _controller.NotesCell;
}
return new UITableViewCell();
return new ExtendedUITableViewCell();
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)

View File

@@ -26,9 +26,12 @@ namespace Bit.iOS.Core.Controllers
public SwitchTableViewCell LowercaseCell { get; set; } = new SwitchTableViewCell("a-z");
public SwitchTableViewCell NumbersCell { get; set; } = new SwitchTableViewCell("0-9");
public SwitchTableViewCell SpecialCell { get; set; } = new SwitchTableViewCell("!@#$%^&*");
public StepperTableViewCell MinNumbersCell { get; set; } = new StepperTableViewCell(AppResources.MinNumbers, 1, 0, 5, 1);
public StepperTableViewCell MinSpecialCell { get; set; } = new StepperTableViewCell(AppResources.MinSpecial, 1, 0, 5, 1);
public SliderTableViewCell LengthCell { get; set; } = new SliderTableViewCell(AppResources.Length, 10, 5, 64);
public StepperTableViewCell MinNumbersCell { get; set; } = new StepperTableViewCell(
AppResources.MinNumbers, 1, 0, 5, 1);
public StepperTableViewCell MinSpecialCell { get; set; } = new StepperTableViewCell(
AppResources.MinSpecial, 1, 0, 5, 1);
public SliderTableViewCell LengthCell { get; set; } = new SliderTableViewCell(
AppResources.Length, 10, 5, 64);
public PasswordGenerationOptions PasswordOptions { get; set; }
public abstract UINavigationItem BaseNavItem { get; }
@@ -36,13 +39,6 @@ namespace Bit.iOS.Core.Controllers
public abstract UIBarButtonItem BaseSelectBarButton { get; }
public abstract UILabel BasePasswordLabel { get; }
public override void ViewWillAppear(bool animated)
{
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
base.ViewWillAppear(animated);
}
public async override void ViewDidLoad()
{
_passwordGenerationService = ServiceContainer.Resolve<IPasswordGenerationService>(
@@ -51,13 +47,13 @@ namespace Bit.iOS.Core.Controllers
BaseNavItem.Title = AppResources.PasswordGenerator;
BaseCancelButton.Title = AppResources.Cancel;
BaseSelectBarButton.Title = AppResources.Select;
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
var descriptor = UIFontDescriptor.PreferredBody;
BasePasswordLabel.Font = UIFont.FromName("Menlo-Regular", descriptor.PointSize * 1.3f);
BasePasswordLabel.LineBreakMode = UILineBreakMode.TailTruncation;
BasePasswordLabel.Lines = 1;
BasePasswordLabel.AdjustsFontSizeToFitWidth = false;
BasePasswordLabel.TextColor = ThemeHelpers.TextColor;
var controller = ChildViewControllers.LastOrDefault();
if(controller != null)
@@ -71,7 +67,8 @@ namespace Bit.iOS.Core.Controllers
OptionsTableViewController.TableView.EstimatedRowHeight = 70;
OptionsTableViewController.TableView.Source = new TableSource(this);
OptionsTableViewController.TableView.AllowsSelection = true;
OptionsTableViewController.View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
OptionsTableViewController.View.BackgroundColor = ThemeHelpers.BackgroundColor;
OptionsTableViewController.TableView.SeparatorColor = ThemeHelpers.SeparatorColor;
}
var options = await _passwordGenerationService.GetOptionsAsync();
@@ -159,7 +156,8 @@ namespace Bit.iOS.Core.Controllers
private bool InvalidState()
{
return !LowercaseCell.Switch.On && !UppercaseCell.Switch.On && !NumbersCell.Switch.On && !SpecialCell.Switch.On;
return !LowercaseCell.Switch.On && !UppercaseCell.Switch.On && !NumbersCell.Switch.On &&
!SpecialCell.Switch.On;
}
private async Task GeneratePasswordAsync()
@@ -177,7 +175,7 @@ namespace Bit.iOS.Core.Controllers
});
}
public class TableSource : UITableViewSource
public class TableSource : ExtendedUITableViewSource
{
private PasswordGeneratorViewController _controller;
@@ -190,8 +188,8 @@ namespace Bit.iOS.Core.Controllers
{
if(indexPath.Section == 0)
{
var cell = new UITableViewCell();
cell.TextLabel.TextColor = new UIColor(red: 0.24f, green: 0.55f, blue: 0.74f, alpha: 1.0f);
var cell = new ExtendedUITableViewCell();
cell.TextLabel.TextColor = ThemeHelpers.PrimaryColor;
if(indexPath.Row == 0)
{
cell.TextLabel.Text = AppResources.RegeneratePassword;
@@ -232,7 +230,7 @@ namespace Bit.iOS.Core.Controllers
return _controller.MinSpecialCell;
}
return new UITableViewCell();
return new ExtendedUITableViewCell();
}
public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)