diff --git a/iTunesSearch.xcodeproj/project.pbxproj b/iTunesSearch.xcodeproj/project.pbxproj index 79e06d7..08b6567 100644 --- a/iTunesSearch.xcodeproj/project.pbxproj +++ b/iTunesSearch.xcodeproj/project.pbxproj @@ -7,6 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 4D4694431AB2E71200AD029E /* Entidade.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D4694421AB2E71200AD029E /* Entidade.m */; }; + 4D4694461AB2E87300AD029E /* Filme.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D4694451AB2E87300AD029E /* Filme.m */; }; + 4D4694491AB2E8A000AD029E /* Musica.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D4694481AB2E8A000AD029E /* Musica.m */; }; + 4D46944C1AB2E8C100AD029E /* Podcast.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D46944B1AB2E8C100AD029E /* Podcast.m */; }; + 4D46944F1AB2E8E500AD029E /* Ebook.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D46944E1AB2E8E500AD029E /* Ebook.m */; }; 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 */; }; @@ -16,7 +21,6 @@ 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 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -30,6 +34,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4D4694411AB2E71200AD029E /* Entidade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Entidade.h; path = Entidades/Entidade.h; sourceTree = ""; }; + 4D4694421AB2E71200AD029E /* Entidade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Entidade.m; path = Entidades/Entidade.m; sourceTree = ""; }; + 4D4694441AB2E87300AD029E /* Filme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Filme.h; path = Entidades/Filme.h; sourceTree = ""; }; + 4D4694451AB2E87300AD029E /* Filme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Filme.m; path = Entidades/Filme.m; sourceTree = ""; }; + 4D4694471AB2E8A000AD029E /* Musica.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Musica.h; path = Entidades/Musica.h; sourceTree = ""; }; + 4D4694481AB2E8A000AD029E /* Musica.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Musica.m; path = Entidades/Musica.m; sourceTree = ""; }; + 4D46944A1AB2E8C100AD029E /* Podcast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Podcast.h; path = Entidades/Podcast.h; sourceTree = ""; }; + 4D46944B1AB2E8C100AD029E /* Podcast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Podcast.m; path = Entidades/Podcast.m; sourceTree = ""; }; + 4D46944D1AB2E8E500AD029E /* Ebook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Ebook.h; path = Entidades/Ebook.h; sourceTree = ""; }; + 4D46944E1AB2E8E500AD029E /* Ebook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Ebook.m; path = Entidades/Ebook.m; 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 = ""; }; @@ -47,8 +61,6 @@ 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 = ""; }; - 92C21CE61AAE858E0052ABE6 /* Filme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Filme.h; path = Entidades/Filme.h; sourceTree = ""; }; - 92C21CE71AAE858E0052ABE6 /* Filme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Filme.m; path = Entidades/Filme.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -144,8 +156,16 @@ 92C21CE91AAE859A0052ABE6 /* Entidades */ = { isa = PBXGroup; children = ( - 92C21CE61AAE858E0052ABE6 /* Filme.h */, - 92C21CE71AAE858E0052ABE6 /* Filme.m */, + 4D4694411AB2E71200AD029E /* Entidade.h */, + 4D4694421AB2E71200AD029E /* Entidade.m */, + 4D4694441AB2E87300AD029E /* Filme.h */, + 4D4694451AB2E87300AD029E /* Filme.m */, + 4D4694471AB2E8A000AD029E /* Musica.h */, + 4D4694481AB2E8A000AD029E /* Musica.m */, + 4D46944A1AB2E8C100AD029E /* Podcast.h */, + 4D46944B1AB2E8C100AD029E /* Podcast.m */, + 4D46944D1AB2E8E500AD029E /* Ebook.h */, + 4D46944E1AB2E8E500AD029E /* Ebook.m */, ); name = Entidades; sourceTree = ""; @@ -250,10 +270,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4D46944F1AB2E8E500AD029E /* Ebook.m in Sources */, + 4D46944C1AB2E8C100AD029E /* Podcast.m in Sources */, + 4D4694491AB2E8A000AD029E /* Musica.m in Sources */, 92C21CBC1AAE757A0052ABE6 /* TableViewController.m in Sources */, + 4D4694431AB2E71200AD029E /* Entidade.m in Sources */, + 4D4694461AB2E87300AD029E /* Filme.m in Sources */, 92C21CDB1AAE75B30052ABE6 /* iTunesManager.m in Sources */, 92C21CB91AAE757A0052ABE6 /* AppDelegate.m in Sources */, - 92C21CE81AAE858E0052ABE6 /* Filme.m in Sources */, 92C21CE11AAE76930052ABE6 /* TableViewCell.m in Sources */, 92C21CB61AAE757A0052ABE6 /* main.m in Sources */, ); diff --git a/iTunesSearch/Entidades/Ebook.h b/iTunesSearch/Entidades/Ebook.h new file mode 100644 index 0000000..c8d8778 --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.h @@ -0,0 +1,13 @@ +// +// Ebook.h +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Entidade.h" + +@interface Ebook : Entidade + +@end diff --git a/iTunesSearch/Entidades/Ebook.m b/iTunesSearch/Entidades/Ebook.m new file mode 100644 index 0000000..04b8532 --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.m @@ -0,0 +1,14 @@ +// +// Ebook.m +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Ebook.h" + +@implementation Ebook + + +@end diff --git a/iTunesSearch/Entidades/Entidade.h b/iTunesSearch/Entidades/Entidade.h new file mode 100644 index 0000000..90899bd --- /dev/null +++ b/iTunesSearch/Entidades/Entidade.h @@ -0,0 +1,20 @@ +// +// Entidade.h +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import + +@interface Entidade : NSObject +@property (nonatomic, strong) NSString *nome; +@property (nonatomic, strong) NSString *trackId; +@property (nonatomic, strong) NSString *artista; +@property (nonatomic, strong) NSString *duracao; +@property (nonatomic, strong) NSString *genero; +@property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *imagem; + +@end diff --git a/iTunesSearch/Entidades/Entidade.m b/iTunesSearch/Entidades/Entidade.m new file mode 100644 index 0000000..e8b95e1 --- /dev/null +++ b/iTunesSearch/Entidades/Entidade.m @@ -0,0 +1,13 @@ +// +// Entidade.m +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Entidade.h" + +@implementation Entidade + +@end diff --git a/iTunesSearch/Entidades/Filme.h b/iTunesSearch/Entidades/Filme.h index eb126dc..856db22 100644 --- a/iTunesSearch/Entidades/Filme.h +++ b/iTunesSearch/Entidades/Filme.h @@ -2,19 +2,12 @@ // Filme.h // iTunesSearch // -// Created by joaquim on 09/03/15. +// Created by Patricia Machado de Abreu on 13/03/15. // Copyright (c) 2015 joaquim. All rights reserved. // -#import +#import "Entidade.h" -@interface Filme : NSObject - -@property (nonatomic, strong) NSString *nome; -@property (nonatomic, strong) NSString *trackId; -@property (nonatomic, strong) NSString *artista; -@property (nonatomic, strong) NSString *duracao; -@property (nonatomic, strong) NSString *genero; -@property (nonatomic, strong) NSString *pais; +@interface Filme : Entidade @end diff --git a/iTunesSearch/Entidades/Filme.m b/iTunesSearch/Entidades/Filme.m index f00d84e..c7489ad 100644 --- a/iTunesSearch/Entidades/Filme.m +++ b/iTunesSearch/Entidades/Filme.m @@ -2,7 +2,7 @@ // Filme.m // iTunesSearch // -// Created by joaquim on 09/03/15. +// Created by Patricia Machado de Abreu on 13/03/15. // Copyright (c) 2015 joaquim. All rights reserved. // diff --git a/iTunesSearch/Entidades/Musica.h b/iTunesSearch/Entidades/Musica.h new file mode 100644 index 0000000..db7d34e --- /dev/null +++ b/iTunesSearch/Entidades/Musica.h @@ -0,0 +1,13 @@ +// +// Musica.h +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Entidade.h" + +@interface Musica : Entidade + +@end diff --git a/iTunesSearch/Entidades/Musica.m b/iTunesSearch/Entidades/Musica.m new file mode 100644 index 0000000..4b5fe18 --- /dev/null +++ b/iTunesSearch/Entidades/Musica.m @@ -0,0 +1,13 @@ +// +// Musica.m +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Musica.h" + +@implementation Musica + +@end diff --git a/iTunesSearch/Entidades/Podcast.h b/iTunesSearch/Entidades/Podcast.h new file mode 100644 index 0000000..484a1cb --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.h @@ -0,0 +1,13 @@ +// +// Podcast.h +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Entidade.h" + +@interface Podcast : Entidade + +@end diff --git a/iTunesSearch/Entidades/Podcast.m b/iTunesSearch/Entidades/Podcast.m new file mode 100644 index 0000000..e04299b --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.m @@ -0,0 +1,13 @@ +// +// Podcast.m +// iTunesSearch +// +// Created by Patricia Machado de Abreu on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Podcast.h" + +@implementation Podcast + +@end diff --git a/iTunesSearch/TableView.xib b/iTunesSearch/TableView.xib index 55f128c..728b274 100644 --- a/iTunesSearch/TableView.xib +++ b/iTunesSearch/TableView.xib @@ -1,5 +1,5 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/iTunesSearch/TableViewCell.h b/iTunesSearch/TableViewCell.h index b630349..0eb5077 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 *artista; +@property (weak, nonatomic) IBOutlet UIImageView *imagem; + @end diff --git a/iTunesSearch/TableViewCell.m b/iTunesSearch/TableViewCell.m index ffac89c..7b8af41 100644 --- a/iTunesSearch/TableViewCell.m +++ b/iTunesSearch/TableViewCell.m @@ -20,4 +20,5 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated { // Configure the view for the selected state } + @end diff --git a/iTunesSearch/TableViewCell.xib b/iTunesSearch/TableViewCell.xib index bf8bd3f..17cbac8 100644 --- a/iTunesSearch/TableViewCell.xib +++ b/iTunesSearch/TableViewCell.xib @@ -1,46 +1,98 @@ - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/iTunesSearch/TableViewController.h b/iTunesSearch/TableViewController.h index 0cbb5c4..bc728ad 100644 --- a/iTunesSearch/TableViewController.h +++ b/iTunesSearch/TableViewController.h @@ -12,6 +12,9 @@ @property (strong, nonatomic) IBOutlet UITableView *tableview; +@property (nonatomic) UITextField *textBuscador; +@property (nonatomic) UIButton *buttonBuscador; +@property (nonatomic) NSString *text; @end diff --git a/iTunesSearch/TableViewController.m b/iTunesSearch/TableViewController.m index f689980..3cd33ca 100644 --- a/iTunesSearch/TableViewController.m +++ b/iTunesSearch/TableViewController.m @@ -10,15 +10,21 @@ #import "TableViewCell.h" #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" +#import "Entidade.h" @interface TableViewController () { NSArray *midias; + NSUserDefaults *userDefault; } @end @implementation TableViewController +@synthesize textBuscador, buttonBuscador; - (void)viewDidLoad { @@ -26,12 +32,54 @@ - (void)viewDidLoad { UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; [self.tableview registerNib:nib forCellReuseIdentifier:@"celulaPadrao"]; + userDefault = [NSUserDefaults standardUserDefaults]; + _tableview.delegate = self; + _tableview.dataSource = self; - 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)]; + self.tableview.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 45.f)]; + + textBuscador = [[UITextField alloc] initWithFrame:CGRectMake(5.0f, 20.0f, 230.0f, 25.0f)]; + [textBuscador setBorderStyle:UITextBorderStyleRoundedRect]; + + buttonBuscador = [[UIButton alloc] initWithFrame:CGRectMake(240.0f, 20.0f, 60.0f, 25.0f)]; + + [buttonBuscador addTarget:self action:@selector(buttonBuscador:) forControlEvents:UIControlEventTouchUpInside]; + + [buttonBuscador setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [buttonBuscador setTitle:@"Buscar"forState: UIControlStateNormal]; + [buttonBuscador setFont:[UIFont boldSystemFontOfSize:15.0f]]; + + [self.tableview.tableHeaderView addSubview:textBuscador]; + [self.tableview.tableHeaderView addSubview:buttonBuscador]; + + + if (userDefault == nil) { + iTunesManager *iTunes = [iTunesManager sharedInstance]; + midias = [iTunes buscarMidias:@"Apple"]; + + }else{ + iTunesManager *itunes = [iTunesManager sharedInstance]; + NSString *aux = textBuscador.text; + aux = [aux stringByReplacingOccurrencesOfString:@" " withString:@"+"]; + } + +// Mudança de Idioma + NSString *idioma = [[NSLocale preferredLanguages] objectAtIndex:0]; + + if ([idioma isEqualToString:@"pt"]){ + [buttonBuscador setTitle:@"Buscar" forState:UIControlStateNormal]; + textBuscador.placeholder = @"Digite aqui o que deseja procurar"; + } + if ([idioma isEqualToString:@"en"]){ + [buttonBuscador setTitle:@"Search" forState:UIControlStateNormal]; + textBuscador.placeholder = @"Type here what you want to search"; + } + if ([idioma isEqualToString:@"fr"]){ + [buttonBuscador setTitle:@"Recherche" forState:UIControlStateNormal]; + textBuscador.placeholder = @"Tapez ici ce que vous voulez rechercher"; + } } - (void)didReceiveMemoryWarning { @@ -42,27 +90,104 @@ - (void)didReceiveMemoryWarning { #pragma mark - Metodos do UITableViewDataSource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return [midias count]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [midias count]; + return [[midias objectAtIndex:section]count]; +} + +-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ + switch (section) { + case 0: + return @"Filme"; + break; + case 1: + return @"Musica"; + break; + case 2: + return @"Podcast"; + break; + case 3: + return @"Ebook"; + break; + default: + return nil; + break; + } } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *celula = [self.tableview dequeueReusableCellWithIdentifier:@"celulaPadrao"]; + + Filme *filme; + Musica *musica; + Podcast *podcast; + Ebook *eBook; - Filme *filme = [midias objectAtIndex:indexPath.row]; - - [celula.nome setText:filme.nome]; - [celula.tipo setText:@"Filme"]; + Entidade *entidade; - return celula; + switch (indexPath.section) { + case 0: + entidade = [[Filme alloc] init]; + entidade =[[midias objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + [celula.nome setText:entidade.nome]; + [celula.tipo setText:@"Filme"]; + [celula.artista setText:entidade.artista]; + [celula.imagem setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entidade.imagem]]]]; + return celula; + break; + case 1: + entidade = [[Musica alloc] init]; + entidade = [[midias objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + [celula.nome setText:entidade.nome]; + [celula.tipo setText:@"Musica"]; + [celula.artista setText:entidade.artista]; + [celula.imagem setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entidade.imagem]]]]; + return celula; + break; + case 2: + entidade = [[Podcast alloc] init]; + entidade = [[midias objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + [celula.nome setText:entidade.nome]; + [celula.tipo setText:@"Podcast"]; + [celula.artista setText:entidade.artista]; + [celula.imagem setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entidade.imagem]]]]; + return celula; + break; + case 3: + entidade = [[Ebook alloc] init]; + entidade = [[midias objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + [celula.nome setText:entidade.nome]; + [celula.tipo setText:@"eBook"]; + [celula.artista setText:entidade.artista]; + [celula.imagem setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:entidade.imagem]]]]; + return celula; + break; + default: + return nil; + break; + } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70; } +#pragma mark - Metodo do botão buscador + +-(IBAction)buttonBuscador:(id)sender{ + iTunesManager *itunes = [iTunesManager sharedInstance]; + _text = textBuscador.text; + _text = [_text stringByReplacingOccurrencesOfString:@" " withString:@"+"]; + midias = [itunes buscarMidias:_text]; + + [userDefault setObject:@"TextToSave" forKey:@"keyToLookupString"]; + + [_tableview reloadData]; + [textBuscador resignFirstResponder]; +} + + @end diff --git a/iTunesSearch/iTunesManager.h b/iTunesSearch/iTunesManager.h index c0e366b..7228082 100644 --- a/iTunesSearch/iTunesManager.h +++ b/iTunesSearch/iTunesManager.h @@ -10,6 +10,9 @@ @interface iTunesManager : NSObject +@property NSMutableArray *session; + + /** * gets singleton object. * @return singleton diff --git a/iTunesSearch/iTunesManager.m b/iTunesSearch/iTunesManager.m index e2babda..24d9cd7 100644 --- a/iTunesSearch/iTunesManager.m +++ b/iTunesSearch/iTunesManager.m @@ -8,9 +8,14 @@ #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" @implementation iTunesManager +@synthesize session; + static iTunesManager *SINGLETON = nil; static bool isFirstAccess = YES; @@ -34,9 +39,9 @@ - (NSArray *)buscarMidias:(NSString *)termo { termo = @""; } - NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=movie", termo]; - NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]]; + NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=all", termo]; + NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]]; NSError *error; NSDictionary *resultado = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers @@ -48,19 +53,67 @@ - (NSArray *)buscarMidias:(NSString *)termo { NSArray *resultados = [resultado objectForKey:@"results"]; NSMutableArray *filmes = [[NSMutableArray alloc] init]; + NSMutableArray *musicas = [[NSMutableArray alloc] init]; + NSMutableArray *podcasts = [[NSMutableArray alloc] init]; + NSMutableArray *eBooks = [[NSMutableArray alloc] init]; + Entidade *entidade; for (NSDictionary *item in resultados) { - 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 setGenero:[item objectForKey:@"primaryGenreName"]]; - [filme setPais:[item objectForKey:@"country"]]; - [filmes addObject:filme]; + if ([[item objectForKey:@"kind"] isEqualToString:@"feature-movie"]) { + + entidade = [[Filme alloc] init]; + [entidade setNome:[item objectForKey:@"trackName"]]; + [entidade setTrackId:[item objectForKey:@"trackId"]]; + [entidade setArtista:[item objectForKey:@"artistName"]]; + [entidade setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [entidade setGenero:[item objectForKey:@"primaryGenreName"]]; + [entidade setPais:[item objectForKey:@"country"]]; + [entidade setImagem:[item objectForKey:@"artworkUrl30"]]; + [filmes addObject:entidade]; + } + if ([[item objectForKey:@"kind"] isEqualToString:@"song"]) { + + entidade = [[Musica alloc]init]; + [entidade setNome:[item objectForKey:@"trackName"]]; + [entidade setTrackId:[item objectForKey:@"trackId"]]; + [entidade setArtista:[item objectForKey:@"artistName"]]; + [entidade setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [entidade setGenero:[item objectForKey:@"primaryGenreName"]]; + [entidade setPais:[item objectForKey:@"country"]]; + [entidade setImagem:[item objectForKey:@"artworkUrl30"]]; + [musicas addObject:entidade]; + } + if ([[item objectForKey:@"kind"] isEqualToString:@"podcast"]) { + + entidade = [[Podcast alloc]init]; + [entidade setNome:[item objectForKey:@"trackName"]]; + [entidade setTrackId:[item objectForKey:@"trackId"]]; + [entidade setArtista:[item objectForKey:@"artistName"]]; + [entidade setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [entidade setGenero:[item objectForKey:@"primaryGenreName"]]; + [entidade setPais:[item objectForKey:@"country"]]; + [entidade setImagem:[item objectForKey:@"artworkUrl30"]]; + [podcasts addObject:entidade]; + } + if ([[item objectForKey:@"kind"] isEqualToString:@"ebook"]) { + + entidade= [[Ebook alloc]init]; + [entidade setNome:[item objectForKey:@"trackName"]]; + [entidade setTrackId:[item objectForKey:@"trackId"]]; + [entidade setArtista:[item objectForKey:@"artistName"]]; +// [entidade setNumPaginas:[item objectForKey:@"trackTimeMillis"]]; + [entidade setGenero:[item objectForKey:@"primaryGenreName"]]; +// [entidade setPais:[item objectForKey:@"country"]]; + [entidade setImagem:[item objectForKey:@"artworkUrl30"]]; + [eBooks addObject:entidade]; + } } - return filmes; + + + session = [[NSMutableArray alloc] initWithObjects:filmes, musicas, podcasts, eBooks, nil]; + return session; + }