[iOS] Show activity indicator during generation
This commit is contained in:
parent
9583021fa3
commit
47dfd7de4f
2 changed files with 106 additions and 59 deletions
|
@ -462,5 +462,40 @@
|
||||||
</objects>
|
</objects>
|
||||||
<point key="canvasLocation" x="1993" y="-423"/>
|
<point key="canvasLocation" x="1993" y="-423"/>
|
||||||
</scene>
|
</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>
|
</scenes>
|
||||||
</document>
|
</document>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#import "LegacyPasswordGenerator.h"
|
#import "LegacyPasswordGenerator.h"
|
||||||
|
|
||||||
@interface ShowDetailsController ()
|
@interface ShowDetailsController ()
|
||||||
- (NSMutableString*)_generate;
|
- (void)_generateWithCallback: (void(^)(NSMutableString*))block;
|
||||||
- (void)_generateAndCopy;
|
- (void)_generateAndCopy;
|
||||||
- (void)_generateAndShow;
|
- (void)_generateAndShow;
|
||||||
@end
|
@end
|
||||||
|
@ -113,8 +113,7 @@ clearNSMutableString(NSMutableString *string)
|
||||||
|
|
||||||
- (void)_generateAndCopy
|
- (void)_generateAndCopy
|
||||||
{
|
{
|
||||||
NSMutableString *password = [self _generate];
|
[self _generateWithCallback: ^ (NSMutableString *password) {
|
||||||
|
|
||||||
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
|
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
|
||||||
pasteBoard.string = password;
|
pasteBoard.string = password;
|
||||||
|
|
||||||
|
@ -122,8 +121,8 @@ clearNSMutableString(NSMutableString *string)
|
||||||
|
|
||||||
UIAlertController *alert = [UIAlertController
|
UIAlertController *alert = [UIAlertController
|
||||||
alertControllerWithTitle: @"Password Generated"
|
alertControllerWithTitle: @"Password Generated"
|
||||||
message: @"The password has been copied into the "
|
message: @"The password has been copied "
|
||||||
@"clipboard."
|
@"into the clipboard."
|
||||||
preferredStyle: UIAlertControllerStyleAlert];
|
preferredStyle: UIAlertControllerStyleAlert];
|
||||||
[alert addAction:
|
[alert addAction:
|
||||||
[UIAlertAction actionWithTitle: @"OK"
|
[UIAlertAction actionWithTitle: @"OK"
|
||||||
|
@ -135,12 +134,12 @@ clearNSMutableString(NSMutableString *string)
|
||||||
[self presentViewController: alert
|
[self presentViewController: alert
|
||||||
animated: YES
|
animated: YES
|
||||||
completion: nil];
|
completion: nil];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_generateAndShow
|
- (void)_generateAndShow
|
||||||
{
|
{
|
||||||
NSMutableString *password = [self _generate];
|
[self _generateWithCallback: ^ (NSMutableString *password) {
|
||||||
|
|
||||||
UIAlertController *alert = [UIAlertController
|
UIAlertController *alert = [UIAlertController
|
||||||
alertControllerWithTitle: @"Generated Passphrase"
|
alertControllerWithTitle: @"Generated Passphrase"
|
||||||
message: password
|
message: password
|
||||||
|
@ -149,7 +148,8 @@ clearNSMutableString(NSMutableString *string)
|
||||||
[UIAlertAction actionWithTitle: @"OK"
|
[UIAlertAction actionWithTitle: @"OK"
|
||||||
style: UIAlertActionStyleDefault
|
style: UIAlertActionStyleDefault
|
||||||
handler: ^ (UIAlertAction *action) {
|
handler: ^ (UIAlertAction *action) {
|
||||||
[self.navigationController popViewControllerAnimated: YES];
|
[self.navigationController
|
||||||
|
popViewControllerAnimated: YES];
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
[self presentViewController: alert
|
[self presentViewController: alert
|
||||||
|
@ -157,10 +157,20 @@ clearNSMutableString(NSMutableString *string)
|
||||||
completion: ^ {
|
completion: ^ {
|
||||||
clearNSMutableString(password);
|
clearNSMutableString(password);
|
||||||
}];
|
}];
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMutableString*)_generate
|
- (void)_generateWithCallback: (void(^)(NSMutableString*))block
|
||||||
{
|
{
|
||||||
|
UIStoryboard *mainStoryboard =
|
||||||
|
[UIStoryboard storyboardWithName: @"Main"
|
||||||
|
bundle: nil];
|
||||||
|
UIViewController *activityController = [mainStoryboard
|
||||||
|
instantiateViewControllerWithIdentifier: @"activityIndicator"];
|
||||||
|
[self.navigationController.view addSubview: activityController.view];
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_global_queue(
|
||||||
|
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
|
||||||
id <PasswordGenerator> generator;
|
id <PasswordGenerator> generator;
|
||||||
char *passphrase;
|
char *passphrase;
|
||||||
|
|
||||||
|
@ -188,7 +198,9 @@ clearNSMutableString(NSMutableString *string)
|
||||||
of_explicit_memset(generator.output, 0,
|
of_explicit_memset(generator.output, 0,
|
||||||
strlen((char*)generator.output));
|
strlen((char*)generator.output));
|
||||||
|
|
||||||
return password;
|
activityController.view.hidden = YES;
|
||||||
|
block(password);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)remove: (id)sender
|
- (IBAction)remove: (id)sender
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue