Files
TIMSDK/iOS/TUIKit/TUIContact/UI/TUINewFriendViewController.m
T
2022-01-25 21:03:58 +08:00

140 lines
4.2 KiB
Objective-C

//
// TUINewFriendViewController.m
// TUIKit
//
// Created by annidyfeng on 2019/4/19.
// Copyright © 2019年 Tencent. All rights reserved.
//
#import "TUINewFriendViewController.h"
#import "TUINewFriendViewDataProvider.h"
#import "TUIDefine.h"
#import "TUIThemeManager.h"
@interface TUINewFriendViewController ()<UITableViewDelegate,UITableViewDataSource>
@property UITableView *tableView;
@property UIButton *moreBtn;
@property TUINewFriendViewDataProvider *viewModel;
@end
@implementation TUINewFriendViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = TUIKitLocalizableString(TUIKitContactsNewFriends); // @"新的联系人";
titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
titleLabel.textColor = TUICoreDynamicColor(@"nav_title_text_color", @"#000000");
[titleLabel sizeToFit];
self.navigationItem.titleView = titleLabel;
self.view.backgroundColor = TUICoreDynamicColor(@"controller_bg_color", @"#F2F3F5");
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
if (@available(iOS 15.0, *)) {
_tableView.sectionHeaderTopPadding = 0;
}
[self.view addSubview:_tableView];
_tableView.delegate = self;
_tableView.dataSource = self;
[_tableView registerClass:[TUICommonPendencyCell class] forCellReuseIdentifier:@"PendencyCell"];
self.tableView.allowsMultipleSelectionDuringEditing = NO;
_tableView.separatorInset = UIEdgeInsetsMake(0, 94, 0, 0);
_tableView.backgroundColor = self.view.backgroundColor;
_viewModel = TUINewFriendViewDataProvider.new;
_moreBtn = [UIButton buttonWithType:UIButtonTypeSystem];
_moreBtn.mm_h = 20;
_tableView.tableFooterView = _moreBtn;
_moreBtn.hidden = YES;
@weakify(self)
[RACObserve(_viewModel, dataList) subscribeNext:^(id _Nullable x) {
@strongify(self)
[self.tableView reloadData];
}];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self loadData];
}
- (void)loadData
{
[_viewModel loadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.viewModel.dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 86;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TUICommonPendencyCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"PendencyCell" forIndexPath:indexPath];
TUICommonPendencyCellData *data = self.viewModel.dataList[indexPath.row];
data.cselector = @selector(cellClick:);
data.cbuttonSelector = @selector(btnClick:);
data.cRejectButtonSelector = @selector(rejectBtnClick:);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell fillWithData:data];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
[self.tableView beginUpdates];
TUICommonPendencyCellData *data = self.viewModel.dataList[indexPath.row];
[self.viewModel removeData:data];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
}
- (void)btnClick:(TUICommonPendencyCell *)cell
{
[self.viewModel agreeData:cell.pendencyData];
[self.tableView reloadData];
}
- (void)rejectBtnClick:(TUICommonPendencyCell *)cell
{
[self.viewModel rejectData:cell.pendencyData];
[self.tableView reloadData];
}
- (void)cellClick:(TUICommonPendencyCell *)cell
{
if (self.cellClickBlock) {
self.cellClickBlock(cell);
}
}
@end