jenkins-bot has submitted this change and it was merged.
Change subject: Add search suggestions to 5.0
......................................................................
Add search suggestions to 5.0
T105023
Added delegate call back to recent searches
Added recent searches as sub-VC of search VC
Change-Id: I4683f382647846049e6a7c722f977aefd93aa279
---
M Wikipedia/UI-V5/WMFSearchViewController.m
M Wikipedia/UI-V5/iPhone_Root.storyboard
M Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.h
M Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.m
M Wikipedia/View Controllers/SearchResults/SearchResultsController.m
5 files changed, 147 insertions(+), 25 deletions(-)
Approvals:
Mhurd: Looks good to me, but someone else must approve
Bgerstle: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Wikipedia/UI-V5/WMFSearchViewController.m
b/Wikipedia/UI-V5/WMFSearchViewController.m
index 1ca94ba..43a699c 100644
--- a/Wikipedia/UI-V5/WMFSearchViewController.m
+++ b/Wikipedia/UI-V5/WMFSearchViewController.m
@@ -1,5 +1,6 @@
#import "WMFSearchViewController.h"
+#import "RecentSearchesViewController.h"
#import "WMFArticleListCollectionViewController.h"
#import "WMFSearchFetcher.h"
@@ -13,11 +14,15 @@
static NSUInteger const kWMFMinResultsBeforeAutoFullTextSearch = 12;
-@interface WMFSearchViewController ()
+@interface WMFSearchViewController ()<WMFRecentSearchesViewControllerDelegate>
+
+@property (nonatomic, strong) RecentSearchesViewController*
recentSearchesViewController;
@property (nonatomic, strong) WMFArticleListCollectionViewController*
resultsListController;
+
@property (strong, nonatomic) IBOutlet UISearchBar* searchBar;
@property (strong, nonatomic) IBOutlet UIButton* searchSuggestionButton;
@property (strong, nonatomic) IBOutlet UIView* resultsListContainerView;
+@property (strong, nonatomic) IBOutlet UIView* recentSearchesContainerView;
@property (nonatomic, strong) WMFSearchFetcher* fetcher;
@@ -60,6 +65,14 @@
[self.delegate searchController:self searchStateDidChange:self.state];
}
+- (void)updateRecentSearchesVisibility {
+ if ([self.searchBar.text length] == 0 && [self.searchBar isFirstResponder]
&& self.recentSearchesViewController.recentSearchesItemCount > 0) {
+ [self.recentSearchesContainerView setHidden:NO];
+ } else {
+ [self.recentSearchesContainerView setHidden:YES];
+ }
+}
+
#pragma mark - DataSource KVO
- (void)observeSavedPages {
@@ -85,12 +98,18 @@
if ([segue.destinationViewController
isKindOfClass:[WMFArticleListCollectionViewController class]]) {
self.resultsListController = segue.destinationViewController;
}
+ if ([segue.destinationViewController
isKindOfClass:[RecentSearchesViewController class]]) {
+ self.recentSearchesViewController =
segue.destinationViewController;
+ self.recentSearchesViewController.delegate = self;
+ }
}
#pragma mark - UISearchBarDelegate
- (void)searchBarTextDidBeginEditing:(UISearchBar*)searchBar {
[self updateSearchStateAndNotifyDelegate:WMFSearchStateActive];
+
+ [self updateRecentSearchesVisibility];
[self.searchBar setShowsCancelButton:YES animated:YES];
@@ -102,6 +121,12 @@
}
- (void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString*)searchText {
+ [self updateRecentSearchesVisibility];
+
+ if ([searchText length] == 0) {
+ self.resultsListController.dataSource = nil;
+ }
+
dispatchOnMainQueueAfterDelayInSeconds(0.4, ^{
if ([searchText isEqualToString:self.searchBar.text]) {
[self searchForSearchTerm:searchText];
@@ -110,12 +135,15 @@
}
- (void)searchBarTextDidEndEditing:(UISearchBar*)searchBar {
+ [self updateRecentSearchesVisibility];
}
- (void)searchBarSearchButtonClicked:(UISearchBar*)searchBar {
+ [self updateRecentSearchesVisibility];
}
- (void)searchBarCancelButtonClicked:(UISearchBar*)searchBar {
+ [self updateRecentSearchesVisibility];
[self updateSearchStateAndNotifyDelegate:WMFSearchStateInactive];
self.searchBar.text = nil;
self.resultsListController.dataSource = nil;
@@ -141,7 +169,10 @@
return [AnyPromise promiseWithValue:results];
}).then(^(WMFSearchResults* results){
- self.resultsListController.dataSource = results;
+ if ([searchTerm isEqualToString:results.searchTerm]) {
+ self.resultsListController.dataSource = results;
+ [self.recentSearchesViewController saveTerm:searchTerm
forDomain:self.fetcher.searchSite.domain type:SEARCH_TYPE_TITLES];
+ }
}).catch(^(NSError* error){
NSLog(@"%@", [error description]);
});
@@ -178,6 +209,16 @@
}
}
+#pragma mark - WMFRecentSearchesViewControllerDelegate
+
+- (void)recentSearchController:(RecentSearchesViewController*)controller
didSelectSearchTerm:(NSString*)searchTerm {
+ self.searchBar.text = searchTerm;
+ [self searchForSearchTerm:searchTerm];
+ [self updateRecentSearchesVisibility];
+}
+
+#pragma mark - Actions
+
- (IBAction)searchForSuggestion:(id)sender {
self.searchBar.text = [self searchSuggestion];
[UIView animateWithDuration:0.25 animations:^{
diff --git a/Wikipedia/UI-V5/iPhone_Root.storyboard
b/Wikipedia/UI-V5/iPhone_Root.storyboard
index a7ce4ca..8357c6e 100644
--- a/Wikipedia/UI-V5/iPhone_Root.storyboard
+++ b/Wikipedia/UI-V5/iPhone_Root.storyboard
@@ -138,33 +138,53 @@
<action selector="searchForSuggestion:"
destination="tkf-8P-b2O" eventType="touchUpInside" id="0Md-vC-UXr"/>
</connections>
</button>
+ <containerView opaque="NO"
contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO"
id="tpe-pb-Bgw">
+ <rect key="frame" x="0.0" y="44" width="600"
height="536"/>
+ <animations/>
+ <connections>
+ <segue destination="Rqy-g9-mNA"
kind="embed" id="B6d-7Y-a0q"/>
+ </connections>
+ </containerView>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1"
colorSpace="calibratedWhite"/>
<constraints>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="top" secondItem="ZNj-Jo-URc" secondAttribute="bottom"
id="22F-ec-9qm"/>
<constraint firstItem="ukX-0p-5ey"
firstAttribute="top" secondItem="ZNj-Jo-URc" secondAttribute="bottom"
constant="4" id="32n-FT-n9y"/>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="top" secondItem="Ia7-49-Gwu" secondAttribute="top"
id="3ic-NB-X3K"/>
<constraint firstAttribute="centerY"
secondItem="ZNj-Jo-URc" secondAttribute="centerY" id="7um-O6-iBm"/>
<constraint firstItem="Ia7-49-Gwu"
firstAttribute="leading" secondItem="xp5-j8-6jN" secondAttribute="leading"
id="AdT-tS-YIU"/>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="leading" secondItem="Ia7-49-Gwu" secondAttribute="leading"
id="Crb-uF-hEq"/>
<constraint firstItem="ZNj-Jo-URc"
firstAttribute="top" secondItem="CKX-gH-RjL" secondAttribute="bottom"
id="HTd-6H-IdL"/>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="leading" secondItem="xp5-j8-6jN" secondAttribute="leading"
id="Jdl-JP-8BM"/>
+ <constraint firstItem="8Yb-zt-F5o"
firstAttribute="top" secondItem="tpe-pb-Bgw" secondAttribute="bottom"
id="ONj-Ah-ZWd"/>
<constraint firstAttribute="trailing"
secondItem="Ia7-49-Gwu" secondAttribute="trailing" id="PnC-FC-Xud"/>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="bottom" secondItem="Ia7-49-Gwu" secondAttribute="bottom"
id="T0N-dg-3ZT"/>
<constraint firstItem="Ia7-49-Gwu"
firstAttribute="top" secondItem="ZNj-Jo-URc" secondAttribute="bottom"
id="VR7-y0-CDG"/>
<constraint firstItem="8Yb-zt-F5o"
firstAttribute="top" secondItem="Ia7-49-Gwu" secondAttribute="bottom"
id="XlJ-cb-ymV"/>
<constraint firstAttribute="centerX"
secondItem="ZNj-Jo-URc" secondAttribute="centerX" id="cxv-4Q-C8N"/>
<constraint firstItem="Ia7-49-Gwu"
firstAttribute="top" secondItem="ukX-0p-5ey" secondAttribute="bottom"
constant="6" placeholder="YES" id="fdO-Tl-2cD"/>
<constraint firstAttribute="centerX"
secondItem="ukX-0p-5ey" secondAttribute="centerX" id="h5k-7F-xym"/>
+ <constraint firstAttribute="trailing"
secondItem="tpe-pb-Bgw" secondAttribute="trailing" id="k4b-zR-59u"/>
<constraint firstItem="ZNj-Jo-URc"
firstAttribute="leading" secondItem="xp5-j8-6jN" secondAttribute="leading"
id="lud-F9-Eww"/>
+ <constraint firstItem="tpe-pb-Bgw"
firstAttribute="trailing" secondItem="Ia7-49-Gwu" secondAttribute="trailing"
id="xNK-xX-osN"/>
<constraint firstAttribute="trailing"
secondItem="ZNj-Jo-URc" secondAttribute="trailing" id="zhb-KY-6d8"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="7um-O6-iBm"/>
<exclude reference="cxv-4Q-C8N"/>
+ <exclude reference="3ic-NB-X3K"/>
+ <exclude reference="Crb-uF-hEq"/>
+ <exclude reference="T0N-dg-3ZT"/>
+ <exclude reference="xNK-xX-osN"/>
<exclude reference="VR7-y0-CDG"/>
</mask>
</variation>
</view>
<toolbarItems/>
<connections>
+ <outlet property="recentSearchesContainerView"
destination="tpe-pb-Bgw" id="aD2-ul-dw2"/>
<outlet property="resultsListContainerView"
destination="Ia7-49-Gwu" id="xdS-en-9mw"/>
<outlet property="searchBar" destination="ZNj-Jo-URc"
id="Y5b-g5-7Mc"/>
<outlet property="searchSuggestionButton"
destination="ukX-0p-5ey" id="O0X-WP-Nym"/>
@@ -179,7 +199,7 @@
<objects>
<collectionViewController
storyboardIdentifier="WMFArticleListCollectionViewController"
useStoryboardIdentifierAsRestorationIdentifier="YES" id="qVm-oc-aaW"
customClass="WMFArticleListCollectionViewController"
sceneMemberID="viewController">
<collectionView key="view" clipsSubviews="YES"
multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES"
dataMode="prototypes" id="cbI-aA-luO">
- <rect key="frame" x="0.0" y="0.0" width="600"
height="536"/>
+ <rect key="frame" x="0.0" y="0.0" width="600"
height="496"/>
<autoresizingMask key="autoresizingMask"
widthSizable="YES" heightSizable="YES"/>
<animations/>
<collectionViewLayout key="collectionViewLayout"
id="OM6-RR-VUO" customClass="TGLStackedLayout"/>
@@ -224,11 +244,76 @@
</objects>
<point key="canvasLocation" x="950" y="771"/>
</scene>
+ <!--Recent Searches View Controller-->
+ <scene sceneID="MGk-Bd-HA1">
+ <objects>
+ <viewController
restorationIdentifier="RecentSearchesViewController"
storyboardIdentifier="RecentSearchesViewController" id="Rqy-g9-mNA"
customClass="RecentSearchesViewController" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="wQU-Qf-hyW"/>
+ <viewControllerLayoutGuide type="bottom"
id="U8y-aI-ssO"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="un9-Tr-mR7">
+ <rect key="frame" x="0.0" y="0.0" width="600"
height="536"/>
+ <autoresizingMask key="autoresizingMask"
widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <tableView clipsSubviews="YES"
contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes"
style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22"
sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO"
id="ka6-Dy-C8P">
+ <rect key="frame" x="0.0" y="70" width="600"
height="530"/>
+ <animations/>
+ <color key="backgroundColor" white="1"
alpha="1" colorSpace="calibratedWhite"/>
+ <connections>
+ <outlet property="dataSource"
destination="Rqy-g9-mNA" id="5go-DG-2bZ"/>
+ <outlet property="delegate"
destination="Rqy-g9-mNA" id="qWP-b9-11L"/>
+ </connections>
+ </tableView>
+ <label opaque="NO" userInteractionEnabled="NO"
contentMode="left" horizontalHuggingPriority="251"
verticalHuggingPriority="251" text="" lineBreakMode="wordWrap"
numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO"
translatesAutoresizingMaskIntoConstraints="NO" id="bGx-k7-AQ1" userLabel="Title
Label" customClass="PaddedLabel">
+ <rect key="frame" x="0.0" y="20" width="525"
height="50"/>
+ <animations/>
+ <constraints>
+ <constraint firstAttribute="height"
constant="50" placeholder="YES" id="MJn-Fv-Xfk"/>
+ </constraints>
+ <fontDescription key="fontDescription"
type="system" pointSize="17"/>
+ <color key="textColor" red="0.0" green="0.0"
blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
+ <nil key="highlightedColor"/>
+ </label>
+ <view contentMode="scaleToFill"
translatesAutoresizingMaskIntoConstraints="NO" id="7SS-UN-pgW" userLabel="Trash
Button" customClass="WikiGlyphButton">
+ <rect key="frame" x="525" y="20" width="75"
height="50"/>
+ <animations/>
+ <color key="backgroundColor" white="1"
alpha="1" colorSpace="calibratedWhite"/>
+ <constraints>
+ <constraint firstAttribute="width"
constant="75" id="1mE-o0-SnE"/>
+ </constraints>
+ </view>
+ </subviews>
+ <animations/>
+ <color key="backgroundColor" white="1" alpha="1"
colorSpace="calibratedWhite"/>
+ <constraints>
+ <constraint firstItem="U8y-aI-ssO"
firstAttribute="top" secondItem="ka6-Dy-C8P" secondAttribute="bottom"
id="0eP-KB-sYM"/>
+ <constraint firstItem="bGx-k7-AQ1"
firstAttribute="top" secondItem="wQU-Qf-hyW" secondAttribute="bottom"
id="8g7-OL-dpp"/>
+ <constraint firstItem="ka6-Dy-C8P"
firstAttribute="top" secondItem="7SS-UN-pgW" secondAttribute="bottom"
id="Hea-Em-Lo4"/>
+ <constraint firstAttribute="trailing"
secondItem="ka6-Dy-C8P" secondAttribute="trailing" id="Nxp-8p-jAo"/>
+ <constraint firstItem="bGx-k7-AQ1"
firstAttribute="leading" secondItem="un9-Tr-mR7" secondAttribute="leading"
id="Rqc-W8-ezB"/>
+ <constraint firstItem="ka6-Dy-C8P"
firstAttribute="leading" secondItem="un9-Tr-mR7" secondAttribute="leading"
id="T76-im-h7m"/>
+ <constraint firstItem="ka6-Dy-C8P"
firstAttribute="top" secondItem="bGx-k7-AQ1" secondAttribute="bottom"
id="YB4-03-c48"/>
+ <constraint firstAttribute="trailing"
secondItem="7SS-UN-pgW" secondAttribute="trailing" id="hBO-Jx-cJe"/>
+ <constraint firstItem="7SS-UN-pgW"
firstAttribute="leading" secondItem="bGx-k7-AQ1" secondAttribute="trailing"
id="hC9-Qy-49A"/>
+ <constraint firstItem="7SS-UN-pgW"
firstAttribute="top" secondItem="wQU-Qf-hyW" secondAttribute="bottom"
id="rcG-1H-QW3"/>
+ </constraints>
+ </view>
+ <connections>
+ <outlet property="headingLabel"
destination="bGx-k7-AQ1" id="jiB-LK-Nd9"/>
+ <outlet property="table" destination="ka6-Dy-C8P"
id="ONG-nR-ET1"/>
+ <outlet property="trashButton"
destination="7SS-UN-pgW" id="svA-sm-1IW"/>
+ </connections>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder"
id="Zrx-j4-pdr" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="1672" y="33"/>
+ </scene>
</scenes>
<resources>
<image name="logo-onboarding" width="210" height="192"/>
</resources>
<inferredMetricsTieBreakers>
- <segue reference="cBL-3f-yBc"/>
+ <segue reference="2dT-rC-ziD"/>
</inferredMetricsTieBreakers>
</document>
diff --git a/Wikipedia/View
Controllers/RecentSearches/RecentSearchesViewController.h b/Wikipedia/View
Controllers/RecentSearches/RecentSearchesViewController.h
index bc41bbf..959b38f 100644
--- a/Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.h
+++ b/Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.h
@@ -5,12 +5,23 @@
#import "Defines.h"
#import "SearchResultFetcher.h"
+@protocol WMFRecentSearchesViewControllerDelegate;
+
@interface RecentSearchesViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
-@property (strong, nonatomic, readonly) NSNumber* recentSearchesItemCount;
+@property (nonatomic, assign, readonly) NSUInteger recentSearchesItemCount;
+
+@property (nonatomic, weak) id<WMFRecentSearchesViewControllerDelegate>
delegate;
- (void)saveTerm:(NSString*)term
forDomain:(NSString*)domain
type:(SearchType)searchType;
@end
+
+
+@protocol WMFRecentSearchesViewControllerDelegate <NSObject>
+
+- (void)recentSearchController:(RecentSearchesViewController*)controller
didSelectSearchTerm:(NSString*)searchTerm;
+
+@end
diff --git a/Wikipedia/View
Controllers/RecentSearches/RecentSearchesViewController.m b/Wikipedia/View
Controllers/RecentSearches/RecentSearchesViewController.m
index c46875f..0a8865a 100644
--- a/Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.m
+++ b/Wikipedia/View Controllers/RecentSearches/RecentSearchesViewController.m
@@ -30,7 +30,6 @@
@property (weak, nonatomic) IBOutlet WikiGlyphButton* trashButton;
@property (strong, nonatomic) NSMutableArray* tableDataArray;
-@property (strong, nonatomic) NSNumber* recentSearchesItemCount;
@end
@@ -50,8 +49,10 @@
[self adjustConstraintsScaleForViews:@[self.headingLabel,
self.trashButton]];
[self updateTrashButtonEnabledState];
+}
- self.recentSearchesItemCount = @(self.tableDataArray.count);
+- (NSUInteger)recentSearchesItemCount {
+ return [self.tableDataArray count];
}
- (void)setupTable {
@@ -154,8 +155,6 @@
}
[self updateTrashButtonEnabledState];
-
- self.recentSearchesItemCount = @(self.tableDataArray.count);
}
- (void)loadDataArrayFromFile {
@@ -248,23 +247,9 @@
}
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
-//TODO: repair the commented out code below to work with the 5.0 search text
box.
- NSAssert(NO, @"Fix this!");
-/*
- TopMenuTextFieldContainer* textFieldContainer =
- [ROOT.topMenuViewController getNavBarItem:NAVBAR_TEXT_FIELD];
-
NSString* term = self.tableDataArray[indexPath.row][@"term"];
- textFieldContainer.textField.text = term;
- UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
- [cell animateAndRewindXF:CATransform3DMakeScale(1.025f, 1.0f, 1.0f)
- afterDelay:0.0
- duration:0.1
- then:^{
- [textFieldContainer.textField
sendActionsForControlEvents:UIControlEventEditingChanged];
- }];
- */
+ [self.delegate recentSearchController:self didSelectSearchTerm:term];
}
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView {
diff --git a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
index 66c7a3c..765ecae 100644
--- a/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
+++ b/Wikipedia/View Controllers/SearchResults/SearchResultsController.m
@@ -115,7 +115,7 @@
BOOL shouldHide = (
(self.searchString.length == 0)
&&
-
(self.recentSearchesViewController.recentSearchesItemCount.integerValue > 0)
+ (self.recentSearchesViewController.recentSearchesItemCount > 0)
) ? NO : YES;
if (self.recentSearchesContainer.hidden == shouldHide) {
--
To view, visit https://gerrit.wikimedia.org/r/224110
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4683f382647846049e6a7c722f977aefd93aa279
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: 5.0
Gerrit-Owner: Fjalapeno <[email protected]>
Gerrit-Reviewer: Bgerstle <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits