Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MyConvercationsViewController.h
- // ImaSpanse
- //
- // Created by IgorBizi@mail.ru on 6/21/15.
- // Copyright (c) 2015 Danny Group LLC. All rights reserved.
- //
- #import "ConvercationListViewController.h"
- // * Conversation between 2 people
- @interface MyConvercationsViewController : ConvercationListViewController
- @end
- //
- // MyConvercationsViewController.m
- // ImaSpanse
- //
- // Created by IgorBizi@mail.ru on 6/21/15.
- // Copyright (c) 2015 Danny Group LLC. All rights reserved.
- //
- #import "MyConvercationsViewController.h"
- @interface MyConvercationsViewController ()
- @end
- @implementation MyConvercationsViewController
- #pragma mark - Abstract Class
- - (ConvercationType)convercationType
- {
- return ConvercationTypeSingleChat;
- }
- #pragma mark - LifeCycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self setup];
- }
- - (void)setup
- {
- [super setup];
- self.dataSource = [[TestDataClass testMessages] mutableCopy];
- }
- @end
- //
- // MyConvercationsViewController.m
- // ImaSpanse
- //
- // Created by IgorBizi@mail.ru on 5/2/15.
- // Copyright (c) 2015 Evgeniy Melkov. All rights reserved.
- //
- #import "ConvercationListViewController.h"
- #import <TinyUtils/NSDate+Utilities.h>
- #import "ConversationCell.h"
- #import "Conversation.h"
- #import "UITableViewCell+SelectionBackground.h"
- #import "OnlineView.h"
- #import "RoundImageView.h"
- #import "SingleChatViewController.h"
- #import "GroupChatViewController.h"
- #import <SDWebImage/UIImageView+WebCache.h>
- #define kCellIdentifier_ConversationCell @"ConversationCell"
- #define k_ROW_HEIGHT 80.0
- @interface ConvercationListViewController ()
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @end
- @implementation ConvercationListViewController
- #pragma mark - RootViewController
- - (BOOL)navigationBarBottomShadowEnabled
- {
- return NO;
- }
- - (BOOL)tabBarIsHidden
- {
- return NO;
- }
- #pragma mark - Abstract Class
- - (ConvercationType)convercationType
- {
- NSLog(@"ERROR: convercationListType must implement");
- return ConvercationTypeUnnown;
- }
- #pragma mark - Getters/Setters
- - (void)setDataSource:(NSMutableArray *)dataSource
- {
- _dataSource = dataSource;
- [self.tableView reloadData];
- }
- #pragma mark - LifeCycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self setup];
- }
- - (void)setup
- {
- [self.tableView registerNib:[UINib nibWithNibName:@"ConversationCell" bundle:nil] forCellReuseIdentifier:kCellIdentifier_ConversationCell];
- self.tableView.rowHeight = k_ROW_HEIGHT;
- self.tableView.separatorColor = [UIColor k_greyTableViewSeparator];
- self.tableView.backgroundColor = [UIColor k_mainBackground];
- }
- #pragma mark - TableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- ConversationCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ConversationCell];
- [self configurateCell:cell forRowAtIndexPath:indexPath];
- return cell;
- }
- - (void)configurateCell:(ConversationCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- Conversation *conversation = self.dataSource[indexPath.row];
- cell.nameLabel.text = conversation.name;
- cell.online = conversation.online;
- cell.unread = conversation.unread;
- NSDateFormatter *dateFormatter = [[Assistant sharedInstance] dateFormatterWithFormat:DateFormatTimeOrDateWithFlexibleYear withPickedDate:conversation.date];
- cell.dateLabel.text = [dateFormatter stringFromDate:conversation.date];
- cell.messageLabel.text = conversation.message;
- // * Update onlineView
- cell.onlineViewHidden = self.convercationType == ConvercationTypeGroupChat;
- // * Handle photo/placeholder and stroke
- UIImage *placeholderImage = nil;
- if (self.convercationType == ConvercationTypeSingleChat) {
- placeholderImage = [RoundImageView placeholderWithGenderType:conversation.gender];
- [cell.photoImageView strokeWithGenderType:conversation.gender];
- } else if (self.convercationType == ConvercationTypeGroupChat) {
- placeholderImage = [RoundImageView placeholderWithType:PlaceholderTypeEvent];
- [cell.photoImageView strokeWithType:PlaceholderTypeEvent];
- }
- [cell.photoImageView sd_setImageWithURL:conversation.imageURL placeholderImage:placeholderImage];
- // * Part of custom selecton BG color
- [cell setSelectionBackground];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(ConversationCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // * Separator base on content
- cell.separatorInset = UIEdgeInsetsMake(0.0, cell.photoImageView.frame.origin.x, 0.0, -cell.contentView.bounds.size.width);
- // * Part of custom selecton BG color
- [cell handleSelectionBackground];
- }
- #pragma mark - Events
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- [self startChatWithConversationAtIndexPath:indexPath];
- }
- - (void)startChatWithConversationAtIndexPath:(NSIndexPath *)indexPath
- {
- Conversation *conversation = self.dataSource[indexPath.row];
- if (self.convercationType == ConvercationTypeSingleChat) {
- SingleChatViewController *chatViewController = [[SingleChatViewController alloc]init];
- chatViewController.conversation = conversation;
- [self.navigationController pushViewController:chatViewController animated:YES];
- } else if (self.convercationType == ConvercationTypeGroupChat) {
- GroupChatViewController *groupChatViewController = [[GroupChatViewController alloc]init];
- groupChatViewController.conversation = conversation;
- [self.navigationController pushViewController:groupChatViewController animated:YES];
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement