diff --git a/Blog/Base.lproj/Main.storyboard b/Blog/Base.lproj/Main.storyboard index 04efa97..ff7f586 100644 --- a/Blog/Base.lproj/Main.storyboard +++ b/Blog/Base.lproj/Main.storyboard @@ -2,6 +2,7 @@ + @@ -57,8 +58,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. @@ -68,44 +122,35 @@ - - - - + + - + + - - - - - - + + + @@ -335,6 +380,10 @@ + + + + diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index 0ece4af..112e434 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -18,7 +18,9 @@ @property (nonatomic, weak) IBOutlet UILabel *titleView; @property (nonatomic, weak) IBOutlet UITextView *textView; @property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewTopConstraint; -@property (nonatomic, weak) IBOutlet UILabel *linkLabel; +@property (nonatomic, weak) IBOutlet UIView *linkView; +@property (nonatomic, weak) IBOutlet UIButton *linkButton; +@property (nonatomic, weak) IBOutlet UIButton *removeLinkButton; @property (nonatomic, weak) IBOutlet UIToolbar *toolbar; @property (nonatomic, weak) IBOutlet UIBarButtonItem *publishBarButtonItem; @property (strong, nonatomic) Post *modifiedPost; @@ -52,20 +54,22 @@ - (void)configureLinkView { NSURL *url = self.modifiedPost.url; - if (url) { - self.linkLabel.text = url.absoluteString; - self.linkLabel.alpha = 0; - [UIView animateWithDuration:0.3 animations:^{ - self.linkLabel.alpha = 1; - self.textViewTopConstraint.constant = CGRectGetMaxY(self.linkLabel.frame) + 4; - }]; + if (url || [self pasteboardHasLink]) { + NSString *title = url ? url.absoluteString : @"Add Link from Pasteboard"; + [self.linkButton setTitle:title forState:UIControlStateNormal]; + self.removeLinkButton.hidden = !url; + if (self.textViewTopConstraint.constant <= FLT_EPSILON) { + self.linkView.alpha = 0; + [UIView animateWithDuration:0.3 animations:^{ + self.linkView.alpha = 1; + self.textViewTopConstraint.constant = CGRectGetMaxY(self.linkView.frame); + }]; + } } - else { + else if (self.textViewTopConstraint.constant > FLT_EPSILON) { [UIView animateWithDuration:0.3 animations:^{ - self.linkLabel.alpha = 0; + self.linkView.alpha = 0; self.textViewTopConstraint.constant = 0; - } completion:^(BOOL finished) { - self.linkLabel.text = nil; }]; } } @@ -99,6 +103,9 @@ - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(savePost) name:UIApplicationWillResignActiveNotification object:nil]; + if ([self pasteboardHasLink]) { + [self configureLinkView]; + } } - (void)viewWillDisappear:(BOOL)animated { @@ -257,51 +264,22 @@ #pragma mark - Link management -- (IBAction)presentLinkActionSheet:(id)sender { - if (self.presentedViewController) { - return; - } - +- (IBAction)tappedLinkButton:(id)sender { NSURL *currentURL = self.modifiedPost.url; - - // If nothing to add or remove, then don't present the action sheet. - if (!currentURL && ![self pasteboardHasLink]) { - [self showAlertWithTitle:@"No Link Found" message:@"Copy a link to the pasteboard to add it."]; - return; - } - - UIAlertController *menuController = [UIAlertController alertControllerWithTitle:nil message:currentURL.absoluteString preferredStyle:UIAlertControllerStyleActionSheet]; - - // Cancel - [menuController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { - [self dismissViewControllerAnimated:YES completion:nil]; - }]]; - - // Add/Replace from Pasteboard - NSString *addVerb = self.modifiedPost.link ? @"Replace" : @"Add"; - if ([self pasteboardHasLink]) { - NSString *title = [NSString stringWithFormat:@"%@ from Pasteboard", addVerb]; - __weak __typeof__(self) welf = self; - [menuController addAction:[UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - __typeof__(self) self = welf; - [self dismissViewControllerAnimated:YES completion:^{ - [self addLinkFromPasteboard]; - }]; - }]]; - } - - // Remove Link if (currentURL) { - __weak __typeof__(self) welf = self; - [menuController addAction:[UIAlertAction actionWithTitle:@"Remove Link" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - __typeof__(self) self = welf; - [self dismissViewControllerAnimated:YES completion:^{ - [self updatePostURL:nil]; - }]; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TODO" message:@"show a web browser" preferredStyle:UIAlertControllerStyleAlert]; + [alertController addAction:[UIAlertAction actionWithTitle:@"Dismiss" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [self dismissViewControllerAnimated:YES completion:nil]; }]]; + [self presentViewController:alertController animated:YES completion:nil]; } + else { + [self addLinkFromPasteboard]; + } +} - [self presentViewController:menuController animated:YES completion:nil]; +- (IBAction)removeLink:(id)sender { + [self updatePostURL:nil]; } - (BOOL)pasteboardHasLink { diff --git a/Blog/Images.xcassets/Close.imageset/Contents.json b/Blog/Images.xcassets/Close.imageset/Contents.json new file mode 100644 index 0000000..eac90e6 --- /dev/null +++ b/Blog/Images.xcassets/Close.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "close-60@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x", + "filename" : "close-60@3x.png" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Blog/Images.xcassets/Close.imageset/close-60@2x.png b/Blog/Images.xcassets/Close.imageset/close-60@2x.png new file mode 100644 index 0000000..de91f7b Binary files /dev/null and b/Blog/Images.xcassets/Close.imageset/close-60@2x.png differ diff --git a/Blog/Images.xcassets/Close.imageset/close-60@3x.png b/Blog/Images.xcassets/Close.imageset/close-60@3x.png new file mode 100644 index 0000000..5f727e5 Binary files /dev/null and b/Blog/Images.xcassets/Close.imageset/close-60@3x.png differ diff --git a/Blog/Images.xcassets/Link.imageset/Contents.json b/Blog/Images.xcassets/Link.imageset/Contents.json new file mode 100644 index 0000000..e155ffa --- /dev/null +++ b/Blog/Images.xcassets/Link.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "link-67@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x", + "filename" : "link-67@3x.png" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Blog/Images.xcassets/Link.imageset/link-67@2x.png b/Blog/Images.xcassets/Link.imageset/link-67@2x.png new file mode 100644 index 0000000..4f970fb Binary files /dev/null and b/Blog/Images.xcassets/Link.imageset/link-67@2x.png differ diff --git a/Blog/Images.xcassets/Link.imageset/link-67@3x.png b/Blog/Images.xcassets/Link.imageset/link-67@3x.png new file mode 100644 index 0000000..7e78d11 Binary files /dev/null and b/Blog/Images.xcassets/Link.imageset/link-67@3x.png differ diff --git a/close.pxm b/close.pxm new file mode 100644 index 0000000..51fb5e7 Binary files /dev/null and b/close.pxm differ diff --git a/link.pxm b/link.pxm new file mode 100644 index 0000000..f512216 Binary files /dev/null and b/link.pxm differ