Brion VIBBER has submitted this change and it was merged.

Change subject: Made search keyboard use 'Go' button.
......................................................................


Made search keyboard use 'Go' button.

If article with exact title as search term is in the search
results, the Go button will load that article. If no exact
match, it will load the first article in the search results.

Change-Id: Ia250d9f5e20bc411f7fc3b3d1c9e5bdaa2f77fd7
---
M wikipedia/View Controllers/Navigation/Top/TopMenuViewController.m
M wikipedia/View Controllers/SearchResults/SearchResultsController.h
M wikipedia/View Controllers/SearchResults/SearchResultsController.m
3 files changed, 40 insertions(+), 4 deletions(-)

Approvals:
  Brion VIBBER: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikipedia/View Controllers/Navigation/Top/TopMenuViewController.m 
b/wikipedia/View Controllers/Navigation/Top/TopMenuViewController.m
index bfd1fc2..03a9dff 100644
--- a/wikipedia/View Controllers/Navigation/Top/TopMenuViewController.m
+++ b/wikipedia/View Controllers/Navigation/Top/TopMenuViewController.m
@@ -205,7 +205,7 @@
     self.textFieldContainer = [[TopMenuTextFieldContainer alloc] 
initWithMargin:textFieldContainerMargin];
     self.textFieldContainer.translatesAutoresizingMaskIntoConstraints = NO;
     self.textFieldContainer.textField.delegate = self;
-    self.textFieldContainer.textField.returnKeyType = UIReturnKeyDone;
+    self.textFieldContainer.textField.returnKeyType = UIReturnKeyGo;
     self.textFieldContainer.textField.autocorrectionType = 
UITextAutocorrectionTypeNo;
     self.textFieldContainer.textField.font = SEARCH_TEXT_FIELD_FONT;
     self.textFieldContainer.textField.textColor = 
SEARCH_TEXT_FIELD_HIGHLIGHTED_COLOR;
@@ -661,6 +661,10 @@
 
 - (BOOL)textFieldShouldReturn:(UITextField *)textField
 {
+    if (self.navBarMode == NAVBAR_MODE_SEARCH) {
+        [self.searchResultsController doneTapped];
+    }
+
     [self hideKeyboard];
     return YES;
 }
diff --git a/wikipedia/View Controllers/SearchResults/SearchResultsController.h 
b/wikipedia/View Controllers/SearchResults/SearchResultsController.h
index c43bb0f..33f5e8b 100644
--- a/wikipedia/View Controllers/SearchResults/SearchResultsController.h
+++ b/wikipedia/View Controllers/SearchResults/SearchResultsController.h
@@ -12,5 +12,6 @@
 -(void)search;
 -(void)clearSearchResults;
 -(void)saveSearchTermToRecentList;
+-(void)doneTapped;
 
 @end
diff --git a/wikipedia/View Controllers/SearchResults/SearchResultsController.m 
b/wikipedia/View Controllers/SearchResults/SearchResultsController.m
index bd02189..a112470 100644
--- a/wikipedia/View Controllers/SearchResults/SearchResultsController.m
+++ b/wikipedia/View Controllers/SearchResults/SearchResultsController.m
@@ -24,6 +24,7 @@
 #import "WikiDataShortDescriptionFetcher.h"
 #import "SearchMessageLabel.h"
 #import "RecentSearchesViewController.h"
+#import "NSArray+Predicate.h"
 
 @interface SearchResultsController (){
     CGFloat scrollViewDragBeganVerticalOffset_;
@@ -457,15 +458,20 @@
 
 - (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    [self saveSearchTermToRecentList];
+    [self hideKeyboard];
 
     NSString *title = self.searchResults[indexPath.row][@"title"];
+
+    [self loadArticleWithTitle:title];
+}
+
+-(void)loadArticleWithTitle:(NSString *)title
+{
+    [self saveSearchTermToRecentList];
 
     // Set CurrentArticleTitle so web view knows what to load.
     title = [title wikiTitleWithoutUnderscores];
     
-    [self hideKeyboard];
-
     [NAV loadArticleWithTitle: [MWPageTitle titleWithString:title]
                        domain: [SessionSingleton sharedInstance].domain
                      animated: YES
@@ -474,6 +480,21 @@
                    popToWebVC: YES];
 }
 
+-(void)doneTapped
+{
+    if(self.searchResults.count == 0) return;
+
+    // If there is an exact match in the search results for the current search 
term,
+    // load that article.
+    if ([self perfectSearchStringTitleMatchFoundInSearchResults]){
+        [self loadArticleWithTitle:self.searchString];
+    }else{
+        // Else load title of first result.
+        NSDictionary *firstItem = self.searchResults.firstObject;
+        if (firstItem[@"title"]) [self 
loadArticleWithTitle:firstItem[@"title"]];
+    }
+}
+
 -(void)saveSearchTermToRecentList
 {
     [self.recentSearchesViewController saveTerm: self.searchString
@@ -481,6 +502,16 @@
                                            type: 
self.searchTypeMenu.searchType];
 }
 
+-(BOOL)perfectSearchStringTitleMatchFoundInSearchResults
+{
+    if(self.searchResults.count == 0) return NO;
+    id perfectMatch =
+        [self.searchResults firstMatchForPredicate:[NSPredicate 
predicateWithFormat:@"(title == %@)", self.searchString]];
+    
+    BOOL perfectMatchFound = perfectMatch ? YES : NO;
+    return perfectMatchFound;
+}
+
 #pragma mark Memory
 
 - (void)didReceiveMemoryWarning

-- 
To view, visit https://gerrit.wikimedia.org/r/174066
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia250d9f5e20bc411f7fc3b3d1c9e5bdaa2f77fd7
Gerrit-PatchSet: 2
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mhurd <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to