MessageNotiView.m
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// MessageNotiView.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageNotiView.h"
#import "MessageOfficialNotiCell.h"
#import "MessageComReplyCell.h"
#import "TextInputAlertView.h"
static int secHeaderHeight = 52;
static int secFooterHeight = 8;
@interface MessageNotiView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) MessageCenterViewModel *messageCenterVM;
@property (nonatomic, strong) TextInputAlertView *textInputAlertView;
@end
@implementation MessageNotiView
- (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate viewModel:(MessageCenterViewModel *)vm {
if (self = [super initWithFrame:CGRectZero style:UITableViewStyleGrouped]) {
self.messageDelegate = messageDelegate;
self.messageCenterVM = vm;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
self.delegate = self;
self.dataSource = self;
self.showsVerticalScrollIndicator = NO;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self registerClass:[MessageOfficialNotiCell class] forCellReuseIdentifier:NSStringFromClass([MessageOfficialNotiCell class])];
[self registerClass:[MessageComReplyCell class] forCellReuseIdentifier:NSStringFromClass([MessageComReplyCell class])];
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 24 + Bottom_SafeArea_Height)];
}
return self;
}
#pragma mark - public
- (void)dismissKeyBoard {
[self.textInputAlertView dismiss];
}
- (void)refreshReadStatusView:(NSIndexPath *)indexPath {
[self reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.messageCenterVM.messageListArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *sectionArr = self.messageCenterVM.messageListArr[section];
return sectionArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 77;
} else {
NSArray *userNotiList = self.messageCenterVM.messageListArr[indexPath.section];
MessageComReplyModel *model = userNotiList[indexPath.row];
return [model cellHeight];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return section == 0 ? CGFLOAT_MIN : secHeaderHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0)];
header.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
if (section == 0) {
header.height = 0;
} else {
header.height = secHeaderHeight;
NSArray *userNotiList = self.messageCenterVM.messageListArr[section];
UILabel *totalReplyCountLab = [UILabel labWithFont:BoldFont(15)];
totalReplyCountLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
totalReplyCountLab.origin = CGPointMake(15, 15);
totalReplyCountLab.text = userNotiList.count ? @"评论和回复" : @"暂无评论回复";
[totalReplyCountLab sizeToFit];
[header addSubview:totalReplyCountLab];
}
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return section == self.messageCenterVM.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, section == self.messageCenterVM.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight)];
footer.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
return footer;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
MessageOfficialNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageOfficialNotiCell class]) forIndexPath:indexPath];
NSArray *officialNotiList = self.messageCenterVM.messageListArr[indexPath.section];
cell.officialModel = officialNotiList[indexPath.row];
return cell;
} else {
WS(weakSelf);
MessageComReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageComReplyCell class]) forIndexPath:indexPath];
NSArray *userNotiList = self.messageCenterVM.messageListArr[indexPath.section];
MessageComReplyModel *model = userNotiList[indexPath.row];
cell.comReplyModel = model;
cell.tapReplyBtnBlock = ^{
[weakSelf.textInputAlertView showReplyTextAlertWithCommentUser:model.nickName model:model];
};
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.messageDelegate && [self.messageDelegate respondsToSelector:@selector(didSelectRowAtIndexPath:)]) {
[self.messageDelegate didSelectRowAtIndexPath:indexPath];
}
}
#pragma mark - lazy
- (TextInputAlertView *)textInputAlertView {
if (!_textInputAlertView) {
WS(weakSelf);
_textInputAlertView = [[TextInputAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_textInputAlertView.tapReplyBlock = ^(NSString * _Nonnull content, id _Nonnull model) {
if (weakSelf.messageDelegate && [weakSelf.messageDelegate respondsToSelector:@selector(replyContent:userMessageModel:)]) {
[weakSelf.messageDelegate replyContent:content userMessageModel:model];
}
};
}
return _textInputAlertView;
}
@end