KSShareGroupViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // KSShareGroupViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/6/29.
  6. //
  7. #import "KSShareGroupViewController.h"
  8. #import "GroupListModel.h"
  9. #import "GroupListViewCell.h"
  10. #import <RongIMKit/RongIMKit.h>
  11. @interface KSShareGroupViewController ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, copy) ShareGroupCallback callback;
  14. @end
  15. @implementation KSShareGroupViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view.
  19. [self allocTitle:@"分享到群聊"];
  20. [self configUI];
  21. [self queryGroupList];
  22. }
  23. - (void)backAction {
  24. if (self.callback) {
  25. self.callback(NO, @"已取消");
  26. }
  27. [self.navigationController popViewControllerAnimated:YES];
  28. }
  29. - (void)configUI {
  30. [self.scrollView removeFromSuperview];
  31. [self.view addSubview:self.tableView];
  32. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.right.mas_equalTo(self.view);
  34. make.top.mas_equalTo(self.view);
  35. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  36. }];
  37. }
  38. - (void)searchRequest:(NSString *)searchKey {
  39. [self queryGroupList];
  40. }
  41. - (void)queryGroupList {
  42. [self showhud];
  43. [KSNetworkingManager imGroupQueryPage:KS_POST search:nil success:^(NSDictionary * _Nonnull dic) {
  44. [self removehub];
  45. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  46. NSArray *array = [dic arrayValueForKey:@"data"];
  47. for (NSDictionary *parm in array) {
  48. GroupListModel *model = [[GroupListModel alloc] initWithDictionary:parm];
  49. [self.dataArray addObject:model];
  50. }
  51. }
  52. else {
  53. [self MBPShow:MESSAGEKEY];
  54. }
  55. [self.tableView reloadData];
  56. [self changePromptLabelState];
  57. } faliure:^(NSError * _Nonnull error) {
  58. [self removehub];
  59. if (self.networkAvaiable == NO) {
  60. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  61. }
  62. [self.dataArray removeAllObjects];
  63. [self.tableView reloadData];
  64. [self changePromptLabelState];
  65. }];
  66. }
  67. - (void)shareGroupCallback:(ShareGroupCallback)callback {
  68. if (callback) {
  69. self.callback = callback;
  70. }
  71. }
  72. #pragma mark ----- table data source
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. return self.dataArray.count;
  75. }
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  77. GroupListModel *model = self.dataArray[indexPath.row];
  78. GroupListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupListViewCell"];
  79. [cell configWithSource:model];
  80. return cell;
  81. }
  82. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  83. GroupListModel *model = self.dataArray[indexPath.row];
  84. if (![NSString isEmptyString:model.groupId]) {
  85. [self shareImageToGroup:model.groupId];
  86. }
  87. }
  88. - (void)shareImageToGroup:(NSString *)groupId {
  89. RCImageMessage *imgMsg = [RCImageMessage messageWithImage:self.shareImage];
  90. imgMsg.full = YES;
  91. [[RCIMClient sharedRCIMClient] sendMediaMessage:ConversationType_GROUP targetId:groupId content:imgMsg pushContent:nil pushData:nil progress:^(int progress, long messageId) {
  92. } success:^(long messageId) {
  93. dispatch_main_async_safe(^{
  94. if (self.callback) {
  95. self.callback(YES, @"发送成功");
  96. // [self MBPShow:@"发送成功"];
  97. }
  98. [self shareCallback];
  99. });
  100. } error:^(RCErrorCode errorCode, long messageId) {
  101. dispatch_main_async_safe(^{
  102. if (self.callback) {
  103. self.callback(NO, @"发送失败");
  104. // [self MBPShow:@"发送失败"];
  105. }
  106. [self shareCallback];
  107. });
  108. } cancel:^(long messageId) {
  109. dispatch_main_async_safe(^{
  110. if (self.callback) {
  111. self.callback(NO, @"已取消");
  112. }
  113. [self shareCallback];
  114. });
  115. }];
  116. }
  117. - (void)shareCallback {
  118. [self.navigationController popViewControllerAnimated:YES];
  119. }
  120. - (UITableView *)tableView {
  121. if (!_tableView) {
  122. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  123. _tableView.backgroundColor = HexRGB(0xf3f4f8);
  124. _tableView.showsVerticalScrollIndicator = NO;
  125. _tableView.dataSource = self;
  126. _tableView.delegate = self;
  127. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  128. _tableView.rowHeight = UITableViewAutomaticDimension;
  129. _tableView.rowHeight = 70;
  130. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
  131. headView.backgroundColor = HexRGB(0xf3f4f8);
  132. _tableView.tableHeaderView = headView;
  133. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
  134. bottomView.backgroundColor = HexRGB(0xf3f4f8);
  135. _tableView.tableFooterView = bottomView;
  136. [_tableView registerNib:[UINib nibWithNibName:@"GroupListViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupListViewCell"];
  137. }
  138. return _tableView;
  139. }
  140. /*
  141. #pragma mark - Navigation
  142. // In a storyboard-based application, you will often want to do a little preparation before navigation
  143. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  144. // Get the new view controller using [segue destinationViewController].
  145. // Pass the selected object to the new view controller.
  146. }
  147. */
  148. @end