-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathEACodeReleaseListViewController.m
More file actions
159 lines (143 loc) · 6.16 KB
/
Copy pathEACodeReleaseListViewController.m
File metadata and controls
159 lines (143 loc) · 6.16 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
//
// EACodeReleaseListViewController.m
// Coding_iOS
//
// Created by Easeeeeeeeee on 2018/3/22.
// Copyright © 2018年 Coding. All rights reserved.
//
#import "EACodeReleaseListViewController.h"
#import "EACodeReleases.h"
#import "ODRefreshControl.h"
#import "SVPullToRefresh.h"
#import "Coding_NetAPIManager.h"
#import "EACodeReleaseListCell.h"
#import "EACodeReleaseViewController.h"
@interface EACodeReleaseListViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate>
@property (strong, nonatomic) UITableView *myTableView;
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
@property (strong, nonatomic) EACodeReleases *myCodeReleases;
@property (strong, nonatomic) NSArray *dataList;
@end
@implementation EACodeReleaseListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"发布管理";
self.view.backgroundColor = kColorTableSectionBg;
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
tableView.dataSource = self;
tableView.delegate = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[tableView registerNib:[UINib nibWithNibName:[EACodeReleaseListCell nameOfClass] bundle:nil] forCellReuseIdentifier:[EACodeReleaseListCell nameOfClass]];
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
tableView.contentInset = insets;
tableView.scrollIndicatorInsets = insets;
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
__weak typeof(self) weakSelf = self;
[_myTableView addInfiniteScrollingWithActionHandler:^{
[weakSelf refreshMore:YES];
}];
[self refresh];
}
- (void)setMyProject:(Project *)myProject{
_myProject = myProject;
_myCodeReleases = [EACodeReleases new];
_myCodeReleases.curPro = _myProject;
}
#pragma Data
- (void)refresh{
[self refreshMore:NO];
}
- (void)refreshMore:(BOOL)willLoadMore{
if (_myCodeReleases.isLoading) {
return;
}
if (willLoadMore && !_myCodeReleases.canLoadMore) {
[_myTableView.infiniteScrollingView stopAnimating];
return;
}
_myCodeReleases.willLoadMore = willLoadMore;
[self sendRequest];
}
- (void)sendRequest{
if (_myCodeReleases.list.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_CodeReleases_WithObj:_myCodeReleases andBlock:^(EACodeReleases *data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
[weakSelf.myTableView.infiniteScrollingView stopAnimating];
if (data) {
[weakSelf.myCodeReleases configWithObj:data];
[weakSelf.myTableView reloadData];
weakSelf.myTableView.showsInfiniteScrolling = weakSelf.myCodeReleases.canLoadMore;
}
[weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:(weakSelf.myCodeReleases.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
[weakSelf refreshMore:NO];
}];
}];
}
#pragma mark TableM
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _myCodeReleases.list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
EACodeReleaseListCell *cell = [tableView dequeueReusableCellWithIdentifier:[EACodeReleaseListCell nameOfClass] forIndexPath:indexPath];
cell.curCodeRelease = self.myCodeReleases.list[indexPath.row];
cell.delegate = self;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 65;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
EACodeReleaseViewController *vc = [EACodeReleaseViewController new];
vc.curRelease = self.myCodeReleases.list[indexPath.row];
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark SWTableViewCellDelegate
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index{
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
EACodeRelease *curR = self.myCodeReleases.list[indexPath.row];
__weak typeof(self) weakSelf = self;
[[UIAlertController ea_actionSheetCustomWithTitle:[NSString stringWithFormat:@"请确认是否删除版本 %@ ?", curR.tag_name] buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIAlertAction *action, NSInteger index) {
if (index == 0) {
[weakSelf deleteRelease:curR];
}
}] showInView:self.view];
}
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{
return YES;
}
- (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{
return YES;
}
- (void)deleteRelease:(EACodeRelease *)curR{
__weak typeof(self) weakSelf = self;
[NSObject showHUDQueryStr:@"请稍等..."];
[[Coding_NetAPIManager sharedManager] request_DeleteCodeRelease:curR andBlock:^(id data, NSError *error) {
[NSObject hideHUDQuery];
if (data) {
[NSObject showHudTipStr:@"删除成功"];
// [weakSelf.myCodeReleases.list removeObject:curR];
// [weakSelf.myTableView reloadData];
[weakSelf refresh];
}
}];
}
@end