diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings new file mode 100644 index 0000000..e3b6715 --- /dev/null +++ b/en.lproj/Localizable.strings @@ -0,0 +1,8 @@ +/* + Localizable.strings + iTunesSearch + + Created by Eduardo Quadros on 3/12/15. + Copyright (c) 2015 joaquim. All rights reserved. +*/ +"search"="Search"; \ No newline at end of file diff --git a/iTunesSearch.xcodeproj/project.pbxproj b/iTunesSearch.xcodeproj/project.pbxproj index 79e06d7..4efbe64 100644 --- a/iTunesSearch.xcodeproj/project.pbxproj +++ b/iTunesSearch.xcodeproj/project.pbxproj @@ -7,13 +7,14 @@ objects = { /* Begin PBXBuildFile section */ + 61D302851AB22E0500B76908 /* TableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 61D302841AB22E0500B76908 /* TableView.xib */; }; + 61D302861AB22E8900B76908 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61D302881AB22E8900B76908 /* Localizable.strings */; }; 92C21CB61AAE757A0052ABE6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CB51AAE757A0052ABE6 /* main.m */; }; 92C21CB91AAE757A0052ABE6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CB81AAE757A0052ABE6 /* AppDelegate.m */; }; 92C21CBC1AAE757A0052ABE6 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CBB1AAE757A0052ABE6 /* TableViewController.m */; }; 92C21CC11AAE757A0052ABE6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 92C21CC01AAE757A0052ABE6 /* Images.xcassets */; }; 92C21CD01AAE757A0052ABE6 /* iTunesSearchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CCF1AAE757A0052ABE6 /* iTunesSearchTests.m */; }; 92C21CDB1AAE75B30052ABE6 /* iTunesManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CDA1AAE75B30052ABE6 /* iTunesManager.m */; }; - 92C21CDD1AAE75DC0052ABE6 /* TableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92C21CDC1AAE75DC0052ABE6 /* TableView.xib */; }; 92C21CE11AAE76930052ABE6 /* TableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CDF1AAE76930052ABE6 /* TableViewCell.m */; }; 92C21CE21AAE76930052ABE6 /* TableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 92C21CE01AAE76930052ABE6 /* TableViewCell.xib */; }; 92C21CE81AAE858E0052ABE6 /* Filme.m in Sources */ = {isa = PBXBuildFile; fileRef = 92C21CE71AAE858E0052ABE6 /* Filme.m */; }; @@ -30,6 +31,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 61D302841AB22E0500B76908 /* TableView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableView.xib; sourceTree = ""; }; + 61D302891AB22E8C00B76908 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + 61D3028A1AB22EB400B76908 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/Localizable.strings; sourceTree = ""; }; 92C21CB01AAE757A0052ABE6 /* iTunesSearch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iTunesSearch.app; sourceTree = BUILT_PRODUCTS_DIR; }; 92C21CB41AAE757A0052ABE6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 92C21CB51AAE757A0052ABE6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; @@ -43,7 +47,6 @@ 92C21CCF1AAE757A0052ABE6 /* iTunesSearchTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iTunesSearchTests.m; sourceTree = ""; }; 92C21CD91AAE75B30052ABE6 /* iTunesManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunesManager.h; sourceTree = ""; }; 92C21CDA1AAE75B30052ABE6 /* iTunesManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTunesManager.m; sourceTree = ""; }; - 92C21CDC1AAE75DC0052ABE6 /* TableView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableView.xib; sourceTree = ""; }; 92C21CDE1AAE76930052ABE6 /* TableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewCell.h; sourceTree = ""; }; 92C21CDF1AAE76930052ABE6 /* TableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewCell.m; sourceTree = ""; }; 92C21CE01AAE76930052ABE6 /* TableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TableViewCell.xib; sourceTree = ""; }; @@ -72,6 +75,7 @@ 92C21CA71AAE757A0052ABE6 = { isa = PBXGroup; children = ( + 61D302881AB22E8900B76908 /* Localizable.strings */, 92C21CB21AAE757A0052ABE6 /* iTunesSearch */, 92C21CCC1AAE757A0052ABE6 /* iTunesSearchTests */, 92C21CB11AAE757A0052ABE6 /* Products */, @@ -96,7 +100,7 @@ 92C21CB81AAE757A0052ABE6 /* AppDelegate.m */, 92C21CBA1AAE757A0052ABE6 /* TableViewController.h */, 92C21CBB1AAE757A0052ABE6 /* TableViewController.m */, - 92C21CDC1AAE75DC0052ABE6 /* TableView.xib */, + 61D302841AB22E0500B76908 /* TableView.xib */, 92C21CD91AAE75B30052ABE6 /* iTunesManager.h */, 92C21CDA1AAE75B30052ABE6 /* iTunesManager.m */, 92C21CC01AAE757A0052ABE6 /* Images.xcassets */, @@ -213,6 +217,7 @@ knownRegions = ( en, Base, + pt, ); mainGroup = 92C21CA71AAE757A0052ABE6; productRefGroup = 92C21CB11AAE757A0052ABE6 /* Products */; @@ -231,8 +236,9 @@ buildActionMask = 2147483647; files = ( 92C21CC11AAE757A0052ABE6 /* Images.xcassets in Resources */, + 61D302851AB22E0500B76908 /* TableView.xib in Resources */, + 61D302861AB22E8900B76908 /* Localizable.strings in Resources */, 92C21CE21AAE76930052ABE6 /* TableViewCell.xib in Resources */, - 92C21CDD1AAE75DC0052ABE6 /* TableView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -277,6 +283,18 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + 61D302881AB22E8900B76908 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 61D302891AB22E8C00B76908 /* en */, + 61D3028A1AB22EB400B76908 /* pt */, + ); + name = Localizable.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 92C21CD11AAE757A0052ABE6 /* Debug */ = { isa = XCBuildConfiguration; diff --git a/iTunesSearch/Entidades/Filme.h b/iTunesSearch/Entidades/Filme.h index eb126dc..c271656 100644 --- a/iTunesSearch/Entidades/Filme.h +++ b/iTunesSearch/Entidades/Filme.h @@ -16,5 +16,6 @@ @property (nonatomic, strong) NSString *duracao; @property (nonatomic, strong) NSString *genero; @property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *kind; @end diff --git a/iTunesSearch/TableView.xib b/iTunesSearch/TableView.xib index 55f128c..5fe86bd 100644 --- a/iTunesSearch/TableView.xib +++ b/iTunesSearch/TableView.xib @@ -1,25 +1,31 @@ - + - - + + + - + + + + + + - - + + - + diff --git a/iTunesSearch/TableViewCell.h b/iTunesSearch/TableViewCell.h index b630349..353a48a 100644 --- a/iTunesSearch/TableViewCell.h +++ b/iTunesSearch/TableViewCell.h @@ -12,6 +12,9 @@ @property (weak, nonatomic) IBOutlet UILabel *nome; @property (weak, nonatomic) IBOutlet UILabel *tipo; - +@property (weak, nonatomic) IBOutlet UILabel *directorName; +@property (weak, nonatomic) IBOutlet UILabel *duration; +@property (weak, nonatomic) IBOutlet UILabel *genre; @end + diff --git a/iTunesSearch/TableViewCell.m b/iTunesSearch/TableViewCell.m index ffac89c..8439766 100644 --- a/iTunesSearch/TableViewCell.m +++ b/iTunesSearch/TableViewCell.m @@ -10,14 +10,10 @@ @implementation TableViewCell -- (void)awakeFromNib { - // Initialization code -} +- (void)awakeFromNib {} - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; - - // Configure the view for the selected state } @end diff --git a/iTunesSearch/TableViewCell.xib b/iTunesSearch/TableViewCell.xib index bf8bd3f..2cd66c3 100644 --- a/iTunesSearch/TableViewCell.xib +++ b/iTunesSearch/TableViewCell.xib @@ -1,5 +1,5 @@ - + @@ -8,16 +8,16 @@ - + + + + @@ -37,10 +55,13 @@ + + + - + diff --git a/iTunesSearch/TableViewController.h b/iTunesSearch/TableViewController.h index 0cbb5c4..f676119 100644 --- a/iTunesSearch/TableViewController.h +++ b/iTunesSearch/TableViewController.h @@ -8,10 +8,9 @@ #import -@interface TableViewController : UIViewController - +@interface TableViewController : UIViewController +@property (weak, nonatomic) IBOutlet UISearchBar *searchMedia; @property (strong, nonatomic) IBOutlet UITableView *tableview; @end - diff --git a/iTunesSearch/TableViewController.m b/iTunesSearch/TableViewController.m index f689980..665dce8 100644 --- a/iTunesSearch/TableViewController.m +++ b/iTunesSearch/TableViewController.m @@ -19,30 +19,60 @@ @interface TableViewController () { @implementation TableViewController - +- (BOOL)prefersStatusBarHidden { + return YES; +} - (void)viewDidLoad { [super viewDidLoad]; - + UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; [self.tableview registerNib:nib forCellReuseIdentifier:@"celulaPadrao"]; - + + [_searchMedia setDelegate:self]; + [_searchMedia setPlaceholder:NSLocalizedString(@"search", nil)]; + iTunesManager *itunes = [iTunesManager sharedInstance]; - midias = [itunes buscarMidias:@"Apple"]; - -#warning Necessario para que a table view tenha um espaco em relacao ao topo, pois caso contrario o texto ficara atras da barra superior - self.tableview.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 15.f)]; +// midias = [itunes buscarMidias:@"Apple"]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. } +#pragma mark SearchBar + +- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { + [_searchMedia setShowsCancelButton:YES animated:YES]; +} + +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { + [_searchMedia setShowsCancelButton:NO animated:YES]; + [_searchMedia resignFirstResponder]; +} + +// Amazingly slow. +- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { + iTunesManager *manager = [iTunesManager sharedInstance]; + midias = [manager buscarMidias:_searchMedia.text]; + + [_tableview reloadData]; +} + +#pragma mark - UITableViewDataSource -#pragma mark - Metodos do UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + // Media Types + // movie, podcast, music, musicVideo, audiobook, shortFilm, tvShow, software, ebook, all + // https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html + + if (midias) { + // get all media types from returned search array + + return 0; + } + + return 0; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -51,18 +81,22 @@ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *celula = [self.tableview dequeueReusableCellWithIdentifier:@"celulaPadrao"]; - Filme *filme = [midias objectAtIndex:indexPath.row]; - + [celula.nome setText:filme.nome]; [celula.tipo setText:@"Filme"]; - + [celula.directorName setText:filme.artista]; + [celula.duration setText:filme.duracao]; + [celula.genre setText:filme.genero]; return celula; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return 70; + return 150; // Hard coded sucks... } +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + [_searchMedia resignFirstResponder]; +} @end diff --git a/iTunesSearch/iTunesManager.h b/iTunesSearch/iTunesManager.h index c0e366b..aace199 100644 --- a/iTunesSearch/iTunesManager.h +++ b/iTunesSearch/iTunesManager.h @@ -8,14 +8,28 @@ #import +typedef enum { + MOVIE, + PODCAST, + MUSIC, + MUSICVIDEO, + AUDIOBOOK, + SHORTFILM, + TVSHOW, + SOFTWARE, + EBOOK +} MediaTypes; + @interface iTunesManager : NSObject /** * gets singleton object. * @return singleton */ -+ (iTunesManager*)sharedInstance; +@property MediaTypes *mediaTypes; + ++ (iTunesManager*)sharedInstance; - (NSArray *)buscarMidias:(NSString *)termo; @end diff --git a/iTunesSearch/iTunesManager.m b/iTunesSearch/iTunesManager.m index e2babda..ac6d877 100644 --- a/iTunesSearch/iTunesManager.m +++ b/iTunesSearch/iTunesManager.m @@ -22,19 +22,25 @@ + (id)sharedInstance static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ isFirstAccess = NO; - SINGLETON = [[super allocWithZone:NULL] init]; + SINGLETON = [[super allocWithZone:NULL] init]; }); return SINGLETON; } +- (id)init { + _mediaTypes = [NSArray arrayWithObjects:@"movie", @"podcast", @"music", @"musicVideo", + @"audiobook", @"shortFilm", @"tvShow", @"software", + @"ebook", nil]; +} - (NSArray *)buscarMidias:(NSString *)termo { if (!termo) { termo = @""; } - - NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=movie", termo]; + + // Search for all medias. + NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=all", termo]; NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]]; NSError *error; @@ -53,18 +59,38 @@ - (NSArray *)buscarMidias:(NSString *)termo { Filme *filme = [[Filme alloc] init]; [filme setNome:[item objectForKey:@"trackName"]]; [filme setTrackId:[item objectForKey:@"trackId"]]; - [filme setArtista:[item objectForKey:@"artistName"]]; - [filme setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [filme setArtista:[item objectForKey:@"artistName"]]; // Director + + int milliSeconds = [[item objectForKey:@"trackTimeMillis"] intValue]; + int minutes = ((milliSeconds / 1000) / 60); + + [filme setDuracao: [[NSString alloc] initWithFormat:@"%d", minutes]]; [filme setGenero:[item objectForKey:@"primaryGenreName"]]; [filme setPais:[item objectForKey:@"country"]]; + [filme setKind:[item objectForKey:@"kind"]]; [filmes addObject:filme]; } return filmes; } +- (int)howManyMediaTypes:(NSArray *)mediaList { + if (mediaList) { + NSMutableArray *mediaKinds; + for (Filme* media in mediaList) { + NSString *mediaKind = media.kind; + if (![mediaKinds containsObject:mediaKind]) { + [mediaKinds addObject:mediaKind]; + } + } + + return mediaKind; + } + + return 0; +} #pragma mark - Life Cycle diff --git a/iTunesSearchTests/fr.lproj/InfoPlist.strings b/iTunesSearchTests/fr.lproj/InfoPlist.strings new file mode 100644 index 0000000..dc62739 --- /dev/null +++ b/iTunesSearchTests/fr.lproj/InfoPlist.strings @@ -0,0 +1 @@ +/* No Localized Strings */ \ No newline at end of file diff --git a/iTunesSearchTests/pt.lproj/InfoPlist.strings b/iTunesSearchTests/pt.lproj/InfoPlist.strings new file mode 100644 index 0000000..dc62739 --- /dev/null +++ b/iTunesSearchTests/pt.lproj/InfoPlist.strings @@ -0,0 +1 @@ +/* No Localized Strings */ \ No newline at end of file diff --git a/pt.lproj/Localizable.strings b/pt.lproj/Localizable.strings new file mode 100644 index 0000000..f04110f --- /dev/null +++ b/pt.lproj/Localizable.strings @@ -0,0 +1,8 @@ +/* + Localizable.strings + iTunesSearch + + Created by Eduardo Quadros on 3/12/15. + Copyright (c) 2015 joaquim. All rights reserved. +*/ +"search"="Pesquisa"; \ No newline at end of file