Mhurd has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/96406


Change subject: Search term now highlighted in titles of search results.
......................................................................

Search term now highlighted in titles of search results.

Change-Id: I43a785c160b42768fc70793fc92bd8c9a6853cc8
---
M Wikipedia-iOS/Base.lproj/Main_iPhone.storyboard
M Wikipedia-iOS/View Controllers/SearchResultCell.h
M Wikipedia-iOS/View Controllers/SearchResultCell.m
M Wikipedia-iOS/View Controllers/SearchResultPrototypeView.xib
M Wikipedia-iOS/View Controllers/ViewController.m
5 files changed, 49 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia 
refs/changes/06/96406/1

diff --git a/Wikipedia-iOS/Base.lproj/Main_iPhone.storyboard 
b/Wikipedia-iOS/Base.lproj/Main_iPhone.storyboard
index f135f95..beb2f03 100644
--- a/Wikipedia-iOS/Base.lproj/Main_iPhone.storyboard
+++ b/Wikipedia-iOS/Base.lproj/Main_iPhone.storyboard
@@ -28,7 +28,7 @@
                             <searchBar contentMode="redraw" 
searchBarStyle="minimal" translatesAutoresizingMaskIntoConstraints="NO" 
id="eYB-ra-ZkE">
                                 <rect key="frame" x="0.0" y="20" width="320" 
height="44"/>
                                 <autoresizingMask key="autoresizingMask" 
widthSizable="YES" flexibleMaxY="YES"/>
-                                <textInputTraits key="textInputTraits"/>
+                                <textInputTraits key="textInputTraits" 
autocorrectionType="no"/>
                                 <connections>
                                     <outlet property="delegate" 
destination="vXZ-lx-hvc" id="3Z4-7z-PXM"/>
                                 </connections>
diff --git a/Wikipedia-iOS/View Controllers/SearchResultCell.h 
b/Wikipedia-iOS/View Controllers/SearchResultCell.h
index a8ff3fe..4aab670 100644
--- a/Wikipedia-iOS/View Controllers/SearchResultCell.h
+++ b/Wikipedia-iOS/View Controllers/SearchResultCell.h
@@ -5,6 +5,7 @@
 @property (weak, nonatomic) IBOutlet UIImageView *imageView;
 @property (weak, nonatomic) IBOutlet UILabel *textLabel;
 @property (weak, nonatomic) IBOutlet UIView *bottomBorder;
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBorderHeight;
 @property (nonatomic) BOOL useField;
 
 @end
diff --git a/Wikipedia-iOS/View Controllers/SearchResultCell.m 
b/Wikipedia-iOS/View Controllers/SearchResultCell.m
index 1af82b8..0856fc5 100644
--- a/Wikipedia-iOS/View Controllers/SearchResultCell.m
+++ b/Wikipedia-iOS/View Controllers/SearchResultCell.m
@@ -24,8 +24,8 @@
         // This "field" - ie a slight background color, slightly rounded 
corners,
         // and a light border - helps images which may have large amounts of 
white,
         // or which may have transparent parts, look much nicer and more 
visually
-        // consistent. The thumbnail for the search term "Monaco", for example,
-        // looks much better atop this field.
+        // consistent. The thumbnails for search terms "Monaco" and "Poland", 
for
+        // example, look much better atop this field.
         UIColor *borderColor = [UIColor colorWithWhite:0.0 alpha:0.1];
         
         self.imageView.layer.borderColor = borderColor.CGColor;
