refactored: dateLabel --> timestamp

This commit is contained in:
Jesse Squires
2013-03-20 10:17:17 -04:00
parent 7fd1153a4b
commit bc086a2845
8 changed files with 73 additions and 66 deletions

View File

@@ -42,11 +42,11 @@
#pragma mark - Initialization
- (id)initWithBubbleStyle:(JSBubbleMessageStyle)style
hasDate:(BOOL)hasDate
hasTimestamp:(BOOL)hasTimestamp
reuseIdentifier:(NSString *)reuseIdentifier;
#pragma mark - Message Cell
- (void)setMessage:(NSString *)msg;
- (void)setDate:(NSDate *)date;
- (void)setTimestamp:(NSDate *)date;
@end

View File

@@ -39,11 +39,11 @@
@interface JSBubbleMessageCell()
@property (strong, nonatomic) JSBubbleView *bubbleView;
@property (strong, nonatomic) UILabel *dateLabel;
@property (strong, nonatomic) UILabel *timestampLabel;
- (void)setup;
- (void)configureDateLabel;
- (void)configureWithStyle:(JSBubbleMessageStyle)style date:(BOOL)hasDate;
- (void)configureTimestampLabel;
- (void)configureWithStyle:(JSBubbleMessageStyle)style timestamp:(BOOL)hasTimestamp;
@end
@@ -67,37 +67,37 @@
self.detailTextLabel.hidden = YES;
}
- (void)configureDateLabel
- (void)configureTimestampLabel
{
self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f,
4.0f,
[UIScreen mainScreen].bounds.size.width,
14.5f)];
self.dateLabel.autoresizingMask = UIViewAutoresizingNone;
self.dateLabel.backgroundColor = [UIColor clearColor];
self.dateLabel.textAlignment = NSTextAlignmentCenter;
self.dateLabel.textColor = [UIColor messagesDateLabelColor];
self.dateLabel.shadowColor = [UIColor whiteColor];
self.dateLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
self.dateLabel.font = [UIFont boldSystemFontOfSize:11.5f];
self.timestampLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f,
4.0f,
[UIScreen mainScreen].bounds.size.width,
14.5f)];
self.timestampLabel.autoresizingMask = UIViewAutoresizingNone;
self.timestampLabel.backgroundColor = [UIColor clearColor];
self.timestampLabel.textAlignment = NSTextAlignmentCenter;
self.timestampLabel.textColor = [UIColor messagesTimestampColor];
self.timestampLabel.shadowColor = [UIColor whiteColor];
self.timestampLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
self.timestampLabel.font = [UIFont boldSystemFontOfSize:11.5f];
[self.contentView addSubview:self.dateLabel];
[self.contentView bringSubviewToFront:self.dateLabel];
[self.contentView addSubview:self.timestampLabel];
[self.contentView bringSubviewToFront:self.timestampLabel];
}
- (void)configureWithStyle:(JSBubbleMessageStyle)style date:(BOOL)hasDate
- (void)configureWithStyle:(JSBubbleMessageStyle)style timestamp:(BOOL)hasTimestamp
{
CGFloat bubbleY = 0.0f;
if(hasDate) {
[self configureDateLabel];
if(hasTimestamp) {
[self configureTimestampLabel];
bubbleY = 14.0f;
}
CGRect frame = CGRectMake(0.0f,
bubbleY,
self.contentView.frame.size.width,
self.contentView.frame.size.height - self.dateLabel.frame.size.height);
self.contentView.frame.size.height - self.timestampLabel.frame.size.height);
self.bubbleView = [[JSBubbleView alloc] initWithFrame:frame
bubbleStyle:style];
@@ -108,12 +108,12 @@
[self.contentView sendSubviewToBack:self.bubbleView];
}
- (id)initWithBubbleStyle:(JSBubbleMessageStyle)style hasDate:(BOOL)hasDate reuseIdentifier:(NSString *)reuseIdentifier
- (id)initWithBubbleStyle:(JSBubbleMessageStyle)style hasTimestamp:(BOOL)hasTimestamp reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
if(self) {
[self setup];
[self configureWithStyle:style date:hasDate];
[self configureWithStyle:style timestamp:hasTimestamp];
}
return self;
}
@@ -132,11 +132,11 @@
self.bubbleView.text = msg;
}
- (void)setDate:(NSDate *)date
- (void)setTimestamp:(NSDate *)date
{
self.dateLabel.text = [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterShortStyle];
self.timestampLabel.text = [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterShortStyle];
}
@end

View File

