Brion VIBBER has submitted this change and it was merged. Change subject: Random articles. ......................................................................
Random articles. * mhurd asked to make Random tappable in W menu (as opposed to shake). * See PS3 for the version using shake and with W menu and Settings app backing. * See PS7 for the version supporting lower-left corner swipe + W menu tap (but not shake). Change-Id: I7f6948de527fa4dda2a00d157fd44adf02f7aaaa --- M Wikipedia-iOS.xcodeproj/project.pbxproj M Wikipedia-iOS/AppDelegate.m A Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.h A Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.m M Wikipedia-iOS/Queues/QueuesSingleton.h M Wikipedia-iOS/Queues/QueuesSingleton.m M Wikipedia-iOS/View Controllers/MainMenu/MainMenuTableViewController.m M Wikipedia-iOS/en.lproj/Localizable.strings M Wikipedia-iOS/qqq.lproj/Localizable.strings 9 files changed, 152 insertions(+), 1 deletion(-) Approvals: Mhurd: Looks good to me, but someone else must approve Brion VIBBER: Verified; Looks good to me, approved diff --git a/Wikipedia-iOS.xcodeproj/project.pbxproj b/Wikipedia-iOS.xcodeproj/project.pbxproj index 73a9f32..cd6a332 100644 --- a/Wikipedia-iOS.xcodeproj/project.pbxproj +++ b/Wikipedia-iOS.xcodeproj/project.pbxproj @@ -264,6 +264,8 @@ C9180EC518AED30C006C1DCA /* WikipediaAppUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = C9180EC318AED30C006C1DCA /* WikipediaAppUtils.m */; }; C9180EC918AED3B6006C1DCA /* ZeroConfigState.m in Sources */ = {isa = PBXBuildFile; fileRef = C9180EC818AED3B6006C1DCA /* ZeroConfigState.m */; }; C9180ECA18AED3B6006C1DCA /* ZeroConfigState.m in Sources */ = {isa = PBXBuildFile; fileRef = C9180EC818AED3B6006C1DCA /* ZeroConfigState.m */; }; + C958EE3418CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m in Sources */ = {isa = PBXBuildFile; fileRef = C958EE3318CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m */; }; + C958EE3518CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m in Sources */ = {isa = PBXBuildFile; fileRef = C958EE3318CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m */; }; C9928B8618AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.m in Sources */ = {isa = PBXBuildFile; fileRef = C9928B8518AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.m */; }; C9928B8818AD5E1000FCCA9A /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = C9928B8718AD5E1000FCCA9A /* Settings.bundle */; }; D469889518B52DA200DBE014 /* Main_iPhone.strings in Resources */ = {isa = PBXBuildFile; fileRef = D469889318B52DA200DBE014 /* Main_iPhone.strings */; }; @@ -524,6 +526,8 @@ C9180EC318AED30C006C1DCA /* WikipediaAppUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WikipediaAppUtils.m; sourceTree = "<group>"; }; C9180EC718AED3B6006C1DCA /* ZeroConfigState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZeroConfigState.h; sourceTree = "<group>"; }; C9180EC818AED3B6006C1DCA /* ZeroConfigState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZeroConfigState.m; sourceTree = "<group>"; }; + C958EE3218CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadTitlesForRandomArticlesOp.h; sourceTree = "<group>"; }; + C958EE3318CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DownloadTitlesForRandomArticlesOp.m; sourceTree = "<group>"; }; C9928B8418AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DownloadWikipediaZeroMessageOp.h; sourceTree = "<group>"; }; C9928B8518AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DownloadWikipediaZeroMessageOp.m; sourceTree = "<group>"; }; C9928B8718AD5E1000FCCA9A /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; }; @@ -940,6 +944,8 @@ 04D75823189248E900CE2040 /* DownloadLangLinksOp.m */, C9928B8418AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.h */, C9928B8518AD5C6A00FCCA9A /* DownloadWikipediaZeroMessageOp.m */, + C958EE3218CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.h */, + C958EE3318CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m */, ); path = Operations; sourceTree = "<group>"; @@ -1429,6 +1435,7 @@ 0429300E18604898002A13FC /* SavedPagesTableHeadingLabel.m in Sources */, 04D7582018923D3A00CE2040 /* ArticleLanguagesCell.m in Sources */, 0433542218A023FE009305F0 /* UIViewController+HideKeyboard.m in Sources */, + C958EE3418CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m in Sources */, 04F0E2EE186FB2D100468738 /* TOCSectionCellView.m in Sources */, 04D122321899B8AC006B9A30 /* AlertWebView.m in Sources */, D4991449181D51DE00E6073C /* AppDelegate.m in Sources */, @@ -1469,6 +1476,7 @@ D4991467181D51DF00E6073C /* Wikipedia_iOSTests.m in Sources */, 04D7582118923D3A00CE2040 /* ArticleLanguagesCell.m in Sources */, 04D34DAC1863D2D600610A87 /* TFHpple.m in Sources */, + C958EE3518CE73E600148D13 /* DownloadTitlesForRandomArticlesOp.m in Sources */, 0429301118604899002A13FC /* SavedPagesViewController.m in Sources */, 04DB0BE718BC2E1E00B4BCF3 /* CaptchaResetOp.m in Sources */, 04AE1C711891B302002D5487 /* NSObject+Extras.m in Sources */, diff --git a/Wikipedia-iOS/AppDelegate.m b/Wikipedia-iOS/AppDelegate.m index 370f2ba..9e868ae 100644 --- a/Wikipedia-iOS/AppDelegate.m +++ b/Wikipedia-iOS/AppDelegate.m @@ -39,7 +39,7 @@ // See: http://stackoverflow.com/a/5397647/135557 NSDictionary *userDefaultsDefaults = @{ @"CurrentArticleTitle": @"", - @"CurrentArticleDomain": @"", + @"CurrentArticleDomain": @"en", @"Domain": @"en", @"DomainName": @"English", @"Site": @"wikipedia.org", diff --git a/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.h b/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.h new file mode 100644 index 0000000..ca13a93 --- /dev/null +++ b/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.h @@ -0,0 +1,13 @@ +// Created by Adam Baso on 2/14/14. + +#import "MWNetworkOp.h" + +@interface DownloadTitlesForRandomArticlesOp : MWNetworkOp + +- (id)initForDomain: (NSString *)domain + completionBlock: (void (^)(NSString *title))completionBlock + cancelledBlock: (void (^)(NSError *))cancelledBlock + errorBlock: (void (^)(NSError *))errorBlock +; + +@end diff --git a/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.m b/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.m new file mode 100644 index 0000000..f589180 --- /dev/null +++ b/Wikipedia-iOS/Data/Operations/DownloadTitlesForRandomArticlesOp.m @@ -0,0 +1,64 @@ +// Created by Adam Baso on 2/14/14. + +#import "DownloadTitlesForRandomArticlesOp.h" +#import "SessionSingleton.h" +#import "NSURLRequest+DictionaryRequest.h" +#import "MWNetworkActivityIndicatorManager.h" +#import "NSString+Extras.h" + +@implementation DownloadTitlesForRandomArticlesOp + +- (id)initForDomain: (NSString *)domain + completionBlock: (void (^)(NSString *))completionBlock + cancelledBlock: (void (^)(NSError *))cancelledBlock + errorBlock: (void (^)(NSError *))errorBlock +{ + self = [super init]; + if (self) { + // FUTURE FEATURE: Get multiple titles, and cache them so they're readily available + // Will need to consider things like article language changes, though. + self.request = [NSURLRequest postRequestWithURL: [[SessionSingleton sharedInstance] urlForDomain:domain] + parameters: @{ + @"action": @"query", + @"list": @"random", + @"rnlimit": @"1", + @"rnnamespace": @"0", + @"format": @"json" + } + ]; + __weak DownloadTitlesForRandomArticlesOp *weakSelf = self; + self.aboutToStart = ^{ + [[MWNetworkActivityIndicatorManager sharedManager] push]; + }; + self.completionBlock = ^(){ + [[MWNetworkActivityIndicatorManager sharedManager] pop]; + + if(weakSelf.isCancelled){ + cancelledBlock(weakSelf.error); + return; + } + + // Check for error + if(weakSelf.jsonRetrieved[@"error"]){ + NSMutableDictionary *errorDict = [weakSelf.jsonRetrieved[@"error"] mutableCopy]; + errorDict[NSLocalizedDescriptionKey] = errorDict[@"info"]; + // Set error condition so dependent ops don't even start and so the errorBlock below will fire. + weakSelf.error = [NSError errorWithDomain:@"Random Titles Op" code:001 userInfo:errorDict]; + } + + if (weakSelf.error) { + errorBlock(weakSelf.error); + return; + } + + NSArray *randomArticles = (NSArray *)weakSelf.jsonRetrieved[@"query"][@"random"]; + NSDictionary *article = [randomArticles objectAtIndex:0]; + NSString *title = article[@"title"]; + + completionBlock(title); + }; + } + return self; +} + +@end diff --git a/Wikipedia-iOS/Queues/QueuesSingleton.h b/Wikipedia-iOS/Queues/QueuesSingleton.h index 6d93d69..991600d 100644 --- a/Wikipedia-iOS/Queues/QueuesSingleton.h +++ b/Wikipedia-iOS/Queues/QueuesSingleton.h @@ -16,6 +16,8 @@ @property (strong, nonatomic) NSOperationQueue *langLinksQ; @property (strong, nonatomic) NSOperationQueue *accountCreationQ; +@property (strong, nonatomic) NSOperationQueue *randomArticleQ; + + (QueuesSingleton *)sharedInstance; @end diff --git a/Wikipedia-iOS/Queues/QueuesSingleton.m b/Wikipedia-iOS/Queues/QueuesSingleton.m index 180f6f7..ce1f4bd 100644 --- a/Wikipedia-iOS/Queues/QueuesSingleton.m +++ b/Wikipedia-iOS/Queues/QueuesSingleton.m @@ -28,6 +28,7 @@ self.langLinksQ = [[NSOperationQueue alloc] init]; self.zeroRatedMessageStringQ = [[NSOperationQueue alloc] init]; self.accountCreationQ = [[NSOperationQueue alloc] init]; + self.randomArticleQ = [[NSOperationQueue alloc] init]; //[self setupQMonitorLogging]; } return self; diff --git a/Wikipedia-iOS/View Controllers/MainMenu/MainMenuTableViewController.m b/Wikipedia-iOS/View Controllers/MainMenu/MainMenuTableViewController.m index 479133f..7ab2fe8 100644 --- a/Wikipedia-iOS/View Controllers/MainMenu/MainMenuTableViewController.m +++ b/Wikipedia-iOS/View Controllers/MainMenu/MainMenuTableViewController.m @@ -6,6 +6,11 @@ #import "LoginViewController.h" #import "HistoryViewController.h" #import "SavedPagesViewController.h" +#import "QueuesSingleton.h" +#import "DownloadTitlesForRandomArticlesOp.h" +#import "SessionSingleton.h" +#import "WebViewController.h" +#import "UINavigationController+SearchNavStack.h" // Section indexes. #define SECTION_LOGIN_OPTIONS 0 @@ -13,6 +18,7 @@ #define SECTION_ARTICLE_OPTIONS 2 #define SECTION_SEARCH_LANGUAGE_OPTIONS 3 #define SECTION_ZERO_OPTIONS 4 +#define SECTION_RANDOM 5 // Row indexes. #define ROW_SAVED_PAGES 1 @@ -91,6 +97,12 @@ [self updateLoginTitle]; [self updateZeroToggles]; [self.tableView reloadData]; +} + +-(void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; + [[QueuesSingleton sharedInstance].randomArticleQ cancelAllOperations]; } #pragma mark - Login / logout button @@ -259,6 +271,23 @@ @"rows": [@[ ] mutableCopy] } mutableCopy] + , + + + + [@{ + @"key": @"random", + @"title": NSLocalizedString(@"main-menu-random", nil), + @"label": @"", + @"subTitle": @"", + @"rows": [@[ + [@{ + @"key": @"randomTappable", + @"title": NSLocalizedString(@"main-menu-random", nil), + @"label": @"" + } mutableCopy] + ] mutableCopy] + } mutableCopy] ] mutableCopy]; } @@ -398,6 +427,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [[QueuesSingleton sharedInstance].randomArticleQ cancelAllOperations]; NSDictionary *sectionDict = [self sectionDict:indexPath.section]; NSString *selectedSectionKey = sectionDict[@"key"]; @@ -477,6 +507,11 @@ [[SessionSingleton sharedInstance].zeroConfigState toggleDevMode]; [self updateZeroToggles]; [self.tableView reloadData]; + } else if ([selectedRowKey isEqualToString:@"randomTappable"]) { + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + // TODO: make showAlert work. mhurd on it. + // [self showAlert:NSLocalizedString(@"fetching-random-article", nil)]; + [self fetchRandomArticle]; } } @@ -613,4 +648,28 @@ return (error) ? [@[] mutableCopy]: [result mutableCopy]; } +#pragma mark - Random +-(void)fetchRandomArticle { + [[QueuesSingleton sharedInstance].randomArticleQ cancelAllOperations]; + DownloadTitlesForRandomArticlesOp *downloadTitlesForRandomArticlesOp = + [ + [DownloadTitlesForRandomArticlesOp alloc] + initForDomain: [SessionSingleton sharedInstance].domain + completionBlock: ^(NSString *title) { + if (title) { + dispatch_async(dispatch_get_main_queue(), ^(){ + [SessionSingleton sharedInstance].currentArticleTitle = title; + [SessionSingleton sharedInstance].currentArticleDomain = [SessionSingleton sharedInstance].domain; + WebViewController *webVC = [self.navigationController searchNavStackForViewControllerOfClass:[WebViewController class]]; + [self.navigationController popToViewController:webVC animated:YES]; + }); + } + } cancelledBlock:^(NSError *errorCancel) { + NSLog(@"error for Random - cancel block encountered"); + } errorBlock:^(NSError *errorError) { + NSLog(@"error for Random - error block encountered"); + }]; + [[QueuesSingleton sharedInstance].randomArticleQ addOperation:downloadTitlesForRandomArticlesOp]; +} + @end diff --git a/Wikipedia-iOS/en.lproj/Localizable.strings b/Wikipedia-iOS/en.lproj/Localizable.strings index c85d653..29317c8 100644 --- a/Wikipedia-iOS/en.lproj/Localizable.strings +++ b/Wikipedia-iOS/en.lproj/Localizable.strings @@ -64,6 +64,7 @@ "main-menu-show-history" = "My browsing history"; "main-menu-show-saved" = "My saved pages"; "main-menu-current-article-save" = "Save for offline reading"; +"main-menu-random" = "Random"; "saved-pages-title" = "Saved Pages"; @@ -82,3 +83,4 @@ "edit-summary-description" = "A specific summary for important changes helps co-editors quickly review your edits. Or you could select from the tags below."; "edit-summary-field-placeholder-text" = "How did you improve the page?"; +"fetching-random-article" = "Fetching random article"; diff --git a/Wikipedia-iOS/qqq.lproj/Localizable.strings b/Wikipedia-iOS/qqq.lproj/Localizable.strings index 0ccde02..7e1a7b6 100644 --- a/Wikipedia-iOS/qqq.lproj/Localizable.strings +++ b/Wikipedia-iOS/qqq.lproj/Localizable.strings @@ -61,6 +61,7 @@ "main-menu-show-history" = "Button text for article history interface"; "main-menu-show-saved" = "Button text for saved articles interface"; "main-menu-current-article-save" = "Button text for saving the current article"; +"main-menu-random" = "Button text for fetching a Random article"; "saved-pages-title" = "Header text for Saved Pages interface"; "navbar-title-mode-edit-wikitext" = "Header text shown when wikitext is being edited"; "navbar-title-mode-login" = "Header text shown when user is signing in"; @@ -76,4 +77,5 @@ "edit-summary-choice-add-remove-info" = "Button text for quick 'added/removed info' edit summary selection"; "edit-summary-description" = "Label text describing the edit summary interface"; "edit-summary-field-placeholder-text" = "Placeholder text which appears initially in the free-form edit summary text box"; +"fetching-random-article" = "Alert text shown when fetching a random article"; -- To view, visit https://gerrit.wikimedia.org/r/118027 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7f6948de527fa4dda2a00d157fd44adf02f7aaaa Gerrit-PatchSet: 13 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Dr0ptp4kt <ab...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dr0ptp4kt <ab...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits