diff --git a/media/iphone/Classes/AddSiteAutocompleteCell.h b/media/iphone/Classes/AddSiteAutocompleteCell.h new file mode 100644 index 000000000..fc2e34b31 --- /dev/null +++ b/media/iphone/Classes/AddSiteAutocompleteCell.h @@ -0,0 +1,21 @@ +// +// AddSiteAutocompleteCell.h +// NewsBlur +// +// Created by Samuel Clay on 10/12/11. +// Copyright 2011 NewsBlur. All rights reserved. +// + +#import + +@interface AddSiteAutocompleteCell : UITableViewCell { + UILabel *feedTitle; + UILabel *feedUrl; + UILabel *feedSubs; +} + +@property (nonatomic, retain) IBOutlet UILabel *feedTitle; +@property (nonatomic, retain) IBOutlet UILabel *feedUrl; +@property (nonatomic, retain) IBOutlet UILabel *feedSubs; + +@end diff --git a/media/iphone/Classes/AddSiteAutocompleteCell.m b/media/iphone/Classes/AddSiteAutocompleteCell.m new file mode 100644 index 000000000..78edf05b3 --- /dev/null +++ b/media/iphone/Classes/AddSiteAutocompleteCell.m @@ -0,0 +1,40 @@ +// +// AddSiteAutocompleteCell.m +// NewsBlur +// +// Created by Samuel Clay on 10/12/11. +// Copyright 2011 NewsBlur. All rights reserved. +// + +#import "AddSiteAutocompleteCell.h" + +@implementation AddSiteAutocompleteCell + +@synthesize feedTitle; +@synthesize feedUrl; +@synthesize feedSubs; + +- (id)initWithStyle:(UITableViewCellStyle)style + reuseIdentifier:(NSString *)reuseIdentifier { + if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { + // Initialization code + } + return self; +} + + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated { + + [super setSelected:selected animated:animated]; +} + + +- (void)dealloc { + [feedTitle release]; + [feedUrl release]; + [feedSubs release]; + [super dealloc]; +} + + +@end diff --git a/media/iphone/Classes/AddSiteAutocompleteCell.xib b/media/iphone/Classes/AddSiteAutocompleteCell.xib new file mode 100644 index 000000000..90217be79 --- /dev/null +++ b/media/iphone/Classes/AddSiteAutocompleteCell.xib @@ -0,0 +1,344 @@ + + + + 1056 + 11B26 + 1617 + 1138 + 566.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 534 + + + YES + IBProxyObject + IBUILabel + IBUITableViewCell + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + + + YES + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 292 + + YES + + + 256 + + YES + + + 292 + {{20, 3}, {194, 21}} + + + + _NS:311 + NO + YES + 7 + NO + IBCocoaTouchFramework + Daring Fireball + + Helvetica + 15 + 16 + + + 1 + MCAwIDAAA + + + 1 + 15 + + + + 292 + {{20, 20}, {280, 21}} + + + + _NS:311 + NO + YES + 7 + NO + IBCocoaTouchFramework + http://daringfireball.net/feeds/extra/parameters/that/might/be/truncated/rss.xml + + Helvetica + 12 + 16 + + + 3 + MC4zMzMzMzMzMzMzAA + + + 1 + 12 + 5 + + + + 292 + {{213, 3}, {87, 21}} + + + + _NS:311 + NO + YES + 7 + NO + IBCocoaTouchFramework + 123 subscribers + + Helvetica + 11 + 16 + + + 2 + MC4xNDUwOTgwNDU1IDAuMTc2NDcwNTkyNiAwLjQyMzUyOTQ0NjEAA + + + 1 + 11 + 2 + + + {320, 44} + + + + _NS:370 + + 3 + MCAwAA + + NO + YES + 4 + YES + IBCocoaTouchFramework + + + {320, 44} + + + + _NS:358 + + 1 + MSAxIDEAA + + IBCocoaTouchFramework + 1 + + AddSiteAutocompleteCellIdentifier + + + + + YES + + + feedSubs + + + + 11 + + + + feedTitle + + + + 12 + + + + feedUrl + + + + 13 + + + + + YES + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + YES + + + + + + + + 5 + + + + + 6 + + + + + 7 + + + + + + + YES + + YES + -1.CustomClassName + -1.IBPluginDependency + -2.CustomClassName + -2.IBPluginDependency + 4.CustomClassName + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBPluginDependency + 7.IBPluginDependency + + + YES + AddSiteAutocompleteCell + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + AddSiteAutocompleteCell + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + + + + YES + + + + + 13 + + + + YES + + AddSiteAutocompleteCell + UITableViewCell + + YES + + YES + feedSubs + feedTitle + feedUrl + + + YES + UILabel + UILabel + UILabel + + + + YES + + YES + feedSubs + feedTitle + feedUrl + + + YES + + feedSubs + UILabel + + + feedTitle + UILabel + + + feedUrl + UILabel + + + + + IBProjectSource + ./Classes/AddSiteAutocompleteCell.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + 3 + 534 + + diff --git a/media/iphone/Classes/AddViewController.h b/media/iphone/Classes/AddViewController.h index 9b33b97be..424970a14 100644 --- a/media/iphone/Classes/AddViewController.h +++ b/media/iphone/Classes/AddViewController.h @@ -19,7 +19,8 @@ UITextField *inFolderInput; UITextField *newFolderInput; UITextField *siteAddressInput; - NSMutableData * jsonString; + NSMutableData *jsonString; + NSMutableArray *autocompleteResults; UIBarButtonItem *addButton; UIBarButtonItem *cancelButton; @@ -28,6 +29,7 @@ UINavigationBar *navBar; UIActivityIndicatorView *activityIndicator; + UIActivityIndicatorView *siteActivityIndicator; UILabel *addingLabel; UILabel *errorLabel; UISegmentedControl *addTypeControl; @@ -41,6 +43,7 @@ - (void)reload; - (IBAction)addSite; +- (void)autocompleteSite:(ASIHTTPRequest *)request; - (IBAction)addFolder; - (IBAction)selectAddTypeSignup; - (IBAction)doCancelButton; @@ -48,6 +51,7 @@ - (NSString *)extractParentFolder; - (void)animateLoop; - (void)hideFolderPicker; +- (IBAction)checkSiteAddress; @property (nonatomic, retain) IBOutlet NewsBlurAppDelegate *appDelegate; @property (nonatomic, retain) IBOutlet UITextField *inFolderInput; @@ -59,9 +63,11 @@ @property (nonatomic, retain) IBOutlet UIPickerView *folderPicker; @property (nonatomic, retain) IBOutlet UITableView *siteTable; @property (nonatomic, retain) NSMutableData * jsonString; +@property (nonatomic, retain) NSMutableArray *autocompleteResults; @property (nonatomic, retain) IBOutlet UINavigationBar *navBar; @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator; +@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *siteActivityIndicator; @property (nonatomic, retain) IBOutlet UILabel *addingLabel; @property (nonatomic, retain) IBOutlet UILabel *errorLabel; @property (nonatomic, retain) IBOutlet UISegmentedControl *addTypeControl; diff --git a/media/iphone/Classes/AddViewController.m b/media/iphone/Classes/AddViewController.m index 8fb85c9d2..22e4a6ab9 100644 --- a/media/iphone/Classes/AddViewController.m +++ b/media/iphone/Classes/AddViewController.m @@ -7,6 +7,7 @@ // #import "AddViewController.h" +#import "AddSiteAutocompleteCell.h" #import "NewsBlurAppDelegate.h" #import "ASIHTTPRequest.h" #import "ASIFormDataRequest.h" @@ -23,8 +24,10 @@ @synthesize folderPicker; @synthesize siteTable; @synthesize jsonString; +@synthesize autocompleteResults; @synthesize navBar; @synthesize activityIndicator; +@synthesize siteActivityIndicator; @synthesize addingLabel; @synthesize errorLabel; @synthesize addTypeControl; @@ -98,6 +101,7 @@ [folderPicker release]; [siteTable release]; [jsonString release]; + [autocompleteResults release]; [navBar release]; [super dealloc]; } @@ -160,6 +164,46 @@ return YES; } +- (IBAction)checkSiteAddress { + NSString *phrase = siteAddressInput.text; + int period_loc = [phrase rangeOfString:@"."].location; + NSLog(@"phrase: %@ - %d", phrase, period_loc); + if (period_loc != NSNotFound) { + // URL + [siteAddressInput setReturnKeyType:UIReturnKeyDone]; + [siteAddressInput resignFirstResponder]; + [siteAddressInput becomeFirstResponder]; + } else { + // Search + [siteAddressInput setReturnKeyType:UIReturnKeySearch]; + [siteAddressInput resignFirstResponder]; + [siteAddressInput becomeFirstResponder]; + } + + + [self.siteActivityIndicator startAnimating]; + [siteAddressInput setLeftView:self.siteActivityIndicator]; + NSString *urlString = [NSString stringWithFormat:@"http://%@/rss_feeds/feed_autocomplete?term=%@", + NEWSBLUR_URL, phrase]; + NSURL *url = [NSURL URLWithString:urlString]; + ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:url]; + [request setDelegate:self]; + [request setDidFinishSelector:@selector(autocompleteSite:)]; + [request startAsynchronous]; +} + +- (void)autocompleteSite:(ASIHTTPRequest *)request { + [self.siteActivityIndicator stopAnimating]; + UIImageView *urlImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"world.png"]]; + [siteAddressInput setLeftView:urlImage]; + [urlImage release]; + NSString *responseString = [request responseString]; + autocompleteResults = [responseString JSONValue]; + NSLog(@"%@", autocompleteResults); + [siteTable reloadData]; + [siteTable setHidden:NO]; +} + - (IBAction)addSite { [self hideFolderPicker]; [siteAddressInput resignFirstResponder]; @@ -349,12 +393,33 @@ numberOfRowsInComponent:(NSInteger)component { - (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return [autocompleteResults count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *AddSiteAutocompleteCellIdentifier = @"AddSiteAutocompleteCellIdentifier"; + AddSiteAutocompleteCell *cell = (AddSiteAutocompleteCell *)[tableView dequeueReusableCellWithIdentifier:AddSiteAutocompleteCellIdentifier]; + if (cell == nil) { + NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AddSiteAutocompleteCell" + owner:self + options:nil]; + for (id oneObject in nib) { + if ([oneObject isKindOfClass:[AddSiteAutocompleteCell class]]) { + cell = (AddSiteAutocompleteCell *)oneObject; + } + } + } + + NSDictionary *result = [autocompleteResults objectAtIndex:indexPath.row]; + int subs = [[result objectForKey:@"num_subscribers"] intValue]; + cell.feedTitle.text = [result objectForKey:@"label"]; + cell.feedUrl.text = [result objectForKey:@"value"]; + cell.feedSubs.text = [NSString stringWithFormat:@"%@ subscriber%@", + subs, subs == 1 ? @"" : @"s"]; + + return cell; } @end diff --git a/media/iphone/Classes/AddViewController.xib b/media/iphone/Classes/AddViewController.xib index ead1fbbd4..76dd22b01 100644 --- a/media/iphone/Classes/AddViewController.xib +++ b/media/iphone/Classes/AddViewController.xib @@ -20,6 +20,7 @@ IBProxyObject IBUINavigationBar IBUINavigationItem + IBUIScrollView IBUIView IBUIImageView IBUITableView @@ -72,7 +73,7 @@ {{111, 294}, {189, 52}} - + _NS:311 NO YES @@ -129,6 +130,7 @@ {{87, 310}, {20, 20}} + _NS:824 NO IBCocoaTouchFramework @@ -212,7 +214,7 @@ {{0, 244}, {320, 216}} - + _NS:624 IBCocoaTouchFramework YES @@ -274,7 +276,7 @@ 18 1 - 3 + 7 6 YES IBCocoaTouchFramework @@ -287,7 +289,7 @@ {{20, 130}, {280, 31}} - + _NS:294 NO YES @@ -314,25 +316,51 @@ 1 - + - 274 - {{0, 179}, {320, 281}} + -2147483356 + {{25, 136}, {20, 20}} - - _NS:392 - - YES + + _NS:824 + NO + IBCocoaTouchFramework + 2 + + + + 268 + + YES + + + 274 + {280, 77} + + + + _NS:392 + + YES + IBCocoaTouchFramework + YES + NO + 1 + 0 + YES + 44 + 22 + 22 + + + {{20, 164}, {280, 77}} + + + _NS:174 + YES + YES IBCocoaTouchFramework - YES - NO - 1 - 0 - YES - 44 - 22 - 22 {{0, 20}, {320, 460}} @@ -4935,6 +4963,32 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE 58 + + + checkSiteAddress + + + 13 + + 59 + + + + checkSiteAddress + + + 18 + + 60 + + + + siteActivityIndicator + + + + 62 + @@ -4970,8 +5024,9 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE - + + @@ -5045,16 +5100,30 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE - - 49 - - - 8 + + 61 + + + + + 63 + + + YES + + + + + + 49 + + + @@ -5078,6 +5147,8 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE 48.IBPluginDependency 49.IBPluginDependency 5.IBPluginDependency + 61.IBPluginDependency + 63.IBPluginDependency 7.IBPluginDependency 8.IBPluginDependency 9.IBPluginDependency @@ -5104,6 +5175,8 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -5118,7 +5191,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE - 58 + 63 @@ -5132,6 +5205,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE YES addFolder addSite + checkSiteAddress doAddButton doCancelButton selectAddTypeSignup @@ -5143,6 +5217,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE id id id + id @@ -5151,6 +5226,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE YES addFolder addSite + checkSiteAddress doAddButton doCancelButton selectAddTypeSignup @@ -5165,6 +5241,10 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE addSite id + + checkSiteAddress + id + doAddButton id @@ -5197,6 +5277,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE newFolderInput passwordLabel passwordOptionalLabel + siteActivityIndicator siteAddressInput siteTable usernameLabel @@ -5218,6 +5299,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE UITextField UILabel UILabel + UIActivityIndicatorView UITextField UITableView UILabel @@ -5242,6 +5324,7 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE newFolderInput passwordLabel passwordOptionalLabel + siteActivityIndicator siteAddressInput siteTable usernameLabel @@ -5305,6 +5388,10 @@ AAgAAAAIAAIACAACAAAAAgAAAAEAAQABAAE passwordOptionalLabel UILabel + + siteActivityIndicator + UIActivityIndicatorView + siteAddressInput UITextField diff --git a/media/iphone/NewsBlur.xcodeproj/project.pbxproj b/media/iphone/NewsBlur.xcodeproj/project.pbxproj index 75e21473c..55406e104 100755 --- a/media/iphone/NewsBlur.xcodeproj/project.pbxproj +++ b/media/iphone/NewsBlur.xcodeproj/project.pbxproj @@ -91,6 +91,8 @@ FFD5338D143E701400C5555D /* settings_icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FFD5338C143E701400C5555D /* settings_icon@2x.png */; }; FFD53390143E722000C5555D /* network_icon_all.png in Resources */ = {isa = PBXBuildFile; fileRef = FFD5338E143E722000C5555D /* network_icon_all.png */; }; FFD53391143E722000C5555D /* network_icon.png in Resources */ = {isa = PBXBuildFile; fileRef = FFD5338F143E722000C5555D /* network_icon.png */; }; + FFD887F01445F1E800385399 /* AddSiteAutocompleteCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FFD887EE1445F1E800385399 /* AddSiteAutocompleteCell.m */; }; + FFD887F11445F1E800385399 /* AddSiteAutocompleteCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = FFD887EF1445F1E800385399 /* AddSiteAutocompleteCell.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -221,6 +223,9 @@ FFD5338C143E701400C5555D /* settings_icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "settings_icon@2x.png"; sourceTree = ""; }; FFD5338E143E722000C5555D /* network_icon_all.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = network_icon_all.png; sourceTree = ""; }; FFD5338F143E722000C5555D /* network_icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = network_icon.png; sourceTree = ""; }; + FFD887ED1445F1E800385399 /* AddSiteAutocompleteCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddSiteAutocompleteCell.h; sourceTree = ""; }; + FFD887EE1445F1E800385399 /* AddSiteAutocompleteCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddSiteAutocompleteCell.m; sourceTree = ""; }; + FFD887EF1445F1E800385399 /* AddSiteAutocompleteCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddSiteAutocompleteCell.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -260,6 +265,9 @@ FF5EA47C143B691000B7563D /* AddViewController.h */, FF5EA47D143B691000B7563D /* AddViewController.m */, FF5EA47E143B691000B7563D /* AddViewController.xib */, + FFD887ED1445F1E800385399 /* AddSiteAutocompleteCell.h */, + FFD887EE1445F1E800385399 /* AddSiteAutocompleteCell.m */, + FFD887EF1445F1E800385399 /* AddSiteAutocompleteCell.xib */, 787A0CD811CE65330056422D /* FeedDetailViewController.h */, 787A0CD911CE65330056422D /* FeedDetailViewController.m */, 787A0CDA11CE65330056422D /* FeedDetailViewController.xib */, @@ -536,6 +544,7 @@ FFD5338D143E701400C5555D /* settings_icon@2x.png in Resources */, FFD53390143E722000C5555D /* network_icon_all.png in Resources */, FFD53391143E722000C5555D /* network_icon.png in Resources */, + FFD887F11445F1E800385399 /* AddSiteAutocompleteCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -580,6 +589,7 @@ FF4BBC1E13F7487A001EBEBD /* TransparentToolbar.m in Sources */, FF56EC7B13F755E40009D8E0 /* MBProgressHUD.m in Sources */, FF5EA47F143B691000B7563D /* AddViewController.m in Sources */, + FFD887F01445F1E800385399 /* AddSiteAutocompleteCell.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };