MyDynamicView.m
6.4 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// MyDynamicView.m
// DreamSleep
//
// Created by peter on 2022/10/19.
//
#import "MyDynamicView.h"
@interface MyDynamicView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *listView;
@property (nonatomic, strong) PersonDynViewModel *myDynVM;
@property (nonatomic, strong) UIView *deleteView;
@property (nonatomic, strong) UIButton *allSelectBtn;
@end
@implementation MyDynamicView
#pragma mark - 初始化
- (instancetype)initWithDelegate:(id<MyDynamicViewDelegate>)delegate myDynViewModel:(PersonDynViewModel *)myDynViewModel {
if (self = [super init]) {
self.delegate = delegate;
self.myDynVM = myDynViewModel;
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self addSubview:self.listView];
// [self addSubview:self.deleteView];
}
return self;
}
- (void)layoutSubviews {
self.listView.frame = CGRectMake(15, 0, self.width - 30, self.height);
}
#pragma mark - public
- (void)updateCommunityMoments:(BOOL)loadMore {
[self endRefreshing:loadMore];
[self.listView reloadData];
}
- (void)endRefreshing:(BOOL)loadMore {
if (loadMore) {
[self.listView.mj_footer endRefreshing];
} else {
[self.listView.mj_header endRefreshing];
[self.listView.mj_footer resetNoMoreData];
}
}
- (void)endRefreshingWithNoMoreData {
[self.listView.mj_footer endRefreshingWithNoMoreData];
}
- (void)updateListView {
[self.listView reloadData];
}
#pragma mark - private
- (void)allSelectAction {
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.myDynVM.listArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
ComDynModel *model = self.myDynVM.listArr[indexPath.section];
return [model cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return section == 0 ? 15 : CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return section == self.myDynVM.listArr.count - 1 ? 6.5 : 12;;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WS(weakSelf);
ComDynamicCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ComDynamicCell class])];
if (!cell) {
cell = [[ComDynamicCell alloc] initWithCellType:DynModelTypeMyDyn style:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([ComDynamicCell class])];
}
ComDynModel *model = self.myDynVM.listArr[indexPath.section];
cell.model = model;
__weak ComDynamicCell * weakCell = (ComDynamicCell *)cell;
cell.tapLikeBlock = ^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didTapLikeItem:cell:)]) {
[weakSelf.delegate didTapLikeItem:model cell:weakCell];
}
};
cell.tapRemarkBlock = ^{
[weakSelf tableView:tableView didSelectRowAtIndexPath:indexPath];
};
cell.tapSelectBlock = ^(BOOL selected) {
[weakSelf.myDynVM updateMyDynamicModel:model selected:selected];
};
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ComDynModel *model = self.myDynVM.listArr[indexPath.section];
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectItemWithModel:)]) {
[self.delegate didSelectItemWithModel:model];
}
}
#pragma mark - lazy
- (UITableView *)listView {
if (!_listView) {
_listView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_listView.delegate = self;
_listView.dataSource = self;
_listView.backgroundColor = DSClearColor;
_listView.showsVerticalScrollIndicator = NO;
_listView.separatorStyle = UITableViewCellSeparatorStyleNone;
_listView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
WS(weakSelf);
_listView.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(getDynamicListRequest:)]) {
[weakSelf.delegate getDynamicListRequest:NO];
}
}];
[_listView.mj_header beginRefreshing];
_listView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(getDynamicListRequest:)]) {
[weakSelf.delegate getDynamicListRequest:YES];
}
}];
}
return _listView;
}
- (UIView *)deleteView {
if (!_deleteView) {
_deleteView = [UIView new];
_deleteView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
UIButton *allSelectBtn = [UIButton btnWithTitle:@"全选" font:SysFont(15)];
[allSelectBtn dk_setTitleColorPicker:DKColorPickerWithKey(Dk_TITLE) forState:UIControlStateNormal];
[allSelectBtn addTarget:self action:@selector(allSelectAction) forControlEvents:UIControlEventTouchUpInside];
[allSelectBtn dk_setImage:DKImagePickerWithNames(@"ic_person_xuanze", @"dk_ic_person_xuanze", @"ic_person_xuanze") forState:UIControlStateNormal];
[allSelectBtn dk_setImage:DKImagePickerWithNames(@"ic_person_xuanzhong", @"dk_ic_person_xuanzhong", @"ic_person_xuanzhong") forState:UIControlStateSelected];
allSelectBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 7);
[_deleteView addSubview:allSelectBtn];
self.allSelectBtn = allSelectBtn;
UIButton *deleteBtn = [UIButton btnWithTitle:@"删除" font:BoldFont(18)];
[deleteBtn dk_setTitleColorPicker:DKColorPickerWithKey(Sub_Navi_TITLE) forState:UIControlStateNormal];
deleteBtn.dk_backgroundColorPicker = DKColorPickerWithKey(BrandBG);
[_deleteView addSubview:deleteBtn];
[allSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
}];
}
return _deleteView;
}
@end