1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-21 11:25:56 +01:00

Implemented funcitonality for extension pin VC. Apply size adjustments on proeprty changed for Labels.

This commit is contained in:
Kyle Spearrin 2016-07-20 20:57:00 -04:00
parent d0bf141c5d
commit 1fffeb5614
4 changed files with 157 additions and 45 deletions

View File

@ -1,16 +1,20 @@
using System;
using System;
using Bit.iOS.Extension.Models;
using UIKit;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using Foundation;
using MobileCoreServices;
using Bit.App.Abstractions;
using Bit.iOS.Core.Utilities;
using Bit.App.Resources;
namespace Bit.iOS.Extension
{
public partial class LockPinViewController : UIViewController
{
private ISettings _settings;
private IAuthService _authService;
public LockPinViewController(IntPtr handle) : base(handle)
{ }
@ -27,14 +31,53 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad()
{
_settings = Resolver.Resolve<ISettings>();
_authService = Resolver.Resolve<IAuthService>();
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
var descriptor = UIFontDescriptor.PreferredBody;
PinLabel.Font = UIFont.FromName("Courier", descriptor.PointSize * 1.3f);
PinTextField.ValueChanged += PinTextField_ValueChanged;
base.ViewDidLoad();
}
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
PinTextField.BecomeFirstResponder();
}
private void PinTextField_ValueChanged(object sender, EventArgs e)
{
var newText = string.Empty;
for(int i = 0; i < 4; i++)
{
newText += PinTextField.Text.Length <= i ? "- " : "● ";
}
PinLabel.Text = newText.TrimEnd();
if(PinTextField.Text.Length >= 4)
{
if(PinTextField.Text == _authService.PIN)
{
PinTextField.ResignFirstResponder();
DismissModalViewController(true);
}
else
{
// TODO: keep track of invalid attempts and logout?
var alert = Dialogs.CreateAlert(null, "Invalid PIN. Try again.", AppResources.Ok);
PresentViewController(alert, true, null);
PinTextField.Text = string.Empty;
PinTextField.BecomeFirstResponder();
}
}
}
partial void CancelButton_Activated(UIBarButtonItem sender)
{
CompleteRequest();

View File

@ -11,23 +11,39 @@ using UIKit;
namespace Bit.iOS.Extension
{
[Register ("LockPinViewController")]
partial class LockPinViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIBarButtonItem CancelButton { get; set; }
[Register ("LockPinViewController")]
partial class LockPinViewController
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIBarButtonItem CancelButton { get; set; }
[Action("CancelButton_Activated:")]
[GeneratedCode("iOS Designer", "1.0")]
partial void CancelButton_Activated(UIKit.UIBarButtonItem sender);
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel PinLabel { get; set; }
void ReleaseDesignerOutlets ()
{
if (CancelButton != null) {
CancelButton.Dispose ();
CancelButton = null;
}
}
}
}
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField PinTextField { get; set; }
[Action ("CancelButton_Activated:")]
[GeneratedCode ("iOS Designer", "1.0")]
partial void CancelButton_Activated (UIBarButtonItem sender);
void ReleaseDesignerOutlets ()
{
if (CancelButton != null) {
CancelButton.Dispose ();
CancelButton = null;
}
if (PinLabel != null) {
PinLabel.Dispose ();
PinLabel = null;
}
if (PinTextField != null) {
PinTextField.Dispose ();
PinTextField = null;
}
}
}
}

View File

