| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605 |
- //
- // TUIConversationTableView.m
- // TUIConversation
- //
- // Created by xiangzhang on 2023/3/17.
- // Copyright © 2023 Tencent. All rights reserved.
- //
- #import "TUIConversationTableView.h"
- #import <TIMCommon/TUISecondConfirm.h>
- #import <TUICore/TUICore.h>
- #import "TUIConversationCell.h"
- #import "TUIFoldListViewController.h"
- #import "TUIConversationConfig.h"
- #import "MOConversationEmptyCell.h"
- @interface TUIConversationTableView () <UITableViewDelegate, UITableViewDataSource, TUIConversationListDataProviderDelegate>
- @property(nonatomic, strong) UIImageView *tipsView;
- @property(nonatomic, strong) UILabel *tipsLabel;
- @property (nonatomic, assign) BOOL hideMarkReadAction;
- @property (nonatomic, assign) BOOL hideDeleteAction;
- @property (nonatomic, assign) BOOL hideHideAction;
- @property (nonatomic, strong) NSArray *customizedItems;
- @end
- @implementation TUIConversationTableView {
- TUIConversationListBaseDataProvider *_dataProvider;
- }
- - (instancetype)init {
- self = [super init];
- if (self) {
- [self setTableView];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self setTableView];
- }
- return self;
- }
- - (void)setFrame:(CGRect)frame {
- [super setFrame:frame];
- [self setTipsViewFrame];
- }
- - (void)setTableView {
- self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- self.backgroundColor = TUIConversationDynamicColor(@"conversation_bg_color", @"#FFFFFF");
- self.tableFooterView = [[UIView alloc] init];
- self.contentInset = UIEdgeInsetsMake(0, 0, 120, 0);
- [self registerClass:[TUIConversationCell class] forCellReuseIdentifier:gConversationCell_ReuseId];
- [self registerClass:[MOConversationEmptyCell class] forCellReuseIdentifier:@"MOConversationEmptyCell"];
- self.estimatedRowHeight = TConversationCell_Height;
- self.rowHeight = TConversationCell_Height;
- self.delaysContentTouches = NO;
- // [self setSeparatorColor:TIMCommonDynamicColor(@"separator_color", @"#E1E2E8")];
- self.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.delegate = self;
- self.dataSource = self;
- [self addSubview:self.tipsView];
- [self addSubview:self.tipsLabel];
- self.disableMoreActionExtension = NO;
- [self setTipsViewFrame];
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onFriendInfoChanged:) name:@"FriendInfoChangedNotification" object:nil];
- }
- - (void)onFriendInfoChanged:(NSNotification *)notice {
- V2TIMFriendInfo *friendInfo = notice.object;
- if (friendInfo == nil) {
- return;
- }
- for (TUIConversationCellData *cellData in self.dataProvider.conversationList) {
- if ([cellData.userID isEqualToString:friendInfo.userID]) {
- NSString *title = friendInfo.friendRemark;
- if (title.length == 0) {
- title = friendInfo.userFullInfo.nickName;
- }
- if (title.length == 0) {
- title = friendInfo.userID;
- }
- cellData.title = title;
- [self reloadData];
- break;
- }
- }
- }
- - (UIImageView *)tipsView {
- if (!_tipsView) {
- _tipsView = [[UIImageView alloc] init];
- // _tipsView.image = TUIConversationDynamicImage(@"no_conversation_img", [UIImage imageNamed:TUIConversationImagePath(@"no_conversation")]);
- _tipsView.hidden = YES;
- }
- return _tipsView;
- }
- - (UILabel *)tipsLabel {
- if (!_tipsLabel) {
- _tipsLabel = [[UILabel alloc] init];
- _tipsLabel.textColor = TIMCommonDynamicColor(@"nodata_tips_color", @"#999999");
- _tipsLabel.font = [UIFont systemFontOfSize:14.0];
- _tipsLabel.textAlignment = NSTextAlignmentCenter;
- _tipsLabel.hidden = YES;
- }
- return _tipsLabel;
- }
- - (void)setTipsViewFrame {
- self.tipsView.mm_width(128).mm_height(109).mm__centerX(self.mm_centerX).mm_top(200.0);
- self.tipsLabel.mm_width(300).mm_height(20).mm__centerX(self.mm_centerX).mm_top(self.tipsView.mm_maxY + 18);
- }
- - (void)updateTipsViewStatus {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (0 == self.dataProvider.conversationList.count) {
- self.tipsView.hidden = NO;
- self.tipsLabel.hidden = NO;
- self.tipsLabel.text = self.tipsMsgWhenNoConversation;
- } else {
- self.tipsView.hidden = YES;
- self.tipsLabel.hidden = YES;
- }
- });
- }
- - (void)setDataProvider:(TUIConversationListBaseDataProvider *)dataProvider {
- _dataProvider = dataProvider;
- if (_dataProvider) {
- _dataProvider.delegate = self;
- [_dataProvider loadNexPageConversations];
- }
- }
- - (TUIConversationListBaseDataProvider *)dataProvider {
- return _dataProvider;
- ;
- }
- - (void)dealloc {
- [NSNotificationCenter.defaultCenter removeObserver:self];
- }
- #pragma mark TUIConversationListDataProviderDelegate
- - (void)insertConversationsAtIndexPaths:(NSArray *)indexPaths {
- if (!NSThread.isMainThread) {
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf insertConversationsAtIndexPaths:indexPaths];
- });
- return;
- }
- [UIView performWithoutAnimation:^{
- [self insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
- - (void)reloadConversationsAtIndexPaths:(NSArray *)indexPaths {
- if (!NSThread.isMainThread) {
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf reloadConversationsAtIndexPaths:indexPaths];
- });
- return;
- }
- if (self.isEditing) {
- self.editing = NO;
- }
- [UIView performWithoutAnimation:^{
- [self reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- }];
- }
- - (void)deleteConversationAtIndexPaths:(NSArray *)indexPaths {
- if (!NSThread.isMainThread) {
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf deleteConversationAtIndexPaths:indexPaths];
- });
- return;
- }
- [self deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- }
- - (void)reloadAllConversations {
- if (!NSThread.isMainThread) {
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf reloadAllConversations];
- });
- return;
- }
- [self reloadData];
- }
- - (void)updateMarkUnreadCount:(NSInteger)markUnreadCount markHideUnreadCount:(NSInteger)markHideUnreadCount {
- if (self.unreadCountChanged) {
- self.unreadCountChanged(markUnreadCount, markHideUnreadCount);
- }
- }
- - (void)parseActionHiddenTagAndCustomizedItems:(TUIConversationCellData *)cellData {
- id<TUIConversationConfigDataSource> dataSource = [TUIConversationConfig sharedConfig].moreMenuDataSource;
- NSArray *customizedItems = @[];
- if (dataSource && [dataSource respondsToSelector:@selector(conversationShouldHideItemsInMoreMenu:)]) {
- NSInteger flag = [dataSource conversationShouldHideItemsInMoreMenu:cellData];
- self.hideDeleteAction = flag & TUIConversationItemInMoreMenu_Delete;
- self.hideMarkReadAction = flag & TUIConversationItemInMoreMenu_MarkRead;
- self.hideHideAction = flag & TUIConversationItemInMoreMenu_Hide;
- }
- if (dataSource && [dataSource respondsToSelector:@selector(conversationShouldAddNewItemsToMoreMenu:)]) {
- NSArray *items = [dataSource conversationShouldAddNewItemsToMoreMenu:cellData];
- if ([items isKindOfClass:NSArray.class] && items.count > 0) {
- self.customizedItems = items;
- }
- }
- }
- #pragma mark - Table view data source
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- [self.dataProvider loadNexPageConversations];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- CGFloat offsetY = scrollView.contentOffset.y;
- if (self.convDelegate && [self.convDelegate respondsToSelector:@selector(tableViewDidScroll:)]) {
- [self.convDelegate tableViewDidScroll:offsetY];
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- [self updateTipsViewStatus];
- return self.dataProvider.conversationList.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
- if([cellData.conversationID isEqualToString:@"c2c_10000"] || [cellData.conversationID isEqualToString:@"c2c_10001"]) {
- return 0.1;
- }
- else{
- return TConversationCell_Height;
- }
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- return YES;
- }
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
- NSMutableArray *rowActions = [NSMutableArray array];
- [self parseActionHiddenTagAndCustomizedItems:cellData];
- @weakify(self);
- if (cellData.isLocalConversationFoldList) {
- UITableViewRowAction *markHideAction =
- [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
- title:TIMCommonLocalizableString(MarkHide)
- handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {
- @strongify(self);
- [self.dataProvider markConversationHide:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_HideFoldItem:YES];
- }
- }];
- markHideAction.backgroundColor = RGB(242, 147, 64);
- if (!self.hideHideAction) {
- [rowActions addObject:markHideAction];
- }
- return rowActions;
- }
- // Delete action
- UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive
- title:TIMCommonLocalizableString(Delete)
- handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {
- @strongify(self);
- TUISecondConfirmBtnInfo *cancelBtnInfo = [[TUISecondConfirmBtnInfo alloc] init];
- cancelBtnInfo.tile = TIMCommonLocalizableString(Cancel);
- cancelBtnInfo.click = ^{
- self.editing = NO;
- };
- TUISecondConfirmBtnInfo *confirmBtnInfo = [[TUISecondConfirmBtnInfo alloc] init];
- confirmBtnInfo.tile = TIMCommonLocalizableString(Delete);
- confirmBtnInfo.click = ^{
- [self.dataProvider removeConversation:cellData];
- self.editing = NO;
- };
- [TUISecondConfirm show:TIMCommonLocalizableString(TUIKitConversationTipsDelete)
- cancelBtnInfo:cancelBtnInfo
- confirmBtnInfo:confirmBtnInfo];
- }];
- deleteAction.backgroundColor = RGB(242, 77, 76);
- if (!self.hideDeleteAction) {
- [rowActions addObject:deleteAction];
- }
- // MarkAsRead action
- UITableViewRowAction *markAsReadAction =
- [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
- title:(cellData.isMarkAsUnread || cellData.unreadCount > 0) ? TIMCommonLocalizableString(MarkAsRead)
- : TIMCommonLocalizableString(MarkAsUnRead)
- handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {
- @strongify(self);
- if (cellData.isMarkAsUnread || cellData.unreadCount > 0) {
- [self.dataProvider markConversationAsRead:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_FoldItemIsUnread:NO];
- }
- } else {
- [self.dataProvider markConversationAsUnRead:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_FoldItemIsUnread:YES];
- }
- }
- }];
- markAsReadAction.backgroundColor = RGB(20, 122, 255);
- if (!self.hideMarkReadAction) {
- [rowActions addObject:markAsReadAction];
- }
- // More action
- NSArray *moreExtensionList =
- [TUICore getExtensionList:TUICore_TUIConversationExtension_ConversationCellMoreAction_ClassicExtensionID
- param:@{
- TUICore_TUIConversationExtension_ConversationCellAction_ConversationIDKey : cellData.conversationID,
- TUICore_TUIConversationExtension_ConversationCellAction_MarkListKey : cellData.conversationMarkList ?: @[],
- TUICore_TUIConversationExtension_ConversationCellAction_GroupListKey : cellData.conversationGroupList ?: @[]
- }];
- if (self.disableMoreActionExtension || 0 == moreExtensionList.count) {
- UITableViewRowAction *markAsHideAction =
- [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive
- title:TIMCommonLocalizableString(MarkHide)
- handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {
- @strongify(self);
- [self.dataProvider markConversationHide:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_HideFoldItem:YES];
- }
- }];
- markAsHideAction.backgroundColor = RGB(242, 147, 64);
- if (!self.hideHideAction) {
- [rowActions addObject:markAsHideAction];
- }
- } else {
- UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive
- title:TIMCommonLocalizableString(More)
- handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {
- @strongify(self);
- self.editing = NO;
- [self showMoreAction:cellData extensionList:moreExtensionList];
- }];
- moreAction.backgroundColor = RGB(242, 147, 64);
- [rowActions addObject:moreAction];
- }
- return rowActions;
- }
- // available ios 11 +
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView
- trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) {
- TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
- [self parseActionHiddenTagAndCustomizedItems:cellData];
-
- // config Actions
- @weakify(self);
- if (cellData.isLocalConversationFoldList && !self.hideHideAction) {
- UIContextualAction *markHideAction = [UIContextualAction
- contextualActionWithStyle:UIContextualActionStyleNormal
- title:TIMCommonLocalizableString(MarkHide)
- handler:^(UIContextualAction *_Nonnull action, __kindof UIView *_Nonnull sourceView, void (^_Nonnull completionHandler)(BOOL)) {
- @strongify(self);
- [self.dataProvider markConversationHide:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_HideFoldItem:YES];
- }
- }];
- markHideAction.backgroundColor = RGB(242, 147, 64);
- UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:@[ markHideAction ]];
- configuration.performsFirstActionWithFullSwipe = NO;
- return configuration;
- }
- NSMutableArray *arrayM = [NSMutableArray array];
- // Delete action
- UIContextualAction *deleteAction = [UIContextualAction
- contextualActionWithStyle:UIContextualActionStyleNormal
- title:TIMCommonLocalizableString(Delete)
- handler:^(UIContextualAction *_Nonnull action, __kindof UIView *_Nonnull sourceView, void (^_Nonnull completionHandler)(BOOL)) {
- @strongify(self);
- TUISecondConfirmBtnInfo *cancelBtnInfo = [[TUISecondConfirmBtnInfo alloc] init];
- cancelBtnInfo.tile = TIMCommonLocalizableString(Cancel);
- cancelBtnInfo.click = ^{
- self.editing = NO;
- };
- TUISecondConfirmBtnInfo *confirmBtnInfo = [[TUISecondConfirmBtnInfo alloc] init];
- confirmBtnInfo.tile = TIMCommonLocalizableString(Delete);
- confirmBtnInfo.click = ^{
- [self.dataProvider removeConversation:cellData];
- self.editing = NO;
- };
- [TUISecondConfirm show:TIMCommonLocalizableString(TUIKitConversationTipsDelete)
- cancelBtnInfo:cancelBtnInfo
- confirmBtnInfo:confirmBtnInfo];
- }];
- deleteAction.backgroundColor = RGB(242, 77, 76);
- if (!self.hideDeleteAction) {
- [arrayM addObject:deleteAction];
- }
-
- // MarkAsRead action
- UIContextualAction *markAsReadAction = [UIContextualAction
- contextualActionWithStyle:UIContextualActionStyleNormal
- title:(cellData.isMarkAsUnread || cellData.unreadCount > 0) ? TIMCommonLocalizableString(MarkAsRead)
- : TIMCommonLocalizableString(MarkAsUnRead)
- handler:^(UIContextualAction *_Nonnull action, __kindof UIView *_Nonnull sourceView, void (^_Nonnull completionHandler)(BOOL)) {
- @strongify(self);
- if (cellData.isMarkAsUnread || cellData.unreadCount > 0) {
- [self.dataProvider markConversationAsRead:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_FoldItemIsUnread:NO];
- }
- } else {
- [self.dataProvider markConversationAsUnRead:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_FoldItemIsUnread:YES];
- }
- }
- }];
- markAsReadAction.backgroundColor = RGB(20, 122, 255);
- if (!self.hideMarkReadAction) {
- [arrayM addObject:markAsReadAction];
- }
- // More action
- NSArray *moreExtensionList =
- [TUICore getExtensionList:TUICore_TUIConversationExtension_ConversationCellMoreAction_ClassicExtensionID
- param:@{
- TUICore_TUIConversationExtension_ConversationCellAction_ConversationIDKey : cellData.conversationID,
- TUICore_TUIConversationExtension_ConversationCellAction_MarkListKey : cellData.conversationMarkList ?: @[],
- TUICore_TUIConversationExtension_ConversationCellAction_GroupListKey : cellData.conversationGroupList ?: @[],
- }];
- if (self.disableMoreActionExtension || 0 == moreExtensionList.count) {
- UIContextualAction *markAsHideAction = [UIContextualAction
- contextualActionWithStyle:UIContextualActionStyleNormal
- title:TIMCommonLocalizableString(MarkHide)
- handler:^(UIContextualAction *_Nonnull action, __kindof UIView *_Nonnull sourceView, void (^_Nonnull completionHandler)(BOOL)) {
- @strongify(self);
- [self.dataProvider markConversationHide:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_HideFoldItem:YES];
- }
- }];
- markAsHideAction.backgroundColor = RGB(242, 147, 64);
- if (!self.hideHideAction) {
- [arrayM addObject:markAsHideAction];
- }
- } else {
- UIContextualAction *moreAction = [UIContextualAction
- contextualActionWithStyle:UIContextualActionStyleNormal
- title:TIMCommonLocalizableString(More)
- handler:^(UIContextualAction *_Nonnull action, __kindof UIView *_Nonnull sourceView, void (^_Nonnull completionHandler)(BOOL)) {
- @strongify(self);
- self.editing = NO;
- [self showMoreAction:cellData extensionList:moreExtensionList];
- }];
- moreAction.backgroundColor = RGB(242, 147, 64);
- [arrayM addObject:moreAction];
- }
- UISwipeActionsConfiguration *configuration = [UISwipeActionsConfiguration configurationWithActions:[NSArray arrayWithArray:arrayM]];
- configuration.performsFirstActionWithFullSwipe = NO;
- return configuration;
- }
- // MARK: action
- - (void)showMoreAction:(TUIConversationCellData *)cellData extensionList:(NSArray *)extensionList {
- UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- __weak typeof(self) weakSelf = self;
- if (self.customizedItems.count > 0) {
- for (UIAlertAction *action in self.customizedItems) {
- [ac tuitheme_addAction:action];
- }
- }
- if (!self.hideHideAction) {
- [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(MarkHide)
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *_Nonnull action) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
- [strongSelf.dataProvider markConversationHide:cellData];
- if (cellData.isLocalConversationFoldList) {
- [TUIConversationListDataProvider cacheConversationFoldListSettings_HideFoldItem:YES];
- }
- }]];
- }
- [self addCustomAction:ac cellData:cellData];
- [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Cancel) style:UIAlertActionStyleCancel handler:nil]];
- if (self.convDelegate && [self.convDelegate respondsToSelector:@selector(tableViewDidShowAlert:)]) {
- [self.convDelegate tableViewDidShowAlert:ac];
- }
- }
- - (void)addCustomAction:(UIAlertController *)ac cellData:(TUIConversationCellData *)cellData {
- NSArray *extensionList =
- [TUICore getExtensionList:TUICore_TUIConversationExtension_ConversationCellMoreAction_ClassicExtensionID
- param:@{
- TUICore_TUIConversationExtension_ConversationCellAction_ConversationIDKey : cellData.conversationID,
- TUICore_TUIConversationExtension_ConversationCellAction_MarkListKey : cellData.conversationMarkList ?: @[],
- TUICore_TUIConversationExtension_ConversationCellAction_GroupListKey : cellData.conversationGroupList ?: @[]
- }];
- for (TUIExtensionInfo *info in extensionList) {
- UIAlertAction *action = [UIAlertAction actionWithTitle:info.text
- style:UIAlertActionStyleDefault
- handler:^(UIAlertAction *_Nonnull action) {
- info.onClicked(@{});
- }];
- [ac tuitheme_addAction:action];
- }
- }
- - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
- return NO;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- TUIConversationCellData *cellData = self.dataProvider.conversationList[indexPath.row];
- if([cellData.conversationID isEqualToString:@"c2c_10000"] || [cellData.conversationID isEqualToString:@"c2c_10001"]) {
- MOConversationEmptyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MOConversationEmptyCell" forIndexPath:indexPath];
- return cell;
- }
-
- TUIConversationCell *cell = [tableView dequeueReusableCellWithIdentifier:gConversationCell_ReuseId forIndexPath:indexPath];
- if (cell && indexPath.row < self.dataProvider.conversationList.count) {
- TUIConversationCellData *data = [self.dataProvider.conversationList objectAtIndex:indexPath.row];
- [self tableViewFillCell:cell withData:data];
- NSArray *extensionList =
- [TUICore getExtensionList:TUICore_TUIConversationExtension_ConversationCellUpperRightCorner_ClassicExtensionID
- param:@{
- TUICore_TUIConversationExtension_ConversationCellUpperRightCorner_GroupListKey : data.conversationGroupList ?: @[],
- TUICore_TUIConversationExtension_ConversationCellUpperRightCorner_MarkListKey : data.conversationMarkList ?: @[],
- }];
- if (extensionList.count > 0) {
- TUIExtensionInfo *info = extensionList.firstObject;
- if (info.text.length > 0) {
- cell.timeLabel.text = info.text;
- } else if (info.icon) {
- NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
- textAttachment.image = info.icon;
- NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:textAttachment];
- cell.timeLabel.attributedText = imageStr;
- }
- }
- }
- return cell;
- }
- - (void)tableViewFillCell:(TUIConversationCell *)cell withData:(TUIConversationCellData *)data {
- [cell fillWithData:data];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- TUIConversationCellData *data = [self.dataProvider.conversationList objectAtIndex:indexPath.row];
- [self tableViewDidSelectCell:data];
- }
- - (void)tableViewDidSelectCell:(TUIConversationCellData *)data {
- if (self.convDelegate && [self.convDelegate respondsToSelector:@selector(tableViewDidSelectCell:)]) {
- [self.convDelegate tableViewDidSelectCell:data];
- }
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- // Turn on or off the length of the last line of dividers by controlling this switch
- BOOL needLastLineFromZeroToMax = NO;
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsMake(0, 82, 0, 0)];
- if (needLastLineFromZeroToMax && indexPath.row == (self.dataProvider.conversationList.count - 1)) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- }
- // Prevent the cell from inheriting the Table View's margin settings
- if (needLastLineFromZeroToMax && [cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
- // Explictly set your cell's layout margins
- if (needLastLineFromZeroToMax && [cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- @end
|