2010-09-30 22:52:12 -05:00
|
|
|
//
|
|
|
|
// MGMInboxMessageView.m
|
|
|
|
// VoiceMob
|
|
|
|
//
|
|
|
|
// Created by Mr. Gecko on 9/30/10.
|
2013-07-20 06:56:17 -05:00
|
|
|
// Copyright (c) 2011 Mr. Gecko's Media (James Coleman). http://mrgeckosmedia.com/
|
2010-09-30 22:52:12 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "MGMInboxMessageView.h"
|
2010-10-01 22:03:15 -05:00
|
|
|
#import <VoiceBase/VoiceBase.h>
|
2013-07-20 06:56:17 -05:00
|
|
|
#import <MGMUsers/MGMUsers.h>
|
2010-09-30 22:52:12 -05:00
|
|
|
|
|
|
|
@implementation MGMInboxMessageView
|
|
|
|
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
2013-07-20 06:56:17 -05:00
|
|
|
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
|
2010-09-30 22:52:12 -05:00
|
|
|
nameField = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
|
[nameField setBackgroundColor:[UIColor clearColor]];
|
|
|
|
[nameField setFont:[UIFont boldSystemFontOfSize:18.0]];
|
|
|
|
[[self contentView] addSubview:nameField];
|
|
|
|
dateField = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
|
[dateField setBackgroundColor:[UIColor clearColor]];
|
|
|
|
[dateField setFont:[UIFont systemFontOfSize:12.0]];
|
|
|
|
[dateField setTextAlignment:UITextAlignmentRight];
|
|
|
|
[dateField setTextColor:[UIColor blueColor]];
|
|
|
|
[[self contentView] addSubview:dateField];
|
|
|
|
messageField = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
|
[messageField setBackgroundColor:[UIColor clearColor]];
|
|
|
|
[messageField setFont:[UIFont systemFontOfSize:12.0]];
|
|
|
|
[messageField setLineBreakMode:UILineBreakModeWordWrap];
|
|
|
|
[messageField setNumberOfLines:0];
|
|
|
|
[messageField setTextColor:[UIColor grayColor]];
|
|
|
|
[[self contentView] addSubview:messageField];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (void)dealloc {
|
2013-07-20 06:56:17 -05:00
|
|
|
#if releaseDebug
|
|
|
|
NSLog(@"%s Releasing", __PRETTY_FUNCTION__);
|
|
|
|
#endif
|
|
|
|
[nameField release];
|
|
|
|
[dateField release];
|
|
|
|
[messageField release];
|
|
|
|
[messageData release];
|
2010-09-30 22:52:12 -05:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setInstance:(MGMInstance *)theInstance {
|
|
|
|
instance = theInstance;
|
|
|
|
}
|
|
|
|
- (void)setMessageData:(NSDictionary *)theMessageData {
|
2013-07-20 06:56:17 -05:00
|
|
|
[messageData release];
|
2010-09-30 22:52:12 -05:00
|
|
|
messageData = [theMessageData retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
[super layoutSubviews];
|
|
|
|
|
|
|
|
CGRect frameRect = [[self contentView] bounds];
|
|
|
|
|
2013-07-20 06:56:17 -05:00
|
|
|
if (messageData!=nil) {
|
2010-09-30 22:52:12 -05:00
|
|
|
[nameField setText:[[instance contacts] nameForNumber:[messageData objectForKey:MGMIPhoneNumber]]];
|
|
|
|
int type = [[messageData objectForKey:MGMIType] intValue];
|
2013-07-20 06:56:17 -05:00
|
|
|
if (type==MGMIVoicemailType)
|
2010-09-30 22:52:12 -05:00
|
|
|
[messageField setText:[messageData objectForKey:MGMIText]];
|
2013-07-20 06:56:17 -05:00
|
|
|
else if (type==MGMISMSInType || type==MGMISMSOutType)
|
2010-09-30 22:52:12 -05:00
|
|
|
[messageField setText:[[[[messageData objectForKey:MGMIMessages] lastObject] objectForKey:MGMIText] flattenHTML]];
|
2013-07-20 06:56:17 -05:00
|
|
|
else
|
2010-09-30 22:52:12 -05:00
|
|
|
[messageField setText:[[[messageData objectForKey:MGMIPhoneNumber] areaCode] areaCodeLocation]];
|
|
|
|
NSDate *today = [NSDate dateWithTimeIntervalSinceNow:-86400];
|
|
|
|
if ([[messageData objectForKey:MGMITime] earlierDate:today]==today) {
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter new] autorelease];
|
|
|
|
[formatter setDateFormat:@"h:mm a"];
|
|
|
|
[dateField setText:[formatter stringFromDate:[messageData objectForKey:MGMITime]]];
|
|
|
|
} else {
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter new] autorelease];
|
|
|
|
[formatter setDateFormat:@"M/d/yy"];
|
|
|
|
[dateField setText:[formatter stringFromDate:[messageData objectForKey:MGMITime]]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-20 06:56:17 -05:00
|
|
|
[nameField setFrame:CGRectMake(20, 3, frameRect.size.width-86, 20)];
|
2010-09-30 22:52:12 -05:00
|
|
|
[dateField setFrame:CGRectMake(frameRect.size.width-64, 3, 60, 20)];
|
2013-07-20 06:56:17 -05:00
|
|
|
[messageField setFrame:CGRectMake(20, frameRect.size.height-41, frameRect.size.width-18, 32)];
|
|
|
|
[self setNeedsDisplay];
|
|
|
|
}
|
|
|
|
- (void)drawRect:(CGRect)rect {
|
|
|
|
if (messageData!=nil) {
|
|
|
|
if (![[messageData objectForKey:MGMIRead] boolValue]) {
|
|
|
|
CGRect frameRect = [[self contentView] bounds];
|
|
|
|
MGMPath *path = [MGMPath pathWithRoundedRect:CGRectMake(4, (frameRect.size.height/2)-6.5, 13, 13) cornerRadius:6.5];
|
|
|
|
[path fillGradientFrom:[UIColor colorWithRed:0.5215 green:0.6901 blue:0.9607 alpha:1.0] to:[UIColor colorWithRed:0.1255 green:0.3138 blue:0.6589 alpha:1.0]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[super drawRect:rect];
|
2010-09-30 22:52:12 -05:00
|
|
|
}
|
|
|
|
@end
|