-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTI.m
195 lines (131 loc) · 7.19 KB
/
TI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// TI.m
// Esqueleto DCU
//
// Created by julio.guzman on 18/11/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
//Vista Tipo Información Un Solo Elemento
/*
Descripción/Datos que utiliza
Entrada:
Se alimenta de los datos obtenidos por un servicio web
Acción:
Construye una vista con los Datos de un titulo particular
Salida:
Al dar click en los botones cerca de la imagen nos lleva a una vista con opciones para compartir el titulo y con la lista de reproducción
Al dar click en los botones inferiores nos lleva a la vista correcpondiente.
*/
#import "TI.h"
#import "SBJSON.h"
#import "CL.h"
#define IMAGEURL @"http://www.descargacultura.unam.mx/images/mp3Icons/"
@implementation TI
@synthesize ID = _ID;
@synthesize dictionary;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil idNumber:(NSString *)idNumber
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_ID = idNumber;
//NSLog(@"TI _ID: %@",_ID);
}
return self;
}
-(IBAction)cl
{
//NSLog(@"Dictionary : %@", dictionary);
CL *nextPage = [[CL alloc] initWithNibName:@"CL" bundle:nil dictionary:dictionary];
nextPage.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.view addSubview:nextPage.view];
[self presentModalViewController:nextPage animated:YES];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[activityindicator startAnimating];
[NSThread detachNewThreadSelector:@selector(parse) toTarget:self withObject:nil];
}
-(void)parse{
//Parsing
@try {
SBJSON *parser = [[SBJSON alloc] init];
NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.unam360.com/dcu/service/info?tipo=num&id=%@", _ID]] encoding:NSISOLatin1StringEncoding error:nil];
string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
NSMutableDictionary *dictionary_ =[parser objectWithString:string error:nil];
//NSLog(@"dictionary %@", dictionary_);
NSArray *array =[dictionary_ objectForKey:@"datos"];
NSMutableDictionary *dictionary1 =[array objectAtIndex:0] ;
dictionary = [[NSMutableDictionary alloc] init] ;
dictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary1];
[dictionary retain];
//NSLog(@"Dictionary : %@", dictionary);
//Titulo
label.text = [dictionary1 objectForKey:@"titulo"];
//Image
[NSThread detachNewThreadSelector:@selector(setImage:) toTarget:image withObject:[UIImage imageWithData:[[NSData alloc] initWithContentsOfURL:[[NSURL alloc] initWithString:[IMAGEURL stringByAppendingString:[dictionary1 objectForKey:@"image"]]]]]];
// [image setImage:[UIImage imageWithData:[[NSData alloc] initWithContentsOfURL:[[NSURL alloc] initWithString:[IMAGEURL stringByAppendingString:[dictionary1 objectForKey:@"image"]]]]]];
//Autores
NSArray *autores = [dictionary1 objectForKey:@"autores"];
NSString *string1 = @"";
for (int i = 0; i<[autores count]; i++) {
NSMutableDictionary *autoresdictionary = [autores objectAtIndex:i];
string1 = [string1 stringByAppendingFormat:@"%@\n", [autoresdictionary objectForKey:@"nombre"]];
}
string1 = [string1 stringByAppendingFormat:@"Editorial: %@\n", [dictionary1 objectForKey:@"Editorial"]];
string1 = [string1 stringByAppendingFormat:@"Lectura a cargo de: %@\n", [dictionary1 objectForKey:@"Lectura a cargo de"]];
string1 = [string1 stringByAppendingFormat:@"Estudio de grabación: %@\n", [dictionary1 objectForKey:@"Estudio de grabacion"]];
string1 = [string1 stringByAppendingFormat:@"Dirección: %@\n", [dictionary1 objectForKey:@"Dirección"]];
string1 = [string1 stringByAppendingFormat:@"Música: %@\n", [dictionary1 objectForKey:@"Música"]];
string1 = [string1 stringByAppendingFormat:@"Año de grabación: %@\n", [dictionary1 objectForKey:@"Año de grabacion"]];
string1 = [string1 stringByAppendingFormat:@"Operación y postproducción: %@", [dictionary1 objectForKey:@"Operación y postproducción"]];
[textview performSelectorOnMainThread:@selector(setText:) withObject:string1 waitUntilDone:YES];
//Descripcion
[textviewdescripcion performSelectorOnMainThread:@selector(setText:) withObject:[dictionary1 objectForKey:@"Descripción"] waitUntilDone:YES];
//Rating
switch ([(NSString *)[dictionary1 objectForKey:@"rating"] intValue]) {
case 0:
[star1 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star2 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star3 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star4 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star5 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
break;
case 1:
[star2 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star3 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star4 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star5 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
case 2:
[star3 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star4 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star5 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
case 3:
[star4 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
[star5 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
case 4:
[star5 performSelectorOnMainThread:@selector(setHidden:) withObject:[NSNumber numberWithBool:YES] waitUntilDone:YES];
default:
break;
}
}
@catch (NSException *exception) {
[self reachability];
}
[activityindicator setHidesWhenStopped:YES];
[activityindicator stopAnimating];
[button setHidden:NO];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end