@@ -40,18 +40,18 @@
#import "JSMessageSoundEffect.h"
typedef enum {
JSMessagesViewDateLabelPolicyAll = 0,
JSMessagesViewDateLabelPolicyAlternating,
JSMessagesViewDateLabelPolicyEveryThree,
JSMessagesViewDateLabelPolicyEveryFive,
JSMessagesViewDateLabelPolicyCustom
} JSMessagesViewDateLabelPolicy;
JSMessagesViewTimestampPolicyAll = 0,
JSMessagesViewTimestampPolicyAlternating,
JSMessagesViewTimestampPolicyEveryThree,
JSMessagesViewTimestampPolicyEveryFive,
JSMessagesViewTimestampPolicyCustom
} JSMessagesViewTimestampPolicy;
@interface JSMessagesViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextViewDelegate>
@property (assign, nonatomic) JSMessagesViewDateLabelPolicy dateLabelPolicy;
@property (assign, nonatomic) JSMessagesViewTimestampPolicy timestampPolicy;
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) JSMessageInputView *inputView;
@property (assign, nonatomic) CGFloat previousTextViewContentHeight;
@@ -64,8 +64,8 @@ typedef enum {
#pragma mark - Messages view controller
- (JSBubbleMessageStyle)messageStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSString *)textForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSDate *)dateForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)shouldHaveDateForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)shouldHaveTimestampForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)finishSend;
- (void)setBackgroundColor:(UIColor *)color;
- (void)scrollToBottomAnimated:(BOOL)animated;

View File

@@ -81,7 +81,7 @@
{
[super viewDidLoad];
[self setup];
self.dateLabelPolicy = JSMessagesViewDateLabelPolicyEveryThree;
self.timestampPolicy = JSMessagesViewTimestampPolicyEveryThree;
}
- (void)viewWillAppear:(BOOL)animated
@@ -157,19 +157,19 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
JSBubbleMessageStyle style = [self messageStyleForRowAtIndexPath:indexPath];
BOOL hasDate = [self shouldHaveDateForRowAtIndexPath:indexPath];
BOOL hasTimestamp = [self shouldHaveTimestampForRowAtIndexPath:indexPath];
NSString *CellID = [NSString stringWithFormat:@"MessageCell_%d_%d", style, hasDate];
NSString *CellID = [NSString stringWithFormat:@"MessageCell_%d_%d", style, hasTimestamp];
JSBubbleMessageCell *cell = (JSBubbleMessageCell *)[tableView dequeueReusableCellWithIdentifier:CellID];
if(!cell) {
cell = [[JSBubbleMessageCell alloc] initWithBubbleStyle:style
hasDate:hasDate
hasTimestamp:hasTimestamp
reuseIdentifier:CellID];
}
if(hasDate)
[cell setDate:[self dateForRowAtIndexPath:indexPath]];
if(hasTimestamp)
[cell setTimestamp:[self timestampForRowAtIndexPath:indexPath]];
[cell setMessage:[self textForRowAtIndexPath:indexPath]];
[cell setBackgroundColor:tableView.backgroundColor];
@@ -180,7 +180,7 @@
#pragma mark - Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat dateHeight = [self shouldHaveDateForRowAtIndexPath:indexPath] ? DATE_LABEL_HEIGHT : 0.0f;
CGFloat dateHeight = [self shouldHaveTimestampForRowAtIndexPath:indexPath] ? DATE_LABEL_HEIGHT : 0.0f;
return [JSBubbleView cellHeightForText:[self textForRowAtIndexPath:indexPath]] + dateHeight;
}
@@ -196,27 +196,27 @@
return nil; // Override in subclass
}
- (NSDate *)dateForRowAtIndexPath:(NSIndexPath *)indexPath
- (NSDate *)timestampForRowAtIndexPath:(NSIndexPath *)indexPath
{
return nil; // Override in subclass
}
- (BOOL)shouldHaveDateForRowAtIndexPath:(NSIndexPath *)indexPath // Override in subclass if using JSMessagesViewDateLabelPolicyCustom
- (BOOL)shouldHaveTimestampForRowAtIndexPath:(NSIndexPath *)indexPath // Override in subclass if using JSMessagesViewTimestampPolicyCustom
{
switch (self.dateLabelPolicy) {
case JSMessagesViewDateLabelPolicyAll:
switch (self.timestampPolicy) {
case JSMessagesViewTimestampPolicyAll:
return YES;
break;
case JSMessagesViewDateLabelPolicyAlternating:
case JSMessagesViewTimestampPolicyAlternating:
return indexPath.row % 2 == 0;
break;
case JSMessagesViewDateLabelPolicyEveryThree:
case JSMessagesViewTimestampPolicyEveryThree:
return indexPath.row % 3 == 0;
break;
case JSMessagesViewDateLabelPolicyEveryFive:
case JSMessagesViewTimestampPolicyEveryFive:
return indexPath.row % 5 == 0;
break;
case JSMessagesViewDateLabelPolicyCustom:
case JSMessagesViewTimestampPolicyCustom:
return NO;
break;
}

View File

@@ -31,6 +31,6 @@
@interface UIColor (JSMessagesView)
+ (UIColor *)messagesBackgroundColor;
+ (UIColor *)messagesDateLabelColor;
+ (UIColor *)messagesTimestampColor;
@end

View File

@@ -35,7 +35,7 @@
return [UIColor colorWithRed:0.859f green:0.886f blue:0.929f alpha:1.0f];
}
+ (UIColor *)messagesDateLabelColor
+ (UIColor *)messagesTimestampColor
{
return [UIColor colorWithRed:0.533f green:0.573f blue:0.647f alpha:1.0f];
}