- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSString *CellIdentifier = @"Cell";
- ClearLabelsCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[ClearLabelsCellView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
- cell.backgroundView = [[[GradientView alloc] init] autorelease];
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleLongPress:)];
- longPress.minimumPressDuration = 1.0; //seconds
- longPress.delegate = self;
- [self.tableView addGestureRecognizer:longPress];
- [longPress release];
- }
- [cell.customImageView setImage:[UIImage imageNamed:@"Placeholder.png"]];
- [tableView setBackgroundView:[[[GradientView alloc] init] autorelease]];
- NSString *byauthor = [(Tweet*)[tweets objectAtIndex:indexPath.row] author];
- NSString *imageName =[NSString stringWithString:[(Tweet*)[tweets objectAtIndex:indexPath.row] author]];
- NSString *userImage = [NSString stringWithFormat:@"http://api.twitter.com/1/users/profile_image/%@.json?size=bigger", byauthor];
- NSArray *myArray = [userImage componentsSeparatedByString: @"/"];
- NSString *fileName = (NSString*)[myArray lastObject];
- NSString *picName =[NSString stringWithFormat:@"%@:%@", imageName, fileName];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSError *error;
- NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
- NSString* path = [dataPath stringByAppendingPathComponent:picName];
- UIImage* image = [UIImage imageWithContentsOfFile:path];
- [cell.customImageView setImage:image];
- [cell.textLabel setNumberOfLines:10];
- [cell.textLabel setText:[(Tweet*)[tweets objectAtIndex:indexPath.row] tweet]];
- NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
- //Wed Dec 01 17:08:03 +0000 2010
- //NSDate *date = [df dateFromString:[[tweets objectAtIndex: storyIndex] objectForKey: TWITTER_CREATED_AT_JSON_KEY]];
- NSDate *date = [NSDate dateWithTimeIntervalSince1970: [[time objectAtIndex:indexPath.row] doubleValue]];
- [df setDateFormat:@"ss"];
- NSString *dateStr = [df stringFromDate:date];
- cell.detailTextLabel.text = [NSString stringWithFormat:@"By @%@ %@ ago", byauthor, dateStr];
- cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
- cell.detailTextLabel.textColor = [UIColor grayColor];
- cell.detailTextLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
- usernamestr.text = [NSString stringWithFormat:@"@%@", byauthor];
- [PMRoundImage roundImageCorners:cell.imageView withQuantity:7.0];
- [cell.customImageView setImage: image];
- [cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
- //cell.delegate = self;
- tweetcont.text = [(Tweet*)[tweets objectAtIndex:indexPath.row] tweet];
- [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
- if (!image) {
- UIImage *phoneImage=[UIImage imageWithData:[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:userImage]]];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/ProfilePictures"];
- NSString* path = [dataPath stringByAppendingPathComponent:picName];
- if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
- [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
- NSData* data = UIImagePNGRepresentation(phoneImage);
- [data writeToFile:path atomically:YES];
- [cell.customImageView setImage:image];
- }
- else{
- [cell.customImageView setImage:image];
- }
- return cell;
- }