From d958a11cc1618e080b9aab9a0b84c942afd7012a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 21 Oct 2018 18:30:00 +0300 Subject: Chat styling --- Juick/Helpers/ColorScheme.h | 1 + Juick/Helpers/ColorScheme.m | 4 ++++ Juick/ViewControllers/ChatViewController.h | 2 ++ Juick/ViewControllers/ChatViewController.m | 10 +++++++--- Juick/Views/BubbleMessageCell.h | 2 +- Juick/Views/BubbleMessageCell.m | 8 +++++--- 6 files changed, 20 insertions(+), 7 deletions(-) (limited to 'Juick') diff --git a/Juick/Helpers/ColorScheme.h b/Juick/Helpers/ColorScheme.h index cb3c29b..6620a96 100644 --- a/Juick/Helpers/ColorScheme.h +++ b/Juick/Helpers/ColorScheme.h @@ -16,4 +16,5 @@ +(UIColor *) textColor; +(UIColor *) headerBackground; +(UIColor *) linkColor; ++(UIColor *) secondaryBackground; @end diff --git a/Juick/Helpers/ColorScheme.m b/Juick/Helpers/ColorScheme.m index 69fe98f..67e51ea 100644 --- a/Juick/Helpers/ColorScheme.m +++ b/Juick/Helpers/ColorScheme.m @@ -39,5 +39,9 @@ return [self colorWithHex:0x006699]; } ++ (UIColor *) secondaryBackground { + return [self colorWithHex:0xec4b98]; +} + @end diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h index a5c5d5a..4a5133a 100644 --- a/Juick/ViewControllers/ChatViewController.h +++ b/Juick/ViewControllers/ChatViewController.h @@ -12,4 +12,6 @@ @interface ChatViewController : UITableViewController @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, strong) NSString *uname; + +-(void) reloadChat; @end diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m index 489de66..c36bf1a 100644 --- a/Juick/ViewControllers/ChatViewController.m +++ b/Juick/ViewControllers/ChatViewController.m @@ -13,6 +13,7 @@ @interface ChatViewController () @property (nonatomic, readwrite, retain) UIView *inputAccessoryView; +@property (nonatomic, strong) NSString *me; @end @@ -25,8 +26,11 @@ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; self.tableView.allowsSelection = NO; + self.me = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; [self reloadChat]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; + self.refreshControl = [UIRefreshControl new]; + [self.refreshControl addTarget:self action:@selector(reloadChat) forControlEvents:UIControlEventValueChanged]; } -(void) reloadChat { @@ -44,6 +48,7 @@ [self.tableView endUpdates]; [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.messages count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO]; } + [self.refreshControl endRefreshing]; }]; } @@ -59,9 +64,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { BubbleMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"bubbleMessageCell" forIndexPath:indexPath]; - - [cell configureWithMessage:[self.messages objectAtIndex:indexPath.row]]; - + Message *message = [self.messages objectAtIndex:indexPath.row]; + [cell configureWithMessage:message isMe:[self.me isEqualToString:message.user.uname]]; return cell; } diff --git a/Juick/Views/BubbleMessageCell.h b/Juick/Views/BubbleMessageCell.h index 875efd3..933337b 100644 --- a/Juick/Views/BubbleMessageCell.h +++ b/Juick/Views/BubbleMessageCell.h @@ -16,6 +16,6 @@ @property (strong, nonatomic) IBOutlet UILabel *name; @property (strong, nonatomic) IBOutlet FixedLabel *message; --(void) configureWithMessage:(Message *) message; +-(void) configureWithMessage:(Message *) message isMe:(BOOL)isMe; @end diff --git a/Juick/Views/BubbleMessageCell.m b/Juick/Views/BubbleMessageCell.m index 51fbaa2..42b6019 100644 --- a/Juick/Views/BubbleMessageCell.m +++ b/Juick/Views/BubbleMessageCell.m @@ -22,7 +22,11 @@ // Configure the view for the selected state } --(void) configureWithMessage:(Message *)message { +-(void) configureWithMessage:(Message *)message isMe:(BOOL)isMe { + self.message.backgroundColor = isMe ? [ColorScheme secondaryBackground] : [ColorScheme mainBackground]; + self.message.textColor = isMe ? [UIColor whiteColor] : [ColorScheme textColor]; + self.message.linkAttributes = @{ (id)kCTForegroundColorAttributeName: isMe ? [UIColor whiteColor] : [ColorScheme linkColor], + (id)kCTUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle] }; self.name.text = message.user.uname; self.message.text = message.text; self.unreadMarker.text = @""; @@ -37,8 +41,6 @@ completion:nil]; } failure:nil]; self.message.enabledTextCheckingTypes = NSTextCheckingTypeLink; - self.message.backgroundColor = [ColorScheme mainBackground]; - self.message.layer.cornerRadius = 4; self.message.clipsToBounds = YES; self.message.textInsets = UIEdgeInsetsMake(4.0f, 8.0f, 4.0f, 8.0f); } -- cgit v1.2.3