/* Copyright (c) 2011 Artjom Popov */

#import "UTHistoryCell.h"

@implementation UTHistoryCell

#define UTHistoryCellActivityIndicatorViewTag 2001

@dynamic activityIndicatorView;

- (UIActivityIndicatorView *)activityIndicatorView
{
	return (UIActivityIndicatorView *)[self viewWithTag: UTHistoryCellActivityIndicatorViewTag];
}


#pragma mark UITableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	
    if(self){
		UIActivityIndicatorView *activityIndicatorView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
		activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin |
		UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
		activityIndicatorView.hidesWhenStopped = YES;
		activityIndicatorView.tag = UTHistoryCellActivityIndicatorViewTag;
		activityIndicatorView.center = CGPointMake(self.imageView.bounds.size.width/2, self.imageView.bounds.size.height/2);
		[self addSubview:activityIndicatorView];
    }
	
    return self;
}

- (void)layoutSubviews
{
	[super layoutSubviews];
	
	CGRect r_1 = self.textLabel.frame;
	CGRect r_2 = self.detailTextLabel.frame;
	
	CGRect rect = CGRectMake(15.0F, 15.0F, 60.0F, 60.0F);
	
	self.textLabel.frame = CGRectMake(r_1.origin.x, r_1.origin.y, r_1.size.width , r_1.size.height);
	self.detailTextLabel.frame = CGRectMake(r_1.origin.x, r_2.origin.y, r_2.size.width, r_2.size.height);
	self.imageView.frame = rect;
	
	self.activityIndicatorView.center = CGPointMake(rect.origin.x + rect.size.width/2, rect.origin.y + rect.size.height/2);
	
}

#pragma mark NSObject

- (void)dealloc 
{
    [super dealloc];
}

@end
