KSShareGroupViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
  38. }
  39. - (void)searchRequest:(NSString *)searchKey {
  40. [self queryGroupList];
  41. }
  42. - (void)queryGroupList {
  43. [self showhud];
  44. [KSNetworkingManager imGroupQueryPage:KS_POST search:nil success:^(NSDictionary * _Nonnull dic) {
  45. [self removehub];
  46. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  47. NSArray *array = [dic arrayValueForKey:@"data"];
  48. for (NSDictionary *parm in array) {
  49. GroupListModel *model = [[GroupListModel alloc] initWithDictionary:parm];
  50. [self.dataArray addObject:model];
  51. }
  52. }
  53. else {
  54. [self MBPShow:MESSAGEKEY];
  55. }
  56. [self.tableView reloadData];
  57. [self changePromptLabelState];
  58. } faliure:^(NSError * _Nonnull error) {
  59. [self removehub];
  60. if (self.networkAvaiable == NO) {
  61. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  62. }
  63. [self.dataArray removeAllObjects];
  64. [self.tableView reloadData];
  65. [self changePromptLabelState];
  66. }];
  67. }
  68. - (void)shareGroupCallback:(ShareGroupCallback)callback {
  69. if (callback) {
  70. self.callback = callback;
  71. }
  72. }
  73. #pragma mark ----- table data source
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  75. return self.dataArray.count;
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. GroupListModel *model = self.dataArray[indexPath.row];
  79. GroupListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupListViewCell"];
  80. [cell configWithSource:model];
  81. return cell;
  82. }
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  84. GroupListModel *model = self.dataArray[indexPath.row];
  85. if (![NSString isEmptyString:model.groupId]) {
  86. [self shareImageToGroup:model.groupId];
  87. }
  88. }
  89. - (void)shareImageToGroup:(NSString *)groupId {
  90. RCImageMessage *imgMsg = [RCImageMessage messageWithImage:self.shareImage];
  91. imgMsg.full = YES;
  92. [[RCIMClient sharedRCIMClient] sendMediaMessage:ConversationType_GROUP targetId:groupId content:imgMsg pushContent:nil pushData:nil progress:^(int progress, long messageId) {
  93. } success:^(long messageId) {
  94. dispatch_main_async_safe(^{
  95. if (self.callback) {
  96. self.callback(YES, @"发送成功");
  97. [self MBPShow:@"发送成功"];
  98. }
  99. [self shareCallback];
  100. });
  101. } error:^(RCErrorCode errorCode, long messageId) {
  102. dispatch_main_async_safe(^{
  103. if (self.callback) {
  104. self.callback(NO, @"发送失败");
  105. [self MBPShow:@"发送失败"];
  106. }
  107. [self shareCallback];
  108. });
  109. } cancel:^(long messageId) {
  110. dispatch_main_async_safe(^{
  111. if (self.callback) {
  112. self.callback(NO, @"已取消");
  113. }
  114. [self shareCallback];
  115. });
  116. }];
  117. }
  118. - (void)shareCallback {
  119. [self.navigationController popViewControllerAnimated:YES];
  120. }
  121. - (UITableView *)tableView {
  122. if (!_tableView) {
  123. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  124. _tableView.backgroundColor = HexRGB(0xf3f4f8);
  125. _tableView.showsVerticalScrollIndicator = NO;
  126. _tableView.dataSource = self;
  127. _tableView.delegate = self;
  128. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  129. _tableView.rowHeight = UITableViewAutomaticDimension;
  130. _tableView.rowHeight = 70;
  131. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
  132. headView.backgroundColor = HexRGB(0xf3f4f8);
  133. _tableView.tableHeaderView = headView;
  134. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
  135. bottomView.backgroundColor = HexRGB(0xf3f4f8);
  136. _tableView.tableFooterView = bottomView;
  137. [_tableView registerNib:[UINib nibWithNibName:@"GroupListViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupListViewCell"];
  138. }
  139. return _tableView;
  140. }
  141. /*
  142. #pragma mark - Navigation
  143. // In a storyboard-based application, you will often want to do a little preparation before navigation
  144. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  145. // Get the new view controller using [segue destinationViewController].
  146. // Pass the selected object to the new view controller.
  147. }
  148. */
  149. @end