[iOS] Show activity indicator during generation

This commit is contained in:
Jonathan Schleifer 2016-10-10 00:32:20 +02:00
parent 9583021fa3
commit 47dfd7de4f
No known key found for this signature in database
GPG key ID: 338C3541DB54E169
2 changed files with 106 additions and 59 deletions

View file

@ -462,5 +462,40 @@
</objects>
<point key="canvasLocation" x="1993" y="-423"/>
</scene>
<!--View Controller-->
<scene sceneID="8JA-Zd-1zR">
<objects>
<viewController storyboardIdentifier="activityIndicator" id="asG-zz-a8o" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="hu7-uJ-ly6"/>
<viewControllerLayoutGuide type="bottom" id="vvJ-kn-Vjf"/>
</layoutGuides>
<view key="view" alpha="0.90000000000000002" contentMode="scaleToFill" id="c3D-Ze-5hZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="Qe7-Bk-J1n"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Generating…" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gXF-vs-Gda">
<constraints>
<constraint firstAttribute="width" constant="101" id="jwK-5C-D2D"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="darkTextColor"/>
<constraints>
<constraint firstItem="Qe7-Bk-J1n" firstAttribute="centerY" secondItem="c3D-Ze-5hZ" secondAttribute="centerY" id="9Lb-iu-cD0"/>
<constraint firstItem="Qe7-Bk-J1n" firstAttribute="centerX" secondItem="c3D-Ze-5hZ" secondAttribute="centerX" id="DYg-1r-kfn"/>
<constraint firstItem="Qe7-Bk-J1n" firstAttribute="centerX" secondItem="gXF-vs-Gda" secondAttribute="centerX" id="d15-94-nf5"/>
<constraint firstItem="gXF-vs-Gda" firstAttribute="top" secondItem="Qe7-Bk-J1n" secondAttribute="bottom" constant="8" symbolic="YES" id="n3a-cK-5jh"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="VFj-Pa-4qu" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2896.8000000000002" y="-423.23838080959524"/>
</scene>
</scenes>
</document>

View file

@ -31,7 +31,7 @@
#import "LegacyPasswordGenerator.h"
@interface ShowDetailsController ()
- (NSMutableString*)_generate;
- (void)_generateWithCallback: (void(^)(NSMutableString*))block;
- (void)_generateAndCopy;
- (void)_generateAndShow;
@end
@ -113,82 +113,94 @@ clearNSMutableString(NSMutableString *string)
- (void)_generateAndCopy
{
NSMutableString *password = [self _generate];
[self _generateWithCallback: ^ (NSMutableString *password) {
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
pasteBoard.string = password;
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
pasteBoard.string = password;
clearNSMutableString(password);
clearNSMutableString(password);
UIAlertController *alert = [UIAlertController
alertControllerWithTitle: @"Password Generated"
message: @"The password has been copied "
@"into the clipboard."
preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:
[UIAlertAction actionWithTitle: @"OK"
style: UIAlertActionStyleDefault
handler: ^ (UIAlertAction *action) {
[self.navigationController popViewControllerAnimated: YES];
}]];
UIAlertController *alert = [UIAlertController
alertControllerWithTitle: @"Password Generated"
message: @"The password has been copied into the "
@"clipboard."
preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:
[UIAlertAction actionWithTitle: @"OK"
style: UIAlertActionStyleDefault
handler: ^ (UIAlertAction *action) {
[self.navigationController popViewControllerAnimated: YES];
}]];
[self presentViewController: alert
animated: YES
completion: nil];
[self presentViewController: alert
animated: YES
completion: nil];
}];
}
- (void)_generateAndShow
{
NSMutableString *password = [self _generate];
[self _generateWithCallback: ^ (NSMutableString *password) {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle: @"Generated Passphrase"
message: password
preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:
[UIAlertAction actionWithTitle: @"OK"
style: UIAlertActionStyleDefault
handler: ^ (UIAlertAction *action) {
[self.navigationController
popViewControllerAnimated: YES];
}]];
UIAlertController *alert = [UIAlertController
alertControllerWithTitle: @"Generated Passphrase"
message: password
preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:
[UIAlertAction actionWithTitle: @"OK"
style: UIAlertActionStyleDefault
handler: ^ (UIAlertAction *action) {
[self.navigationController popViewControllerAnimated: YES];
}]];
[self presentViewController: alert
animated: YES
completion: ^ {
clearNSMutableString(password);
[self presentViewController: alert
animated: YES
completion: ^ {
clearNSMutableString(password);
}];
}];
}
- (NSMutableString*)_generate
- (void)_generateWithCallback: (void(^)(NSMutableString*))block
{
id <PasswordGenerator> generator;
char *passphrase;
UIStoryboard *mainStoryboard =
[UIStoryboard storyboardWithName: @"Main"
bundle: nil];
UIViewController *activityController = [mainStoryboard
instantiateViewControllerWithIdentifier: @"activityIndicator"];
[self.navigationController.view addSubview: activityController.view];
if (_legacy)
generator = [LegacyPasswordGenerator generator];
else
generator = [NewPasswordGenerator generator];
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
id <PasswordGenerator> generator;
char *passphrase;
generator.site = _name;
generator.length = _length;
if (_legacy)
generator = [LegacyPasswordGenerator generator];
else
generator = [NewPasswordGenerator generator];
passphrase = of_strdup([self.passphraseField.text UTF8String]);
@try {
self.passphraseField.text = @"";
generator.passphrase = passphrase;
generator.site = _name;
generator.length = _length;
[generator derivePassword];
} @finally {
of_explicit_memset(passphrase, 0, strlen(passphrase));
free(passphrase);
}
passphrase = of_strdup([self.passphraseField.text UTF8String]);
@try {
self.passphraseField.text = @"";
generator.passphrase = passphrase;
NSMutableString *password = [NSMutableString
stringWithUTF8String: (char*)generator.output];
of_explicit_memset(generator.output, 0,
strlen((char*)generator.output));
[generator derivePassword];
} @finally {
of_explicit_memset(passphrase, 0, strlen(passphrase));
free(passphrase);
}
return password;
NSMutableString *password = [NSMutableString
stringWithUTF8String: (char*)generator.output];
of_explicit_memset(generator.output, 0,
strlen((char*)generator.output));
activityController.view.hidden = YES;
block(password);
});
}
- (IBAction)remove: (id)sender