123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // KSShareGroupViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/29.
- //
- #import "KSShareGroupViewController.h"
- #import "GroupListModel.h"
- #import "GroupListViewCell.h"
- #import <RongIMKit/RongIMKit.h>
- @interface KSShareGroupViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, copy) ShareGroupCallback callback;
- @end
- @implementation KSShareGroupViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"分享到群聊"];
- [self configUI];
- [self queryGroupList];
- }
- - (void)backAction {
- if (self.callback) {
- self.callback(NO, @"已取消");
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
- }
- - (void)searchRequest:(NSString *)searchKey {
- [self queryGroupList];
- }
- - (void)queryGroupList {
- [self showhud];
- [KSNetworkingManager imGroupQueryPage:KS_POST search:nil success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *array = [dic arrayValueForKey:@"data"];
- for (NSDictionary *parm in array) {
- GroupListModel *model = [[GroupListModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- [self changePromptLabelState];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- if (self.networkAvaiable == NO) {
- [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
- }
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- [self changePromptLabelState];
- }];
- }
- - (void)shareGroupCallback:(ShareGroupCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- #pragma mark ----- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- GroupListModel *model = self.dataArray[indexPath.row];
- GroupListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupListViewCell"];
- [cell configWithSource:model];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- GroupListModel *model = self.dataArray[indexPath.row];
- if (![NSString isEmptyString:model.groupId]) {
- [self shareImageToGroup:model.groupId];
- }
- }
- - (void)shareImageToGroup:(NSString *)groupId {
-
- RCImageMessage *imgMsg = [RCImageMessage messageWithImage:self.shareImage];
- imgMsg.full = YES;
- [[RCIMClient sharedRCIMClient] sendMediaMessage:ConversationType_GROUP targetId:groupId content:imgMsg pushContent:nil pushData:nil progress:^(int progress, long messageId) {
-
- } success:^(long messageId) {
- dispatch_main_async_safe(^{
- if (self.callback) {
- self.callback(YES, @"发送成功");
- [self MBPShow:@"发送成功"];
- }
- [self shareCallback];
- });
-
- } error:^(RCErrorCode errorCode, long messageId) {
- dispatch_main_async_safe(^{
- if (self.callback) {
- self.callback(NO, @"发送失败");
- [self MBPShow:@"发送失败"];
- }
- [self shareCallback];
- });
-
- } cancel:^(long messageId) {
- dispatch_main_async_safe(^{
- if (self.callback) {
- self.callback(NO, @"已取消");
- }
- [self shareCallback];
- });
- }];
- }
- - (void)shareCallback {
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.backgroundColor = HexRGB(0xf3f4f8);
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.rowHeight = 70;
-
- UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
- headView.backgroundColor = HexRGB(0xf3f4f8);
- _tableView.tableHeaderView = headView;
-
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 10)];
- bottomView.backgroundColor = HexRGB(0xf3f4f8);
- _tableView.tableFooterView = bottomView;
-
- [_tableView registerNib:[UINib nibWithNibName:@"GroupListViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupListViewCell"];
- }
- return _tableView;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|