|
@@ -1,186 +0,0 @@
|
|
|
-//
|
|
|
-// KSSelectConversationViewController.m
|
|
|
-// StudentDaya
|
|
|
-//
|
|
|
-// Created by Kyle on 2021/8/5.
|
|
|
-// Copyright © 2021 DayaMusic. All rights reserved.
|
|
|
-//
|
|
|
-
|
|
|
-#import "KSSelectConversationViewController.h"
|
|
|
-#import <RongIMKit/RCKitUtility.h>
|
|
|
-#import <RongIMKit/RCKitCommonDefine.h>
|
|
|
-#import <RongIMKit/RCKitConfig.h>
|
|
|
-#import <RongIMKit/RCIM.h>
|
|
|
-
|
|
|
-@interface RCSelectConversationCell : UITableViewCell
|
|
|
-
|
|
|
-- (void)setConversation:(RCConversation *)conversation ifSelected:(BOOL)ifSelected;
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-typedef void (^CompleteBlock)(NSArray *conversationList);
|
|
|
-
|
|
|
-@interface KSSelectConversationViewController ()<UITableViewDataSource, UITableViewDelegate>
|
|
|
-
|
|
|
-@property (nonatomic, strong) NSMutableArray *selectedConversationArray;
|
|
|
-
|
|
|
-@property (nonatomic, strong) UITableView *conversationTableView;
|
|
|
-
|
|
|
-@property (nonatomic, strong) UIBarButtonItem *rightBarButtonItem;
|
|
|
-
|
|
|
-@property (nonatomic, strong) NSArray *listingConversationArray;
|
|
|
-
|
|
|
-@property (nonatomic, strong) CompleteBlock completeBlock;
|
|
|
-
|
|
|
-@end
|
|
|
-
|
|
|
-@implementation KSSelectConversationViewController
|
|
|
-
|
|
|
-- (instancetype)initSelectConversationViewControllerCompleted:
|
|
|
- (void (^)(NSArray<RCConversation *> *conversationList))completedBlock {
|
|
|
- if (self = [super init]) {
|
|
|
- self.completeBlock = completedBlock;
|
|
|
- }
|
|
|
- return self;
|
|
|
-}
|
|
|
-- (void)viewDidLoad {
|
|
|
- [super viewDidLoad];
|
|
|
- [self setupNavi];
|
|
|
- self.view.backgroundColor = RCDYCOLOR(0xf0f0f6, 0x000000);
|
|
|
- [self.view addSubview:self.conversationTableView];
|
|
|
- self.selectedConversationArray = [[NSMutableArray alloc] init];
|
|
|
- NSMutableArray *listArray = [NSMutableArray array];
|
|
|
- NSArray *conversationArray = [[RCIMClient sharedRCIMClient] getConversationList:@[@(ConversationType_PRIVATE), @(ConversationType_GROUP)]];
|
|
|
-
|
|
|
- for (RCConversation *conversation in conversationArray) {
|
|
|
- if (conversation.conversationType == ConversationType_GROUP && ![conversation.targetId containsString:@"FAN"] && ![conversation.targetId containsString:@"COURSE"]) { // 视频聊天群不添加
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- [listArray addObject:conversation];
|
|
|
- }
|
|
|
- }
|
|
|
- self.listingConversationArray = [NSArray arrayWithArray:listArray];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - UITableViewDataSource
|
|
|
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
- if (!self.listingConversationArray) {
|
|
|
- return 0;
|
|
|
- } else {
|
|
|
- return self.listingConversationArray.count;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- if (self.listingConversationArray.count <= indexPath.row) {
|
|
|
- return nil;
|
|
|
- }
|
|
|
-
|
|
|
- static NSString *reusableID = @"RCSelectConversationCell";
|
|
|
- RCSelectConversationCell *cell = [tableView dequeueReusableCellWithIdentifier:reusableID];
|
|
|
- if (!cell) {
|
|
|
- cell = [[RCSelectConversationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusableID];
|
|
|
- }
|
|
|
-
|
|
|
- RCConversation *conversation = self.listingConversationArray[indexPath.row];
|
|
|
- BOOL ifSelected = [self.selectedConversationArray containsObject:conversation];
|
|
|
- [cell setConversation:conversation ifSelected:ifSelected];
|
|
|
-
|
|
|
- return cell;
|
|
|
-}
|
|
|
-
|
|
|
-- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- return 70;
|
|
|
-}
|
|
|
-
|
|
|
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- if (indexPath.row >= self.listingConversationArray.count) {
|
|
|
- return;
|
|
|
- }
|
|
|
- NSString *userId = self.listingConversationArray[indexPath.row];
|
|
|
- if ([self.selectedConversationArray containsObject:userId]) {
|
|
|
- [self.selectedConversationArray removeObject:userId];
|
|
|
- } else if (userId) {
|
|
|
- [self.selectedConversationArray addObject:userId];
|
|
|
- }
|
|
|
- [self updateRightButton];
|
|
|
- [UIView performWithoutAnimation:^{
|
|
|
- [self.conversationTableView reloadRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationNone];
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-#pragma mark - Target Action
|
|
|
-
|
|
|
-- (void)onLeftButtonClick:(id)sender {
|
|
|
- [self.navigationController popViewControllerAnimated:NO];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)onRightButtonClick:(id)sender {
|
|
|
- if (!self.selectedConversationArray) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (self.completeBlock) {
|
|
|
- self.completeBlock(self.selectedConversationArray);
|
|
|
- }
|
|
|
- [self.navigationController popViewControllerAnimated:NO];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - Private Methods
|
|
|
-- (void)setupNavi {
|
|
|
- self.title = RCLocalizedString(@"SelectContact");
|
|
|
- UIBarButtonItem *leftBarItem =
|
|
|
- [[UIBarButtonItem alloc] initWithTitle:RCLocalizedString(@"Cancel")
|
|
|
- style:UIBarButtonItemStylePlain
|
|
|
- target:self
|
|
|
- action:@selector(onLeftButtonClick:)];
|
|
|
- leftBarItem.tintColor = RCKitConfigCenter.ui.globalNavigationBarTintColor;
|
|
|
- self.navigationItem.leftBarButtonItem = leftBarItem;
|
|
|
-
|
|
|
- self.rightBarButtonItem =
|
|
|
- [[UIBarButtonItem alloc] initWithTitle:RCLocalizedString(@"OK")
|
|
|
- style:UIBarButtonItemStylePlain
|
|
|
- target:self
|
|
|
- action:@selector(onRightButtonClick:)];
|
|
|
- self.rightBarButtonItem.tintColor = RCKitConfigCenter.ui.globalNavigationBarTintColor;
|
|
|
- self.navigationItem.rightBarButtonItem = self.rightBarButtonItem;
|
|
|
-
|
|
|
- [self updateRightButton];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)updateRightButton {
|
|
|
- [self.rightBarButtonItem setEnabled:self.selectedConversationArray.count > 0];
|
|
|
-}
|
|
|
-
|
|
|
-#pragma mark - Getters and Setters
|
|
|
-
|
|
|
-- (UITableView *)conversationTableView {
|
|
|
- if (!_conversationTableView) {
|
|
|
- _conversationTableView = [[UITableView alloc] init];
|
|
|
- CGFloat navBarHeight = 64;
|
|
|
- CGFloat homeBarHeight = [RCKitUtility getWindowSafeAreaInsets].bottom;
|
|
|
- if (homeBarHeight > 0) {
|
|
|
- navBarHeight = 88;
|
|
|
- }
|
|
|
- _conversationTableView.frame =
|
|
|
- CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - navBarHeight - homeBarHeight);
|
|
|
- _conversationTableView.dataSource = self;
|
|
|
- _conversationTableView.delegate = self;
|
|
|
- _conversationTableView.backgroundColor = [UIColor clearColor];
|
|
|
- _conversationTableView.tableFooterView = [[UIView alloc] init];
|
|
|
- }
|
|
|
- return _conversationTableView;
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
-#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
|