Advertisement
Guest User

Untitled

a guest
Dec 28th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. //
  2. // MyConvercationsViewController.h
  3. // ImaSpanse
  4. //
  5. // Created by IgorBizi@mail.ru on 6/21/15.
  6. // Copyright (c) 2015 Danny Group LLC. All rights reserved.
  7. //
  8.  
  9. #import "ConvercationListViewController.h"
  10.  
  11.  
  12. // * Conversation between 2 people
  13. @interface MyConvercationsViewController : ConvercationListViewController
  14.  
  15. @end
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. //
  24. // MyConvercationsViewController.m
  25. // ImaSpanse
  26. //
  27. // Created by IgorBizi@mail.ru on 6/21/15.
  28. // Copyright (c) 2015 Danny Group LLC. All rights reserved.
  29. //
  30.  
  31. #import "MyConvercationsViewController.h"
  32.  
  33.  
  34. @interface MyConvercationsViewController ()
  35. @end
  36.  
  37.  
  38. @implementation MyConvercationsViewController
  39.  
  40.  
  41. #pragma mark - Abstract Class
  42.  
  43.  
  44. - (ConvercationType)convercationType
  45. {
  46. return ConvercationTypeSingleChat;
  47. }
  48.  
  49.  
  50. #pragma mark - LifeCycle
  51.  
  52.  
  53. - (void)viewDidLoad
  54. {
  55. [super viewDidLoad];
  56. [self setup];
  57. }
  58.  
  59. - (void)setup
  60. {
  61. [super setup];
  62. self.dataSource = [[TestDataClass testMessages] mutableCopy];
  63. }
  64.  
  65.  
  66. @end
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. //
  77. // MyConvercationsViewController.m
  78. // ImaSpanse
  79. //
  80. // Created by IgorBizi@mail.ru on 5/2/15.
  81. // Copyright (c) 2015 Evgeniy Melkov. All rights reserved.
  82. //
  83.  
  84. #import "ConvercationListViewController.h"
  85. #import <TinyUtils/NSDate+Utilities.h>
  86. #import "ConversationCell.h"
  87. #import "Conversation.h"
  88. #import "UITableViewCell+SelectionBackground.h"
  89. #import "OnlineView.h"
  90. #import "RoundImageView.h"
  91. #import "SingleChatViewController.h"
  92. #import "GroupChatViewController.h"
  93. #import <SDWebImage/UIImageView+WebCache.h>
  94.  
  95.  
  96. #define kCellIdentifier_ConversationCell @"ConversationCell"
  97. #define k_ROW_HEIGHT 80.0
  98.  
  99.  
  100. @interface ConvercationListViewController ()
  101. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  102. @end
  103.  
  104.  
  105. @implementation ConvercationListViewController
  106.  
  107.  
  108. #pragma mark - RootViewController
  109.  
  110.  
  111. - (BOOL)navigationBarBottomShadowEnabled
  112. {
  113. return NO;
  114. }
  115.  
  116. - (BOOL)tabBarIsHidden
  117. {
  118. return NO;
  119. }
  120.  
  121.  
  122. #pragma mark - Abstract Class
  123.  
  124.  
  125. - (ConvercationType)convercationType
  126. {
  127. NSLog(@"ERROR: convercationListType must implement");
  128. return ConvercationTypeUnnown;
  129. }
  130.  
  131.  
  132. #pragma mark - Getters/Setters
  133.  
  134.  
  135. - (void)setDataSource:(NSMutableArray *)dataSource
  136. {
  137. _dataSource = dataSource;
  138. [self.tableView reloadData];
  139. }
  140.  
  141.  
  142. #pragma mark - LifeCycle
  143.  
  144.  
  145. - (void)viewDidLoad
  146. {
  147. [super viewDidLoad];
  148.  
  149. [self setup];
  150. }
  151.  
  152. - (void)setup
  153. {
  154. [self.tableView registerNib:[UINib nibWithNibName:@"ConversationCell" bundle:nil] forCellReuseIdentifier:kCellIdentifier_ConversationCell];
  155. self.tableView.rowHeight = k_ROW_HEIGHT;
  156. self.tableView.separatorColor = [UIColor k_greyTableViewSeparator];
  157. self.tableView.backgroundColor = [UIColor k_mainBackground];
  158. }
  159.  
  160.  
  161. #pragma mark - TableViewDataSource
  162.  
  163.  
  164. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  165. {
  166. return 1;
  167. }
  168.  
  169. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  170. {
  171. return self.dataSource.count;
  172. }
  173.  
  174. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  175. ConversationCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier_ConversationCell];
  176. [self configurateCell:cell forRowAtIndexPath:indexPath];
  177.  
  178. return cell;
  179. }
  180.  
  181. - (void)configurateCell:(ConversationCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  182. {
  183. Conversation *conversation = self.dataSource[indexPath.row];
  184. cell.nameLabel.text = conversation.name;
  185. cell.online = conversation.online;
  186. cell.unread = conversation.unread;
  187. NSDateFormatter *dateFormatter = [[Assistant sharedInstance] dateFormatterWithFormat:DateFormatTimeOrDateWithFlexibleYear withPickedDate:conversation.date];
  188. cell.dateLabel.text = [dateFormatter stringFromDate:conversation.date];
  189. cell.messageLabel.text = conversation.message;
  190.  
  191. // * Update onlineView
  192. cell.onlineViewHidden = self.convercationType == ConvercationTypeGroupChat;
  193.  
  194. // * Handle photo/placeholder and stroke
  195. UIImage *placeholderImage = nil;
  196. if (self.convercationType == ConvercationTypeSingleChat) {
  197. placeholderImage = [RoundImageView placeholderWithGenderType:conversation.gender];
  198. [cell.photoImageView strokeWithGenderType:conversation.gender];
  199. } else if (self.convercationType == ConvercationTypeGroupChat) {
  200. placeholderImage = [RoundImageView placeholderWithType:PlaceholderTypeEvent];
  201. [cell.photoImageView strokeWithType:PlaceholderTypeEvent];
  202. }
  203. [cell.photoImageView sd_setImageWithURL:conversation.imageURL placeholderImage:placeholderImage];
  204.  
  205. // * Part of custom selecton BG color
  206. [cell setSelectionBackground];
  207. }
  208.  
  209. - (void)tableView:(UITableView *)tableView willDisplayCell:(ConversationCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  210. {
  211. // * Separator base on content
  212. cell.separatorInset = UIEdgeInsetsMake(0.0, cell.photoImageView.frame.origin.x, 0.0, -cell.contentView.bounds.size.width);
  213.  
  214. // * Part of custom selecton BG color
  215. [cell handleSelectionBackground];
  216. }
  217.  
  218.  
  219. #pragma mark - Events
  220.  
  221.  
  222. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  223. {
  224. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  225. [self startChatWithConversationAtIndexPath:indexPath];
  226. }
  227.  
  228. - (void)startChatWithConversationAtIndexPath:(NSIndexPath *)indexPath
  229. {
  230. Conversation *conversation = self.dataSource[indexPath.row];
  231.  
  232. if (self.convercationType == ConvercationTypeSingleChat) {
  233. SingleChatViewController *chatViewController = [[SingleChatViewController alloc]init];
  234. chatViewController.conversation = conversation;
  235. [self.navigationController pushViewController:chatViewController animated:YES];
  236. } else if (self.convercationType == ConvercationTypeGroupChat) {
  237. GroupChatViewController *groupChatViewController = [[GroupChatViewController alloc]init];
  238. groupChatViewController.conversation = conversation;
  239. [self.navigationController pushViewController:groupChatViewController animated:YES];
  240. }
  241. }
  242.  
  243.  
  244. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement