Mhurd has uploaded a new change for review. https://gerrit.wikimedia.org/r/134974
Change subject: Added save button to share menu - hooked it up too. ...................................................................... Added save button to share menu - hooked it up too. Change-Id: I6bf18ac4d4a60fe76bef74e3a5de450ade3b6146 --- M Wikipedia.xcodeproj/project.pbxproj M wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m A wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.h A wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.m M wikipedia/en.lproj/Localizable.strings M wikipedia/qqq.lproj/Localizable.strings 6 files changed, 142 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/74/134974/1 diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index 1b165ef..93b09ae 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 042A5B36192591520095E172 /* TopMenuTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 042A5B31192591520095E172 /* TopMenuTextField.m */; }; 042A5B37192591520095E172 /* TopMenuLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 042A5B33192591520095E172 /* TopMenuLabel.m */; }; 042A5B38192591520095E172 /* TopMenuButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 042A5B35192591520095E172 /* TopMenuButtonView.m */; }; + 042B3996192EAEEA0066B270 /* ShareMenuSavePageActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 042B3995192EAEEA0066B270 /* ShareMenuSavePageActivity.m */; }; 0433542218A023FE009305F0 /* UIViewController+HideKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = 0433542118A023FE009305F0 /* UIViewController+HideKeyboard.m */; }; 0433542618A093C5009305F0 /* UIView+RemoveConstraints.m in Sources */ = {isa = PBXBuildFile; fileRef = 0433542518A093C5009305F0 /* UIView+RemoveConstraints.m */; }; 043C668A18BE9A8E00580E9B /* PreviewWikiTextOp.m in Sources */ = {isa = PBXBuildFile; fileRef = 043C668918BE9A8E00580E9B /* PreviewWikiTextOp.m */; }; @@ -231,6 +232,8 @@ 042A5B33192591520095E172 /* TopMenuLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopMenuLabel.m; sourceTree = "<group>"; }; 042A5B34192591520095E172 /* TopMenuButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopMenuButtonView.h; sourceTree = "<group>"; }; 042A5B35192591520095E172 /* TopMenuButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopMenuButtonView.m; sourceTree = "<group>"; }; + 042B3994192EAEEA0066B270 /* ShareMenuSavePageActivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareMenuSavePageActivity.h; sourceTree = "<group>"; }; + 042B3995192EAEEA0066B270 /* ShareMenuSavePageActivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShareMenuSavePageActivity.m; sourceTree = "<group>"; }; 0433542018A023FE009305F0 /* UIViewController+HideKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+HideKeyboard.h"; sourceTree = "<group>"; }; 0433542118A023FE009305F0 /* UIViewController+HideKeyboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+HideKeyboard.m"; sourceTree = "<group>"; }; 0433542418A093C5009305F0 /* UIView+RemoveConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+RemoveConstraints.h"; sourceTree = "<group>"; }; @@ -717,6 +720,8 @@ 042A5B2B19253E690095E172 /* BottomMenuViewController.m */, 04B162EF19284A6F00B1ABC2 /* BottomMenuContainerView.h */, 04B162F019284A6F00B1ABC2 /* BottomMenuContainerView.m */, + 042B3994192EAEEA0066B270 /* ShareMenuSavePageActivity.h */, + 042B3995192EAEEA0066B270 /* ShareMenuSavePageActivity.m */, ); path = Bottom; sourceTree = "<group>"; @@ -1538,6 +1543,7 @@ 048A26701905E55B00395F53 /* PreviewChoicesMenuView.m in Sources */, 04992BC418B6971F00A6C22B /* SearchThumbUrlsOp.m in Sources */, 044BD6B618849AD000FFE4BE /* SectionEditorViewController.m in Sources */, + 042B3996192EAEEA0066B270 /* ShareMenuSavePageActivity.m in Sources */, 04D34DAB1863D2D600610A87 /* TFHpple.m in Sources */, 0429301018604898002A13FC /* SavedPagesViewController.m in Sources */, 044213D4191D70E9006C03BF /* BundledJson.m in Sources */, diff --git a/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m b/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m index b5df308..37a043e 100644 --- a/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m +++ b/wikipedia/View Controllers/Navigation/Bottom/BottomMenuViewController.m @@ -15,6 +15,7 @@ #import "UIView+TemporaryAnimatedXF.h" #import "NSString+Extras.h" #import "Article+Convenience.h" +#import "ShareMenuSavePageActivity.h" typedef NS_ENUM(NSInteger, BottomMenuItemTag) { BOTTOM_MENU_BUTTON_UNKNOWN = 0, @@ -127,16 +128,18 @@ return; } + ShareMenuSavePageActivity *shareMenuSavePageActivity = [[ShareMenuSavePageActivity alloc] init]; + UIActivityViewController *shareActivityViewController = [[UIActivityViewController alloc] initWithActivityItems: @[title, desktopURL] - applicationActivities: @[]]; + applicationActivities: @[shareMenuSavePageActivity]]; [self presentViewController:shareActivityViewController animated:YES completion:^{ }]; [shareActivityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) { - + NSLog(@"activityType = %@", activityType); }]; } diff --git a/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.h b/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.h new file mode 100644 index 0000000..b4194d6 --- /dev/null +++ b/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.h @@ -0,0 +1,8 @@ +// Created by Monte Hurd on 5/22/14. +// Copyright (c) 2014 Wikimedia Foundation. Provided under MIT-style license; please copy and modify! + +#import <UIKit/UIKit.h> + +@interface ShareMenuSavePageActivity : UIActivity + +@end diff --git a/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.m b/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.m new file mode 100644 index 0000000..b0d387e --- /dev/null +++ b/wikipedia/View Controllers/Navigation/Bottom/ShareMenuSavePageActivity.m @@ -0,0 +1,116 @@ +// Created by Monte Hurd on 5/22/14. +// Copyright (c) 2014 Wikimedia Foundation. Provided under MIT-style license; please copy and modify! + +#import "ShareMenuSavePageActivity.h" +#import "WikipediaAppUtils.h" +#import "UINavigationController+Alert.h" + +@implementation ShareMenuSavePageActivity + ++ (UIActivityCategory)activityCategory +{ + return UIActivityCategoryAction; +} + +- (NSString *)activityType +{ + return @"wikipedia.app.savearticle"; +} + +- (NSString *)activityTitle +{ + return MWLocalizedString(@"share-menu-save-page", nil); +} + +- (UIImage *)getIconImage +{ + CGRect rect = CGRectMake(0, 0, 50, 50); + + UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); + + // get the context for CoreGraphics + CGContextRef ctx = UIGraphicsGetCurrentContext(); + + [self drawStarInContext: ctx + withNumberOfPoints: 5 + center: CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)) + innerRadius: 8 + outerRadius: 20 + fillColor: [UIColor clearColor] + strokeColor: [UIColor blackColor] + strokeWidth: 1.0]; + + // make image out of bitmap context + UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext(); + + // free the context + UIGraphicsEndImageContext(); + + return retImage; +} + +// Star Drawing! From: http://stackoverflow.com/a/18456212/135557 +- (void)drawStarInContext:(CGContextRef)context withNumberOfPoints:(NSInteger)points center:(CGPoint)center innerRadius:(CGFloat)innerRadius outerRadius:(CGFloat)outerRadius fillColor:(UIColor *)fill strokeColor:(UIColor *)stroke strokeWidth:(CGFloat)strokeWidth { + CGFloat arcPerPoint = 2.0f * M_PI / points; + CGFloat theta = M_PI / 2.0f; + + // Move to starting point (tip at 90 degrees on outside of star) + CGPoint pt = CGPointMake(center.x - (outerRadius * cosf(theta)), center.y - (outerRadius * sinf(theta))); + CGContextMoveToPoint(context, pt.x, pt.y); + + for (int i = 0; i < points; i = i + 1) { + // Calculate next inner point (moving clockwise), accounting for crossing of 0 degrees + theta = theta - (arcPerPoint / 2.0f); + if (theta < 0.0f) { + theta = theta + (2 * M_PI); + } + pt = CGPointMake(center.x - (innerRadius * cosf(theta)), center.y - (innerRadius * sinf(theta))); + CGContextAddLineToPoint(context, pt.x, pt.y); + + // Calculate next outer point (moving clockwise), accounting for crossing of 0 degrees + theta = theta - (arcPerPoint / 2.0f); + if (theta < 0.0f) { + theta = theta + (2 * M_PI); + } + pt = CGPointMake(center.x - (outerRadius * cosf(theta)), center.y - (outerRadius * sinf(theta))); + CGContextAddLineToPoint(context, pt.x, pt.y); + } + CGContextClosePath(context); + CGContextSetLineWidth(context, strokeWidth); + [fill setFill]; + [stroke setStroke]; + CGContextDrawPath(context, kCGPathFillStroke); +} + +- (UIImage *)activityImage +{ + UIImage *starImage = [self getIconImage]; + return starImage; +} + +- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems +{ + return YES; +} + +- (void)prepareWithActivityItems:(NSArray *)activityItems +{ + +} + +- (UIViewController *)activityViewController +{ + return nil; +} + +- (void)performActivity +{ + [[NSNotificationCenter defaultCenter] postNotificationName:@"SavePage" object:self userInfo:nil]; + + [NAV showAlert:MWLocalizedString(@"share-menu-page-saved", nil)]; + [NAV fadeAlert]; + + [self activityDidFinish:YES]; +} + +@end diff --git a/wikipedia/en.lproj/Localizable.strings b/wikipedia/en.lproj/Localizable.strings index ae19526..ce78ebb 100644 --- a/wikipedia/en.lproj/Localizable.strings +++ b/wikipedia/en.lproj/Localizable.strings @@ -122,3 +122,6 @@ "credits-gerrit-repo" = "App main (Gerrit)"; "credits-github-mirror" = "App mirror (GitHub)"; "credits-external-libraries" = "External"; + +"share-menu-save-page" = "Save Page"; +"share-menu-page-saved" = "Page Saved"; diff --git a/wikipedia/qqq.lproj/Localizable.strings b/wikipedia/qqq.lproj/Localizable.strings index 58bb95e..b30fee3 100644 --- a/wikipedia/qqq.lproj/Localizable.strings +++ b/wikipedia/qqq.lproj/Localizable.strings @@ -111,3 +111,7 @@ "credits-github-mirror" = "Text for item linking to the app's mirrored GitHub repository"; "credits-external-libraries" = "Title for area of credits page showing external open source libraries used by app.\n{{Identical|External}}"; "language-button-other-languages" = "Label for 'other languages' button in content area. Button also shows the number of available languages, but an indeterminate plural should be used here."; +"share-menu-save-page" = "Button text for saving current page from the share menu"; +"share-menu-page-saved" = "Alert text shown when page saved"; + + -- To view, visit https://gerrit.wikimedia.org/r/134974 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6bf18ac4d4a60fe76bef74e3a5de450ade3b6146 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits