WFCUPluginBoardView.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #import "WFCUConfigManager.h"
  11. #import "WFCUImage.h"
  12. #define PLUGIN_AREA_HEIGHT 211
  13. #define LeftOffset ([UIScreen mainScreen].bounds.size.width-75*4)/5.0
  14. #define RCPlaginBoardCellSize ((CGSize){ 75, 80 })
  15. #define HorizontalItemsCount 4
  16. #define VerticalItemsCount 2
  17. @interface PluginItem : NSObject
  18. @property(nonatomic, strong)UIImage *image;
  19. @property(nonatomic, strong)NSString *title;
  20. @property(nonatomic, assign)NSUInteger tag;
  21. - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSUInteger)tag;
  22. @end
  23. @implementation PluginItem
  24. - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSUInteger)tag {
  25. self = [super init];
  26. if (self) {
  27. self.title = title;
  28. self.image = image;
  29. self.tag = tag;
  30. }
  31. return self;
  32. }
  33. @end
  34. @interface WFCUPluginBoardView()
  35. @property (nonatomic, strong)NSMutableArray *pluginItems;
  36. @property (nonatomic, weak)id<WFCUPluginBoardViewDelegate> delegate;
  37. @property (nonatomic, assign)BOOL hasVoip;
  38. @property (nonatomic, assign)BOOL hasPtt;
  39. @end
  40. @implementation WFCUPluginBoardView
  41. - (instancetype)initWithDelegate:(id<WFCUPluginBoardViewDelegate>)delegate withVoip:(BOOL)withWoip withPtt:(BOOL)withPtt {
  42. CGFloat width = [UIScreen mainScreen].bounds.size.width-16;
  43. self = [super initWithFrame:CGRectMake(0, 0, width, PLUGIN_AREA_HEIGHT)];
  44. if (self) {
  45. self.delegate = delegate;
  46. self.hasVoip = withWoip;
  47. self.hasPtt = withPtt;
  48. self.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  49. int FACE_COUNT_ALL = (int)self.pluginItems.count;
  50. CGRect frame;
  51. frame.size.width = RCPlaginBoardCellSize.width;
  52. frame.size.height = RCPlaginBoardCellSize.height;
  53. __weak typeof(self)ws = self;
  54. for (int i = 0; i < FACE_COUNT_ALL; i++) {
  55. NSInteger currentRow = (NSInteger)floor((double)i / (double)HorizontalItemsCount);
  56. NSInteger currentColumn = i % HorizontalItemsCount;
  57. frame.origin.x = RCPlaginBoardCellSize.width * currentColumn + LeftOffset * (currentColumn+1);
  58. frame.origin.y = RCPlaginBoardCellSize.height * currentRow + 15 + currentRow * 18;
  59. PluginItem *pluginItem = self.pluginItems[i];
  60. WFCUPluginItemView *item = [[WFCUPluginItemView alloc] initWithTitle:pluginItem.title image:pluginItem.image frame:frame];
  61. item.tag = pluginItem.tag;
  62. NSUInteger tag = item.tag;
  63. item.onItemClicked = ^(void) {
  64. NSLog(@"on item %lu pressed", tag);
  65. [ws.delegate onItemClicked:tag];
  66. };
  67. [self addSubview:item];
  68. }
  69. }
  70. return self;
  71. }
  72. - (NSMutableArray *)pluginItems {
  73. if (!_pluginItems) {
  74. _pluginItems = [@[
  75. [[PluginItem alloc] initWithTitle:WFCString(@"Album") image:[WFCUImage imageNamed:@"chat_input_plugin_album"] tag:1],
  76. [[PluginItem alloc] initWithTitle:WFCString(@"TakePhoto") image:[WFCUImage imageNamed:@"chat_input_plugin_camera"] tag:2],
  77. [[PluginItem alloc] initWithTitle:WFCString(@"Location") image:[WFCUImage imageNamed:@"chat_input_plugin_location"] tag:3],
  78. [[PluginItem alloc] initWithTitle:WFCString(@"Files") image:[WFCUImage imageNamed:@"chat_input_plugin_file"] tag:5],
  79. [[PluginItem alloc] initWithTitle:WFCString(@"Card") image:[WFCUImage imageNamed:@"chat_input_plugin_card"] tag:6]
  80. ] mutableCopy];
  81. #if WFCU_SUPPORT_VOIP
  82. if (self.hasVoip) {
  83. [_pluginItems insertObject:[[PluginItem alloc] initWithTitle:WFCString(@"VideoCall") image:[WFCUImage imageNamed:@"chat_input_plugin_video_call"] tag:4] atIndex:2];
  84. }
  85. #endif
  86. #ifdef WFC_PTT
  87. if(self.hasPtt) {
  88. [_pluginItems addObject:[[PluginItem alloc] initWithTitle:WFCString(@"Talk") image:[WFCUImage imageNamed:@"chat_input_plugin_intercom"] tag:7]];
  89. }
  90. #endif
  91. }
  92. return _pluginItems;
  93. }
  94. @end