@ -40,7 +40,7 @@
<objects>
<navigationController definesPresentationContext="YES" id="64" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="67" translucent="NO" hidden="YES">
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</navigationBar>
<connections>
@ -57,7 +57,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="oCZ-GQ-aOK" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="8A5-AR-QHS" translucent="NO">
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
@ -78,7 +78,7 @@
<navigationController definesPresentationContext="YES" id="1845" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="1848" translucent="NO">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
</textAttributes>
@ -203,7 +203,7 @@
<navigationController definesPresentationContext="YES" id="4574" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="4577" translucent="NO">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
<color key="barTintColor" colorSpace="calibratedRGB" red="0.23529411764705882" green="0.55294117647058827" blue="0.73725490196078436" alpha="1"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
@ -301,7 +301,7 @@
<navigationController definesPresentationContext="YES" id="6512" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6515">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
</navigationBar>
<connections>
<segue destination="6514" kind="relationship" relationship="rootViewController" id="6513"/>
@ -365,7 +365,31 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<subviews/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" id="7350" translatesAutoresizingMaskIntoConstraints="NO" textAlignment="center" text="- - - -">
<rect key="frame" x="30" y="84" width="540" height="60"/>
<fontDescription key="fontDescription" name="Courier-BoldOblique" family="Courier" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
<color key="backgroundColor" colorSpace="calibratedWhite" white="0" alpha="0"/>
<color key="tintColor" colorSpace="calibratedWhite" white="0" alpha="0"/>
<color key="textColor" colorSpace="calibratedWhite" white="0" alpha="0"/>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="- - - -" lineBreakMode="tailTruncation" minimumFontSize="10" id="7373" translatesAutoresizingMaskIntoConstraints="NO" textAlignment="center">
<rect key="frame" x="30" y="104" width="540" height="17"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" name="Courier" family="Courier" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint id="7351" firstItem="7350" firstAttribute="leading" secondItem="6805" secondAttribute="leading" constant="30"/>
<constraint id="7352" firstItem="6805" firstAttribute="trailing" secondItem="7350" secondAttribute="trailing" constant="30"/>
<constraint id="7353" firstItem="7350" firstAttribute="top" secondItem="6812" secondAttribute="bottom" constant="20"/>
<constraint id="7374" firstItem="7373" firstAttribute="leading" secondItem="6805" secondAttribute="leading" constant="30"/>
<constraint id="7375" firstItem="6805" firstAttribute="trailing" secondItem="7373" secondAttribute="trailing" constant="30"/>
<constraint id="7376" firstItem="7373" firstAttribute="top" secondItem="6812" secondAttribute="bottom" constant="40"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Verify PIN" id="6803">
<barButtonItem key="leftBarButtonItem" id="6804" title="Cancel">
@ -376,6 +400,8 @@
</navigationItem>
<connections>
<outlet property="CancelButton" destination="6804" id="name-outlet-6804"/>
<outlet property="PinTextField" destination="7350" id="name-outlet-7350"/>
<outlet property="PinLabel" destination="7373" id="name-outlet-7373"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6813" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -387,7 +413,7 @@
<navigationController definesPresentationContext="YES" id="6815" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6817">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
</navigationBar>
<connections>
<segue destination="6802" kind="relationship" relationship="rootViewController" id="6816"/>
@ -430,7 +456,7 @@
<navigationController definesPresentationContext="YES" id="6855" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6857">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<rect key="frame" x="0.0" y="20" width="600" height="44"/>
<rect key="frame" x="0.0" y="20" width="880" height="44"/>
</navigationBar>
<connections>
<segue destination="6842" kind="relationship" relationship="rootViewController" id="6856"/>

View File

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
@ -16,25 +17,51 @@ namespace Bit.iOS.Controls
var view = e.NewElement as Label;
if(Control != null && view != null)
{
var descriptor = UIFontDescriptor.PreferredBody;
var pointSize = descriptor.PointSize;
var size = view.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
UpdateFont();
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == Label.TextColorProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.FontProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.TextProperty.PropertyName)
{
UpdateFont();
}
else if(e.PropertyName == Label.FormattedTextProperty.PropertyName)
{
UpdateFont();
}
}
private void UpdateFont()
{
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
var size = Element.FontSize;
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
{
pointSize *= 1.3f;
}
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
{
pointSize *= .8f;
}
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Label)))
{
pointSize *= .6f;
}
Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize);
}
}
}