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 Bit.iOS.Extension.Models;
using UIKit; using UIKit;
using XLabs.Ioc; using XLabs.Ioc;
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
using Foundation; using Foundation;
using MobileCoreServices; using MobileCoreServices;
using Bit.App.Abstractions;
using Bit.iOS.Core.Utilities;
using Bit.App.Resources;
namespace Bit.iOS.Extension namespace Bit.iOS.Extension
{ {
public partial class LockPinViewController : UIViewController public partial class LockPinViewController : UIViewController
{ {
private ISettings _settings; private ISettings _settings;
private IAuthService _authService;
public LockPinViewController(IntPtr handle) : base(handle) public LockPinViewController(IntPtr handle) : base(handle)
{ } { }
@ -27,14 +31,53 @@ namespace Bit.iOS.Extension
public override void ViewDidLoad() public override void ViewDidLoad()
{ {
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_authService = Resolver.Resolve<IAuthService>();
View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f); View.BackgroundColor = new UIColor(red: 0.94f, green: 0.94f, blue: 0.96f, alpha: 1.0f);
var descriptor = UIFontDescriptor.PreferredBody; var descriptor = UIFontDescriptor.PreferredBody;
PinLabel.Font = UIFont.FromName("Courier", descriptor.PointSize * 1.3f);
PinTextField.ValueChanged += PinTextField_ValueChanged;
base.ViewDidLoad(); 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) partial void CancelButton_Activated(UIBarButtonItem sender)
{ {
CompleteRequest(); CompleteRequest();

View file

@ -16,11 +16,19 @@ namespace Bit.iOS.Extension
{ {
[Outlet] [Outlet]
[GeneratedCode ("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
UIKit.UIBarButtonItem CancelButton { get; set; } UIBarButtonItem CancelButton { get; set; }
[Action("CancelButton_Activated:")] [Outlet]
[GeneratedCode("iOS Designer", "1.0")] [GeneratedCode ("iOS Designer", "1.0")]
partial void CancelButton_Activated(UIKit.UIBarButtonItem sender); UILabel PinLabel { get; set; }
[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 () void ReleaseDesignerOutlets ()
{ {
@ -28,6 +36,14 @@ namespace Bit.iOS.Extension
CancelButton.Dispose (); CancelButton.Dispose ();
CancelButton = null; CancelButton = null;
} }
if (PinLabel != null) {
PinLabel.Dispose ();
PinLabel = null;
}
if (PinTextField != null) {
PinTextField.Dispose ();
PinTextField = null;
}
} }
} }
} }

View file

@ -40,7 +40,7 @@
<objects> <objects>
<navigationController definesPresentationContext="YES" id="64" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="64" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="67" translucent="NO" hidden="YES"> <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"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</navigationBar> </navigationBar>
<connections> <connections>
@ -57,7 +57,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="oCZ-GQ-aOK" sceneMemberID="viewController"> <navigationController automaticallyAdjustsScrollViewInsets="NO" id="oCZ-GQ-aOK" sceneMemberID="viewController">
<toolbarItems/> <toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="8A5-AR-QHS" translucent="NO"> <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"/> <autoresizingMask key="autoresizingMask"/>
<textAttributes key="titleTextAttributes"> <textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
@ -78,7 +78,7 @@
<navigationController definesPresentationContext="YES" id="1845" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="1845" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="1848" translucent="NO"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="1848" translucent="NO">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <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"> <textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
</textAttributes> </textAttributes>
@ -203,7 +203,7 @@
<navigationController definesPresentationContext="YES" id="4574" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="4574" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="4577" translucent="NO"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="4577" translucent="NO">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <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"/> <color key="barTintColor" colorSpace="calibratedRGB" red="0.23529411764705882" green="0.55294117647058827" blue="0.73725490196078436" alpha="1"/>
<textAttributes key="titleTextAttributes"> <textAttributes key="titleTextAttributes">
<color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/> <color key="textColor" colorSpace="calibratedWhite" white="1" alpha="1"/>
@ -301,7 +301,7 @@
<navigationController definesPresentationContext="YES" id="6512" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="6512" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6515"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="6515">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <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> </navigationBar>
<connections> <connections>
<segue destination="6514" kind="relationship" relationship="rootViewController" id="6513"/> <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"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <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> </view>
<navigationItem key="navigationItem" title="Verify PIN" id="6803"> <navigationItem key="navigationItem" title="Verify PIN" id="6803">
<barButtonItem key="leftBarButtonItem" id="6804" title="Cancel"> <barButtonItem key="leftBarButtonItem" id="6804" title="Cancel">
@ -376,6 +400,8 @@
</navigationItem> </navigationItem>
<connections> <connections>
<outlet property="CancelButton" destination="6804" id="name-outlet-6804"/> <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> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6813" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="6813" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -387,7 +413,7 @@
<navigationController definesPresentationContext="YES" id="6815" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="6815" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6817"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="6817">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <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> </navigationBar>
<connections> <connections>
<segue destination="6802" kind="relationship" relationship="rootViewController" id="6816"/> <segue destination="6802" kind="relationship" relationship="rootViewController" id="6816"/>
@ -430,7 +456,7 @@
<navigationController definesPresentationContext="YES" id="6855" sceneMemberID="viewController"> <navigationController definesPresentationContext="YES" id="6855" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6857"> <navigationBar key="navigationBar" contentMode="scaleToFill" id="6857">
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <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> </navigationBar>
<connections> <connections>
<segue destination="6842" kind="relationship" relationship="rootViewController" id="6856"/> <segue destination="6842" kind="relationship" relationship="rootViewController" id="6856"/>

View file

@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel;
using Bit.iOS.Controls; using Bit.iOS.Controls;
using UIKit; using UIKit;
using Xamarin.Forms; using Xamarin.Forms;
@ -16,10 +17,37 @@ namespace Bit.iOS.Controls
var view = e.NewElement as Label; var view = e.NewElement as Label;
if(Control != null && view != null) if(Control != null && view != null)
{ {
var descriptor = UIFontDescriptor.PreferredBody; UpdateFont();
var pointSize = descriptor.PointSize; }
}
var size = view.FontSize; 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))) if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
{ {
pointSize *= 1.3f; pointSize *= 1.3f;
@ -33,8 +61,7 @@ namespace Bit.iOS.Controls
pointSize *= .6f; pointSize *= .6f;
} }
Control.Font = UIFont.FromDescriptor(descriptor, pointSize); Control.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize);
}
} }
} }
} }