@@ -48,6 +48,9 @@
 {
     [super awakeFromNib];
 
+    // Use finer line on retina displays
+    self.bottomBorderHeight.constant = 1.0f / [UIScreen mainScreen].scale;
+
     // Initial changes to ui elements go here.
     // See: http://stackoverflow.com/a/15591474 for details.
 
diff --git a/Wikipedia-iOS/View Controllers/SearchResultPrototypeView.xib 
b/Wikipedia-iOS/View Controllers/SearchResultPrototypeView.xib
index fa84454..d3f9df0 100644
--- a/Wikipedia-iOS/View Controllers/SearchResultPrototypeView.xib
+++ b/Wikipedia-iOS/View Controllers/SearchResultPrototypeView.xib
@@ -32,28 +32,29 @@
                             <constraint firstAttribute="width" constant="55" 
id="an5-O3-h22"/>
                         </constraints>
                     </imageView>
-                    <view contentMode="scaleToFill" misplaced="YES" 
translatesAutoresizingMaskIntoConstraints="NO" id="Kfy-Vr-Cm4" 
userLabel="Bottom Border">
-                        <rect key="frame" x="0.0" y="60" width="320" 
height="2"/>
+                    <view contentMode="scaleToFill" 
translatesAutoresizingMaskIntoConstraints="NO" id="Kfy-Vr-Cm4" 
userLabel="Bottom Border">
+                        <rect key="frame" x="69" y="61" width="241" 
height="1"/>
                         <autoresizingMask key="autoresizingMask" 
flexibleMaxX="YES" flexibleMaxY="YES"/>
-                        <color key="backgroundColor" 
white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
+                        <color key="backgroundColor" 
white="0.89738252737226276" alpha="1" colorSpace="calibratedWhite"/>
                         <constraints>
-                            <constraint firstAttribute="height" constant="0.5" 
id="ds6-wm-FiV"/>
+                            <constraint firstAttribute="height" constant="1" 
id="ds6-wm-FiV"/>
                         </constraints>
                     </view>
                 </subviews>
                 <constraints>
+                    <constraint firstItem="Kfy-Vr-Cm4" 
firstAttribute="leading" secondItem="Osd-Rs-zDt" secondAttribute="trailing" 
constant="10" id="6Bc-qb-tfa"/>
                     <constraint firstItem="Osd-Rs-zDt" 
firstAttribute="leading" secondItem="c2I-Os-6UK" secondAttribute="leading" 
constant="4" id="7rT-zT-nvx"/>
                     <constraint firstItem="6gV-a2-bBZ" 
firstAttribute="leading" secondItem="Osd-Rs-zDt" secondAttribute="trailing" 
constant="11" id="DJ2-bz-8H4"/>
-                    <constraint firstItem="Kfy-Vr-Cm4" 
firstAttribute="leading" secondItem="c2I-Os-6UK" secondAttribute="leading" 
id="PGF-7c-POP"/>
                     <constraint firstAttribute="trailing" 
secondItem="6gV-a2-bBZ" secondAttribute="trailing" constant="20" symbolic="YES" 
id="aTu-dD-9pX"/>
                     <constraint firstAttribute="centerY" 
secondItem="Osd-Rs-zDt" secondAttribute="centerY" constant="0.5" 
id="bmG-XJ-mP7"/>
-                    <constraint firstAttribute="trailing" 
secondItem="Kfy-Vr-Cm4" secondAttribute="trailing" id="enu-3t-Yc9"/>
                     <constraint firstAttribute="centerY" 
secondItem="6gV-a2-bBZ" secondAttribute="centerY" constant="0.5" 
id="hK4-dK-ad4"/>
                     <constraint firstAttribute="bottom" 
secondItem="Kfy-Vr-Cm4" secondAttribute="bottom" id="hux-vZ-Xop"/>
+                    <constraint firstAttribute="trailing" 
secondItem="Kfy-Vr-Cm4" secondAttribute="trailing" constant="10" 
id="vRz-hF-fLj"/>
                 </constraints>
             </tableViewCellContentView>
             <connections>
                 <outlet property="bottomBorder" destination="Kfy-Vr-Cm4" 
id="lfI-gm-59e"/>
+                <outlet property="bottomBorderHeight" destination="ds6-wm-FiV" 
id="U37-Pu-GOx"/>
                 <outlet property="imageView" destination="Osd-Rs-zDt" 
id="Dwm-6q-j6W"/>
                 <outlet property="textLabel" destination="6gV-a2-bBZ" 
id="8MQ-zs-5C1"/>
             </connections>
diff --git a/Wikipedia-iOS/View Controllers/ViewController.m 
b/Wikipedia-iOS/View Controllers/ViewController.m
index 2f4a4fe..10276b9 100644
--- a/Wikipedia-iOS/View Controllers/ViewController.m
+++ b/Wikipedia-iOS/View Controllers/ViewController.m
@@ -36,6 +36,7 @@
     NSOperationQueue *searchQ_;
     NSOperationQueue *thumbnailQ_;
     UILabel *debugLabel_;
+    NSString *currentSearchString_;
 }
 
 #pragma mark Network activity indicator methods
@@ -62,6 +63,7 @@
 {
     [super viewDidLoad];
 
+    currentSearchString_ = @"";
     self.searchDisplayController.searchBar.placeholder = @"Search Wikipedia";
     self.searchDisplayController.searchResultsDataSource = (id)self;
     self.searchResultsOrdered = [[NSMutableArray alloc] init];
@@ -111,6 +113,9 @@
 
 - (BOOL)searchDisplayController:(UISearchDisplayController *)controller 
shouldReloadTableForSearchString:(NSString *)searchString
 {
+
+    currentSearchString_ = searchString;
+
     // The documentation for ^this^ method recommends initiating async search 
here, then reloading the search results table
     // once results are obtained.
     [self searchForTerm:searchString];
@@ -140,7 +145,8 @@
     SearchResultCell *cell = (SearchResultCell *)[tableView 
dequeueReusableCellWithIdentifier:@"SearchResultCell"];
 
     NSString *title = self.searchResultsOrdered[indexPath.row][@"title"];
-    cell.textLabel.text = title;
+
+    cell.textLabel.attributedText = [self getAttributedTitle:title];
     
     NSString *thumbURL = 
self.searchResultsOrdered[indexPath.row][@"thumbnail"][@"source"];
 
@@ -220,6 +226,34 @@
     searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
 }
 
+#pragma mark Search term highlighter
+
+-(NSAttributedString *)getAttributedTitle:(NSString *)title
+{
+    // Returns attributed string of title with the current search term 
highlighted.
+    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] 
initWithString:title];
+
+    // Non-search term
+    [str addAttribute:NSFontAttributeName
+                value:[UIFont fontWithName:@"HelveticaNeue" size:15.0]
+                range:NSMakeRange(0, title.length)];
+
+    [str addAttribute:NSForegroundColorAttributeName
+                value:[UIColor colorWithWhite:0.0 alpha:0.85]
+                range:NSMakeRange(0, title.length)];
+
+    // Search term
+    [str addAttribute:NSFontAttributeName
+                value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]
+                range:NSMakeRange(0, currentSearchString_.length)];
+
+    [str addAttribute:NSForegroundColorAttributeName
+                value:[UIColor blackColor] //colorWithRed:0.00 green:0.48 
blue:1.00 alpha:1.0]
+                range:NSMakeRange(0, currentSearchString_.length)];
+    
+    return str;
+}
+
 #pragma mark Search term methods (requests titles matching search term and 
associated thumbnail urls)
 
 - (void)searchForTerm:(NSString *)searchTerm

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43a785c160b42768fc70793fc92bd8c9a6853cc8
Gerrit-PatchSet: 1
Gerrit-Project: apps/ios/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mhurd <[email protected]>

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

Reply via email to