diff --git a/iTunesSearch.xcodeproj/project.pbxproj b/iTunesSearch.xcodeproj/project.pbxproj index 79e06d7..a7e53e7 100644 --- a/iTunesSearch.xcodeproj/project.pbxproj +++ b/iTunesSearch.xcodeproj/project.pbxproj @@ -7,13 +7,18 @@ objects = { /* Begin PBXBuildFile section */ + 4B87DC251AB0C0F800062A4B /* Musica.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B87DC241AB0C0F800062A4B /* Musica.m */; }; + 4B87DC281AB0C6CD00062A4B /* Podcast.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B87DC271AB0C6CD00062A4B /* Podcast.m */; }; + 4B87DC2B1AB0C90F00062A4B /* Ebook.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B87DC2A1AB0C90F00062A4B /* Ebook.m */; }; + 4B87DC2C1AB0D39E00062A4B /* TableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B87DC2E1AB0D39E00062A4B /* TableView.xib */; }; + 4BC2383F1AB35B39002737DA /* Detalhescel.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BC2383D1AB35B39002737DA /* Detalhescel.m */; }; + 4BC238401AB35B39002737DA /* Detalhescel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4BC2383E1AB35B39002737DA /* Detalhescel.xib */; }; 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 +35,19 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4B87DC231AB0C0F800062A4B /* Musica.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Musica.h; path = Entidades/Musica.h; sourceTree = ""; }; + 4B87DC241AB0C0F800062A4B /* Musica.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Musica.m; path = Entidades/Musica.m; sourceTree = ""; }; + 4B87DC261AB0C6CD00062A4B /* Podcast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Podcast.h; path = Entidades/Podcast.h; sourceTree = ""; }; + 4B87DC271AB0C6CD00062A4B /* Podcast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Podcast.m; path = Entidades/Podcast.m; sourceTree = ""; }; + 4B87DC291AB0C90F00062A4B /* Ebook.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Ebook.h; path = Entidades/Ebook.h; sourceTree = ""; }; + 4B87DC2A1AB0C90F00062A4B /* Ebook.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Ebook.m; path = Entidades/Ebook.m; sourceTree = ""; }; + 4B87DC2D1AB0D39E00062A4B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/TableView.xib; sourceTree = ""; }; + 4B87DC301AB0D3A100062A4B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/TableView.strings; sourceTree = ""; }; + 4B87DC311AB0D3BE00062A4B /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/TableView.strings; sourceTree = ""; }; + 4B87DC321AB0D3DA00062A4B /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/TableView.strings; sourceTree = ""; }; + 4BC2383C1AB35B39002737DA /* Detalhescel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Detalhescel.h; sourceTree = ""; }; + 4BC2383D1AB35B39002737DA /* Detalhescel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Detalhescel.m; sourceTree = ""; }; + 4BC2383E1AB35B39002737DA /* Detalhescel.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Detalhescel.xib; 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 +61,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 = ""; }; @@ -96,7 +113,10 @@ 92C21CB81AAE757A0052ABE6 /* AppDelegate.m */, 92C21CBA1AAE757A0052ABE6 /* TableViewController.h */, 92C21CBB1AAE757A0052ABE6 /* TableViewController.m */, - 92C21CDC1AAE75DC0052ABE6 /* TableView.xib */, + 4B87DC2E1AB0D39E00062A4B /* TableView.xib */, + 4BC2383C1AB35B39002737DA /* Detalhescel.h */, + 4BC2383D1AB35B39002737DA /* Detalhescel.m */, + 4BC2383E1AB35B39002737DA /* Detalhescel.xib */, 92C21CD91AAE75B30052ABE6 /* iTunesManager.h */, 92C21CDA1AAE75B30052ABE6 /* iTunesManager.m */, 92C21CC01AAE757A0052ABE6 /* Images.xcassets */, @@ -146,6 +166,12 @@ children = ( 92C21CE61AAE858E0052ABE6 /* Filme.h */, 92C21CE71AAE858E0052ABE6 /* Filme.m */, + 4B87DC231AB0C0F800062A4B /* Musica.h */, + 4B87DC241AB0C0F800062A4B /* Musica.m */, + 4B87DC261AB0C6CD00062A4B /* Podcast.h */, + 4B87DC271AB0C6CD00062A4B /* Podcast.m */, + 4B87DC291AB0C90F00062A4B /* Ebook.h */, + 4B87DC2A1AB0C90F00062A4B /* Ebook.m */, ); name = Entidades; sourceTree = ""; @@ -232,7 +258,8 @@ files = ( 92C21CC11AAE757A0052ABE6 /* Images.xcassets in Resources */, 92C21CE21AAE76930052ABE6 /* TableViewCell.xib in Resources */, - 92C21CDD1AAE75DC0052ABE6 /* TableView.xib in Resources */, + 4BC238401AB35B39002737DA /* Detalhescel.xib in Resources */, + 4B87DC2C1AB0D39E00062A4B /* TableView.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -250,7 +277,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4BC2383F1AB35B39002737DA /* Detalhescel.m in Sources */, + 4B87DC2B1AB0C90F00062A4B /* Ebook.m in Sources */, 92C21CBC1AAE757A0052ABE6 /* TableViewController.m in Sources */, + 4B87DC251AB0C0F800062A4B /* Musica.m in Sources */, + 4B87DC281AB0C6CD00062A4B /* Podcast.m in Sources */, 92C21CDB1AAE75B30052ABE6 /* iTunesManager.m in Sources */, 92C21CB91AAE757A0052ABE6 /* AppDelegate.m in Sources */, 92C21CE81AAE858E0052ABE6 /* Filme.m in Sources */, @@ -277,6 +308,20 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + 4B87DC2E1AB0D39E00062A4B /* TableView.xib */ = { + isa = PBXVariantGroup; + children = ( + 4B87DC2D1AB0D39E00062A4B /* Base */, + 4B87DC301AB0D3A100062A4B /* en */, + 4B87DC311AB0D3BE00062A4B /* fr */, + 4B87DC321AB0D3DA00062A4B /* pt */, + ); + name = TableView.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 92C21CD11AAE757A0052ABE6 /* Debug */ = { isa = XCBuildConfiguration; diff --git a/iTunesSearch/AppDelegate.m b/iTunesSearch/AppDelegate.m index d513fd8..8ae9bdb 100644 --- a/iTunesSearch/AppDelegate.m +++ b/iTunesSearch/AppDelegate.m @@ -27,8 +27,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( #warning Adicionado codigo para iniciar com a interface do TableView // TableViewController *tvc = [[TableViewController alloc] initWithNibName:@"TableView" bundle:nil]; + TableViewController *tvc = [[TableViewController alloc] init]; - [self.window setRootViewController:tvc]; + + UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:tvc]; + + [[self window]setRootViewController:nc]; + //[self.window setRootViewController:tvc]; + [self.window makeKeyAndVisible]; return YES; } diff --git a/iTunesSearch/Base.lproj/TableView.xib b/iTunesSearch/Base.lproj/TableView.xib new file mode 100644 index 0000000..ee0c227 --- /dev/null +++ b/iTunesSearch/Base.lproj/TableView.xib @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iTunesSearch/Detalhescel.h b/iTunesSearch/Detalhescel.h new file mode 100644 index 0000000..456e309 --- /dev/null +++ b/iTunesSearch/Detalhescel.h @@ -0,0 +1,19 @@ +// +// Detalhescel.h +// iTunesSearch +// +// Created by Mariana Medeiro on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import + +@interface Detalhescel : UIViewController +@property (weak, nonatomic) IBOutlet UIImageView *imagemdetalhes; +@property (weak, nonatomic) IBOutlet UILabel *nome; +@property (weak, nonatomic) IBOutlet UILabel *pais; +@property (weak, nonatomic) IBOutlet UILabel *price; +@property int row; +@property int section; + +@end diff --git a/iTunesSearch/Detalhescel.m b/iTunesSearch/Detalhescel.m new file mode 100644 index 0000000..2a21263 --- /dev/null +++ b/iTunesSearch/Detalhescel.m @@ -0,0 +1,102 @@ +// +// Detalhescel.m +// iTunesSearch +// +// Created by Mariana Medeiro on 13/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Detalhescel.h" +#import "TableViewCell.h" +#import "iTunesManager.h" +#import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" +#import "Detalhescel.h" + +@interface Detalhescel () + +@end + +@implementation Detalhescel + +@synthesize row, section, nome, pais, price; + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. + + +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +-(void) viewWillAppear:(BOOL)animated { + iTunesManager *im = [iTunesManager sharedInstance]; + id objt = [[im.all objectAtIndex:section]objectAtIndex:row]; + + + Filme *filme; + Musica *musica; + Podcast *podcast; + Ebook *ebook; + + switch (section) { + case 0: + filme = objt; + + [nome setText:filme.nome]; + [pais setText:filme.pais]; + [price setText:[NSString stringWithFormat:@"U$$ %@", filme.price]]; + + + break; + + case 1: + musica = objt; + [nome setText:musica.nome]; + [pais setText:musica.pais]; + [price setText:[NSString stringWithFormat:@"U$$ %@", musica.price]]; + + break; + + case 2: + podcast = objt; + [nome setText:podcast.nome]; + [pais setText:podcast.pais]; + [price setText:[NSString stringWithFormat:@"U$$ %@", podcast.price]]; + + break; + + case 3: + ebook = objt; + [nome setText:ebook.nome]; + [price setText:[NSString stringWithFormat:@"U$$ %@", ebook.price]]; + [nome setText:ebook.nome]; + + + + break; + + default: + break; + } + + +} +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/iTunesSearch/Detalhescel.xib b/iTunesSearch/Detalhescel.xib new file mode 100644 index 0000000..18f3d15 --- /dev/null +++ b/iTunesSearch/Detalhescel.xib @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iTunesSearch/Entidades/Ebook.h b/iTunesSearch/Entidades/Ebook.h new file mode 100644 index 0000000..54646c2 --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.h @@ -0,0 +1,23 @@ +// +// Ebook.h +// iTunesSearch +// +// Created by Mariana Medeiro on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import +#import "Filme.h" + +@interface Ebook : 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 *price; + +@end + diff --git a/iTunesSearch/Entidades/Ebook.m b/iTunesSearch/Entidades/Ebook.m new file mode 100644 index 0000000..8a005fe --- /dev/null +++ b/iTunesSearch/Entidades/Ebook.m @@ -0,0 +1,13 @@ +// +// Ebook.m +// iTunesSearch +// +// Created by Mariana Medeiro on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import "Ebook.h" + +@implementation Ebook + +@end diff --git a/iTunesSearch/Entidades/Filme.h b/iTunesSearch/Entidades/Filme.h index eb126dc..91dfbcc 100644 --- a/iTunesSearch/Entidades/Filme.h +++ b/iTunesSearch/Entidades/Filme.h @@ -16,5 +16,7 @@ @property (nonatomic, strong) NSString *duracao; @property (nonatomic, strong) NSString *genero; @property (nonatomic, strong) NSString *pais; +@property (nonatomic, strong) NSString *price; + @end diff --git a/iTunesSearch/Entidades/Musica.h b/iTunesSearch/Entidades/Musica.h new file mode 100644 index 0000000..d0d139e --- /dev/null +++ b/iTunesSearch/Entidades/Musica.h @@ -0,0 +1,23 @@ +// +// Musica.h +// iTunesSearch +// +// Created by Mariana Medeiro on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import +#import "Filme.h" + +@interface Musica : 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 *price; + + +@end diff --git a/iTunesSearch/Entidades/Musica.m b/iTunesSearch/Entidades/Musica.m new file mode 100644 index 0000000..1727d6b --- /dev/null +++ b/iTunesSearch/Entidades/Musica.m @@ -0,0 +1,13 @@ +// +// Musica.m +// iTunesSearch +// +// Created by Mariana Medeiro on 11/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..271c932 --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.h @@ -0,0 +1,23 @@ +// +// Podcast.h +// iTunesSearch +// +// Created by Mariana Medeiro on 11/03/15. +// Copyright (c) 2015 joaquim. All rights reserved. +// + +#import +#import "Filme.h" + +@interface Podcast : 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 *price; + + +@end diff --git a/iTunesSearch/Entidades/Podcast.m b/iTunesSearch/Entidades/Podcast.m new file mode 100644 index 0000000..3789771 --- /dev/null +++ b/iTunesSearch/Entidades/Podcast.m @@ -0,0 +1,16 @@ +// +// Podcast.m +// iTunesSearch +// +// Created by Mariana Medeiro on 11/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 deleted file mode 100644 index 55f128c..0000000 --- a/iTunesSearch/TableView.xib +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iTunesSearch/TableViewCell.h b/iTunesSearch/TableViewCell.h index b630349..b218f26 100644 --- a/iTunesSearch/TableViewCell.h +++ b/iTunesSearch/TableViewCell.h @@ -13,5 +13,8 @@ @property (weak, nonatomic) IBOutlet UILabel *nome; @property (weak, nonatomic) IBOutlet UILabel *tipo; +@property (weak, nonatomic) IBOutlet UILabel *genero; +@property (weak, nonatomic) IBOutlet UILabel *pais; +@property (weak, nonatomic) IBOutlet UILabel *price; @end diff --git a/iTunesSearch/TableViewCell.xib b/iTunesSearch/TableViewCell.xib index bf8bd3f..5ed4776 100644 --- a/iTunesSearch/TableViewCell.xib +++ b/iTunesSearch/TableViewCell.xib @@ -1,5 +1,5 @@ - + @@ -7,40 +7,78 @@ - - + + - + + + + + + + + + + + + + + + + + + + + - + diff --git a/iTunesSearch/TableViewController.h b/iTunesSearch/TableViewController.h index 0cbb5c4..e02ebc4 100644 --- a/iTunesSearch/TableViewController.h +++ b/iTunesSearch/TableViewController.h @@ -11,7 +11,11 @@ @interface TableViewController : UIViewController +@property (strong, nonatomic) IBOutlet UIView *view; @property (strong, nonatomic) IBOutlet UITableView *tableview; +@property (weak, nonatomic) IBOutlet UITextField *textBusca; + +- (IBAction)buttonSearch:(id)sender; @end diff --git a/iTunesSearch/TableViewController.m b/iTunesSearch/TableViewController.m index f689980..7158235 100644 --- a/iTunesSearch/TableViewController.m +++ b/iTunesSearch/TableViewController.m @@ -10,6 +10,10 @@ #import "TableViewCell.h" #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" +#import "Detalhescel.h" @interface TableViewController () { NSArray *midias; @@ -20,18 +24,22 @@ @interface TableViewController () { @implementation TableViewController - - (void)viewDidLoad { [super viewDidLoad]; + _tableview.delegate=self; + _tableview.dataSource=self; + UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; [self.tableview registerNib:nib forCellReuseIdentifier:@"celulaPadrao"]; - iTunesManager *itunes = [iTunesManager sharedInstance]; - midias = [itunes buscarMidias:@"Apple"]; + _tableview.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0); + +// iTunesManager *itunes = [iTunesManager sharedInstance]; +// midias = [itunes buscarMidias:@"all"]; -#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)]; +//#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)]; } - (void)didReceiveMemoryWarning { @@ -42,27 +50,109 @@ - (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 @"filmes"; + break; + case 1: + return @"musicas"; + break; + case 2: + return @"podcasts"; + break; + case 3: + return @"ebooks"; + break; + default: + return nil; + break; + } } -(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"]; + Filme *filme = [[Filme alloc]init]; + Musica *musica = [[Musica alloc]init]; + Podcast *podcast = [[Podcast alloc]init]; + Ebook *ebook = [[Ebook alloc]init]; - return celula; -} + switch (indexPath.section) { + case 0: + filme = [[midias objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; + + [celula.nome setText:filme.nome]; + [celula.tipo setText:@"Filme"]; + [celula.genero setText:filme.genero]; + [celula.pais setText:filme.pais]; + [celula.price setText:[NSString stringWithFormat:@"U$$ %@", filme.price]]; + return celula; + + break; + + case 1: + musica = [[midias objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; [celula.nome setText:musica.nome]; + [celula.tipo setText:@"Musica"]; + [celula.genero setText:musica.genero]; + [celula.pais setText:musica.pais]; + [celula.price setText:[NSString stringWithFormat:@"U$$ %@", musica.price]]; + + return celula; + break; + + case 2: + podcast = [[midias objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; + [celula.nome setText:podcast.nome]; + [celula.tipo setText:@"Podcast"]; + [celula.genero setText:podcast.genero]; + [celula.pais setText:podcast.pais]; + [celula.price setText:[NSString stringWithFormat:@"U$$ %@", podcast.price]]; + + return celula; + break; + + case 3: + ebook = [[midias objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; + [celula.nome setText:ebook.nome]; + [celula.tipo setText:@"Ebook"]; + [celula.genero setText:ebook.genero]; + [celula.pais setText:ebook.pais]; + [celula.price setText:[NSString stringWithFormat:@"U$$ %@", ebook.price]]; + + return celula; + + break; + + default: + break; + } + return nil; + + } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70; } +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ + Detalhescel *det = [[Detalhescel alloc]init]; + det.row = [indexPath row]; + det.section = [indexPath section]; + [[self navigationController]pushViewController:det animated:YES]; +} + +- (IBAction)buttonSearch:(id)sender { + iTunesManager *itunes =[iTunesManager sharedInstance]; + midias = [itunes buscarMidias:_textBusca.text]; + [self.tableview reloadData]; +} @end diff --git a/iTunesSearch/en.lproj/TableView.strings b/iTunesSearch/en.lproj/TableView.strings new file mode 100644 index 0000000..1f93cf5 --- /dev/null +++ b/iTunesSearch/en.lproj/TableView.strings @@ -0,0 +1,3 @@ + +/* Class = "UIButton"; normalTitle = "Search"; ObjectID = "L81-Yn-Hb9"; */ +"L81-Yn-Hb9.normalTitle" = "Search"; diff --git a/iTunesSearch/fr.lproj/TableView.strings b/iTunesSearch/fr.lproj/TableView.strings new file mode 100644 index 0000000..d173177 --- /dev/null +++ b/iTunesSearch/fr.lproj/TableView.strings @@ -0,0 +1,3 @@ + +/* Class = "UIButton"; normalTitle = "Search"; ObjectID = "L81-Yn-Hb9"; */ +"L81-Yn-Hb9.normalTitle" = "Recherche"; diff --git a/iTunesSearch/iTunesManager.h b/iTunesSearch/iTunesManager.h index c0e366b..658eebd 100644 --- a/iTunesSearch/iTunesManager.h +++ b/iTunesSearch/iTunesManager.h @@ -18,4 +18,7 @@ - (NSArray *)buscarMidias:(NSString *)termo; +@property NSMutableArray *all; + + @end diff --git a/iTunesSearch/iTunesManager.m b/iTunesSearch/iTunesManager.m index e2babda..489e96f 100644 --- a/iTunesSearch/iTunesManager.m +++ b/iTunesSearch/iTunesManager.m @@ -8,8 +8,12 @@ #import "iTunesManager.h" #import "Entidades/Filme.h" +#import "Entidades/Musica.h" +#import "Entidades/Podcast.h" +#import "Entidades/Ebook.h" @implementation iTunesManager +@synthesize all; static iTunesManager *SINGLETON = nil; @@ -34,7 +38,7 @@ - (NSArray *)buscarMidias:(NSString *)termo { termo = @""; } - NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=movie", termo]; + NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/search?term=%@&media=all", termo]; NSData *jsonData = [NSData dataWithContentsOfURL: [NSURL URLWithString:url]]; NSError *error; @@ -48,8 +52,13 @@ - (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]; + for (NSDictionary *item in resultados) { + + if ([[item objectForKey:@"kind" ]isEqualToString:@"feature-movie"]) { Filme *filme = [[Filme alloc] init]; [filme setNome:[item objectForKey:@"trackName"]]; [filme setTrackId:[item objectForKey:@"trackId"]]; @@ -57,15 +66,57 @@ - (NSArray *)buscarMidias:(NSString *)termo { [filme setDuracao:[item objectForKey:@"trackTimeMillis"]]; [filme setGenero:[item objectForKey:@"primaryGenreName"]]; [filme setPais:[item objectForKey:@"country"]]; + [filme setPrice:[item objectForKey:@"trackPrice"]]; [filmes addObject:filme]; } - return filmes; + + + + if ([[item objectForKey:@"kind"]isEqualToString:@"song"]) { + Musica *musica = [[Musica alloc]init]; + [musica setNome:[item objectForKey:@"trackName"]]; + [musica setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [musica setGenero:[item objectForKey:@"primaryGenreName"]]; + [musica setPais:[item objectForKey:@"country"]]; + [musica setPrice:[item objectForKey:@"trackPrice"]]; + [musicas addObject:musica]; + } + + + if ([[item objectForKey:@"kind"]isEqualToString:@"podcast"]) { + Podcast *podcast = [[Podcast alloc]init]; + [podcast setNome:[item objectForKey:@"trackName"]]; + [podcast setDuracao:[item objectForKey:@"trackTimeMillis"]]; + [podcast setGenero:[item objectForKey:@"primaryGenreName"]]; + [podcast setPais:[item objectForKey:@"country"]]; + [podcast setPrice:[item objectForKey:@"trackPrice"]]; + [podcasts addObject:podcast]; + } + + + + + if ([[item objectForKey:@"kind"]isEqualToString:@"ebook"]) { + Ebook *ebook = [[Ebook alloc]init]; + [ebook setNome:[item objectForKey:@"trackName"]]; + [ebook setGenero:[item objectForKey:@"primaryGenreName"]]; + [ebook setPais:[item objectForKey:@"country"]]; + [ebook setPrice:[item objectForKey:@"trackPrice"]]; + [ebooks addObject:ebook]; + } +// [all addObject:filmes]; +// [all addObject:musicas]; +// [all addObject:podcasts]; +// [all addObject:ebooks]; + } + all = [[NSMutableArray alloc]initWithObjects:filmes, musicas, podcasts, ebooks, nil]; + return all; + } - #pragma mark - Life Cycle + (id) allocWithZone:(NSZone *)zone diff --git a/iTunesSearch/pt.lproj/TableView.strings b/iTunesSearch/pt.lproj/TableView.strings new file mode 100644 index 0000000..a22afdb --- /dev/null +++ b/iTunesSearch/pt.lproj/TableView.strings @@ -0,0 +1,3 @@ + +/* Class = "UIButton"; normalTitle = "Search"; ObjectID = "L81-Yn-Hb9"; */ +"L81-Yn-Hb9.normalTitle" = "Buscar";