WFCUPluginBoardView.m 4.4 KB

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