WFCUPluginBoardView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // PluginBoardView.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/29.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUPluginBoardView.h"
  9. #import "WFCUPluginItemView.h"
  10. #define PLUGIN_AREA_HEIGHT 211
  11. #define LeftOffset ([UIScreen mainScreen].bounds.size.width-75*4)/5.0
  12. #define RCPlaginBoardCellSize ((CGSize){ 75, 80 })
  13. #define HorizontalItemsCount 4
  14. #define VerticalItemsCount 2
  15. @interface PluginItem : NSObject
  16. @property(nonatomic, strong)UIImage *image;
  17. @property(nonatomic, strong)NSString *title;
  18. @property(nonatomic, assign)NSUInteger tag;
  19. - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSUInteger)tag;
  20. @end
  21. @implementation PluginItem
  22. - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSUInteger)tag {
  23. self = [super init];
  24. if (self) {
  25. self.title = title;
  26. self.image = image;
  27. self.tag = tag;
  28. }
  29. return self;
  30. }
  31. @end
  32. @interface WFCUPluginBoardView()
  33. @property (nonatomic, strong)NSMutableArray *pluginItems;
  34. @property (nonatomic, weak)id<WFCUPluginBoardViewDelegate> delegate;
  35. @property (nonatomic, assign)BOOL hasVoip;
  36. @end
  37. @implementation WFCUPluginBoardView
  38. - (instancetype)initWithDelegate:(id<WFCUPluginBoardViewDelegate>)delegate withVoip:(BOOL)withWoip {
  39. CGFloat width = [UIScreen mainScreen].bounds.size.width-16;
  40. self = [super initWithFrame:CGRectMake(0, 0, width, PLUGIN_AREA_HEIGHT)];
  41. if (self) {
  42. self.delegate = delegate;
  43. self.hasVoip = withWoip;
  44. self.backgroundColor = [UIColor colorWithRed:236.0/255.0 green:236.0/255.0 blue:236.0/255.0 alpha:1];
  45. int FACE_COUNT_ALL = (int)self.pluginItems.count;
  46. CGRect frame;
  47. frame.size.width = RCPlaginBoardCellSize.width;
  48. frame.size.height = RCPlaginBoardCellSize.height;
  49. __weak typeof(self)ws = self;
  50. for (int i = 0; i < FACE_COUNT_ALL; i++) {
  51. NSInteger currentRow = (NSInteger)floor((double)i / (double)HorizontalItemsCount);
  52. NSInteger currentColumn = i % HorizontalItemsCount;
  53. frame.origin.x = RCPlaginBoardCellSize.width * currentColumn + LeftOffset * (currentColumn+1);
  54. frame.origin.y = RCPlaginBoardCellSize.height * currentRow + 15 + currentRow * 18;
  55. PluginItem *pluginItem = self.pluginItems[i];
  56. WFCUPluginItemView *item = [[WFCUPluginItemView alloc] initWithTitle:pluginItem.title image:pluginItem.image frame:frame];
  57. item.tag = pluginItem.tag;
  58. NSUInteger tag = item.tag;
  59. item.onItemClicked = ^(void) {
  60. NSLog(@"on item %lu pressed", tag);
  61. [ws.delegate onItemClicked:tag];
  62. };
  63. [self addSubview:item];
  64. }
  65. }
  66. return self;
  67. }
  68. - (NSMutableArray *)pluginItems {
  69. if (!_pluginItems) {
  70. if (self.hasVoip) {
  71. _pluginItems = [@[
  72. [[PluginItem alloc] initWithTitle:@"相册" image:[UIImage imageNamed:@"chat_input_plugin_album"] tag:1],
  73. [[PluginItem alloc] initWithTitle:@"拍摄" image:[UIImage imageNamed:@"chat_input_plugin_camera"] tag:2],
  74. [[PluginItem alloc] initWithTitle:@"位置" image:[UIImage imageNamed:@"chat_input_plugin_location"] tag:3],
  75. [[PluginItem alloc] initWithTitle:@"视频通话" image:[UIImage imageNamed:@"chat_input_plugin_video_call"] tag:4],
  76. [[PluginItem alloc] initWithTitle:@"文件" image:[UIImage imageNamed:@"chat_input_plugin_file"] tag:5]
  77. ] mutableCopy];
  78. } else {
  79. _pluginItems = [@[
  80. [[PluginItem alloc] initWithTitle:@"相册" image:[UIImage imageNamed:@"chat_input_plugin_album"] tag:1],
  81. [[PluginItem alloc] initWithTitle:@"拍摄" image:[UIImage imageNamed:@"chat_input_plugin_camera"] tag:2],
  82. [[PluginItem alloc] initWithTitle:@"位置" image:[UIImage imageNamed:@"chat_input_plugin_location"] tag:3],
  83. [[PluginItem alloc] initWithTitle:@"文件" image:[UIImage imageNamed:@"chat_input_plugin_file"] tag:5]
  84. ] mutableCopy];
  85. }
  86. }
  87. return _pluginItems;
  88. }
  89. @end