CommunityController.m
7.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// CommunityController.m
// DreamSleep
//
// Created by peter on 2022/9/2.
//
#import "CommunityController.h"
#import "CommunityView.h"
#import "DynamicController.h"
#import "MessageController.h"
#import "ReportController.h"
#import "DynamicDetailController.h"
#import "PersonDynViewModel.h"
@interface CommunityController () <CommunityViewDelegate, DynamicControllerDelegate, DynamicDetailControllerDelegate>
@property (nonatomic, strong) CommunityView *communityView;
@property (nonatomic, assign) int offset;
@property (nonatomic, strong) NSURLSessionDataTask *likeDataTask;
/// 存储动态id
@property (nonatomic, assign) int talkID;
@property (nonatomic, strong) ComListViewModel *comListViewModel;
@property (nonatomic, strong) PersonDynViewModel *personDynViewModel;
@end
@implementation CommunityController
- (void)loadView {
self.comListViewModel = [ComListViewModel new];
self.view = self.communityView;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
}
#pragma mark - private
- (void)setupUI {
self.offset = 1;
self.edgesForExtendedLayout = UIRectEdgeNone;
UILabel *leftLab = [UILabel dkLabWithText:@"小梦社区" font:BoldFont(24.0)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftLab];
UIButton *messageBtn = [UIButton new];
[messageBtn addTarget:self action:@selector(messageAction) forControlEvents:UIControlEventTouchUpInside];
[messageBtn dk_setImage:DKImagePickerWithNames(@"ic_message_shequ", @"dk_ic_message_shequ", @"ic_message_shequ") forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:messageBtn];
}
- (void)messageAction {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
[self.navigationController pushViewController:[MessageController new] animated:YES];
}
- (void)testDynDeleteAPI {
#warning - 测试删除接口
self.personDynViewModel = [PersonDynViewModel new];
self.personDynViewModel.oper_type = @"comment";
self.personDynViewModel.delete_id = 18;
[self.personDynViewModel communityDeleteOperationWithCompletion:^(PersonDynViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[self.comListViewModel deleteComDynWithDynamicID:self.personDynViewModel.delete_id];
[self.communityView updateListView];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
}
}];
}
#pragma mark - CommunityViewDelegate
- (void)tapCommunityHeaderModule:(NSInteger)index {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
NSString *clsName = index == 1 ? @"ArticleController" : @"EvaluateController";
[self.navigationController pushViewController:[NSClassFromString(clsName) new] animated:YES];
}
- (void)getDynamicListRequest:(BOOL)loadMore {
if (loadMore == NO) { self.offset = 1; }
[self.comListViewModel querySleepDynamicListWithLoadMore:loadMore offset:self.offset completion:^(ComListViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
if (requestModel.latestDataList.count == 0) {
if (loadMore) {
[self.communityView endRefreshingWithNoMoreData];
} else {
[self.communityView endRefreshing:NO];
}
} else {
self.offset++;
[self.communityView updateCommunityMoments:loadMore];
}
} else {
[DSProgressHUD showToast:requestModel.errMessage];
[self.communityView endRefreshing:loadMore];
}
}];
}
- (void)publishLogicDeal {
// 1、判断用户有没有登录
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
// 2、登录了,判断是否绑定了手机号
if (![LoginUtils getUserMobile]) {
UIViewController *bindVC = [[UIStoryboard storyboardWithName:@"BindMobileController" bundle:nil] instantiateViewControllerWithIdentifier:@"BindMobileController"];
[self.navigationController pushViewController:bindVC animated:YES];
return;
}
// 3、进入发布动态页面
DynamicController *dyController = [DynamicController new];
dyController.delegate = self;
[self.navigationController pushViewController:dyController animated:YES];
}
- (void)didTapInformItem:(int)talkID {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
// 弹出举报框
self.talkID = talkID;
[self.communityView showInformCancelView];
}
- (void)jumpToReportPage {
ReportController *reportVC = [ReportController new];
reportVC.talkID = self.talkID;
[self.navigationController pushViewController:reportVC animated:YES];
}
- (void)didSelectItemWithModel:(ComDynModel *)comDynModel {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
DynamicDetailController *detailVC = [DynamicDetailController new];
detailVC.comDynModel = comDynModel;
detailVC.delegate = self;
[self.navigationController pushViewController:detailVC animated:YES];
}
- (void)didTapLikeItem:(ComDynModel *)comDynModel cell:(ComDynamicCell *)cell {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
// 1、用户点赞或取消点赞直接响应UI变化
[ComListViewModel updateLikeData:comDynModel];
[cell fireLikeAnimate];
[cell updateLikeUI];
// 2、更新点赞或取消点赞请求
if (self.likeDataTask) { [self.likeDataTask cancel]; }
self.likeDataTask = [ComListViewModel userDynamicPraiseWithComDynModel:comDynModel completion:^(ComListViewModel * _Nonnull requestModel) {
// 3、如果请求失败,延迟执行回退
if (requestModel.resCode != DSResCodeSuccess) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[cell updateLikeUI];
[DSProgressHUD showToast:requestModel.errMessage];
});
}
}];
}
#pragma mark - DynamicControllerDelegate
- (void)publishSuccessWithData:(id)model {
[self.comListViewModel insertUserDyModel:model];
[self.communityView updateListView];
}
#pragma mark - DynamicDetailControllerDelegate
- (void)updateLikeOrRemark {
[self.communityView updateListView];
}
#pragma mark - lazy
- (CommunityView *)communityView {
if (!_communityView) {
_communityView = [[CommunityView alloc] initWithDelegate:self comListViewModel:self.comListViewModel];
}
return _communityView;
}
#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
}
@end