FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Controllers/FileVersionsViewController.m at master · noif/Coding-iOS · GitHub
noif
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
FileVersionsViewController.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
261 lines (227 loc) · 9.9 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Controllers
/
FileVersionsViewController.m
Copy path
File metadata and controls
261 lines (227 loc) · 9.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//
//
FileVersionsViewController.m
//
Coding_iOS
//
//
Created by Ease on 15/8/12.
//
Copyright (c) 2015年 Coding. All rights reserved.
//
#
import
"
FileVersionsViewController.h
"
#
import
"
SettingTextViewController.h
"
#
import
"
FileViewController.h
"
#
import
"
ODRefreshControl.h
"
#
import
"
Coding_NetAPIManager.h
"
#
import
"
Coding_FileManager.h
"
#
import
"
FileVersionCell.h
"
@interface
FileVersionsViewController
()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate>
@property
(
strong
,
nonatomic
) ProjectFile *curFile;
@property
(
strong
,
nonatomic
)
NSMutableArray
*versionList;
@property
(
nonatomic
,
strong
) UITableView *myTableView;
@property
(
nonatomic
,
strong
) ODRefreshControl *myRefreshControl;
@property
(
assign
,
nonatomic
)
BOOL
isLoading;
@end
@implementation
FileVersionsViewController
+ (
instancetype
)
vcWithFile
:
(ProjectFile *)
file
{
FileVersionsViewController *vc = [
self
new
];
vc.
curFile
= file;
return
vc;
}
- (
void
)
viewDidLoad
{
[
super
viewDidLoad
];
//
Do any additional setup after loading the view.
self.
title
=
@"
历史版本
"
;
//
添加myTableView
_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
registerClass:
[FileVersionCell
class
]
forCellReuseIdentifier:
kCellIdentifier_FileVersionCell
];
[
self
.view
addSubview:
tableView];
[tableView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self.
view
);
}];
tableView.
allowsMultipleSelectionDuringEditing
=
YES
;
tableView;
});
_myRefreshControl = [[ODRefreshControl
alloc
]
initInScrollView:
self
.myTableView];
[_myRefreshControl
addTarget:
self
action:
@selector
(
refresh
)
forControlEvents:
UIControlEventValueChanged];
[
self
refresh
];
}
- (
void
)
viewWillAppear
:
(
BOOL
)
animated
{
[
super
viewWillAppear:
animated];
[
self
.myTableView
reloadData
];
}
- (
void
)
refresh
{
if
(self.
isLoading
) {
return
;
}
[
self
sendRequest
];
}
- (
void
)
sendRequest
{
self.
isLoading
=
YES
;
if
(self.
versionList
.
count
<=
0
) {
[
self
.view
beginLoading
];
}
@
weakify
(self);
[[Coding_NetAPIManager
sharedManager
]
request_VersionListOfFile:
_curFile
andBlock:
^(
id
data,
NSError
*error) {
@
strongify
(self);
self.
isLoading
=
NO
;
[
self
.myRefreshControl
endRefreshing
];
[
self
.view
endLoading
];
if
(data) {
self.
versionList
= data;
[
self
.myTableView
reloadData
];
}
[
self
.view
configBlankPage:
EaseBlankPageTypeView
hasData:
self
.versionList.count >
0
hasError:
error !=
nil
reloadButtonBlock:
^(
id
sender) {
[
self
refresh
];
}];
}];
}
#
pragma mark
Table M
- (
NSInteger
)
tableView
:
(UITableView *)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
return
self.
versionList
.
count
;
}
- (UITableViewCell *)
tableView
:
(UITableView *)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
__weak
typeof
(self) weakSelf = self;
FileVersionCell *cell = [tableView
dequeueReusableCellWithIdentifier:
kCellIdentifier_FileVersionCell
forIndexPath:
indexPath];
FileVersion *curVersion = _versionList[indexPath.row];
cell.
curVersion
= curVersion;
cell.
showDiskFileBlock
= ^(
NSURL
*fileUrl, FileVersion *curVersion){
[weakSelf
goToFileVersionVC:
curVersion];
};
[cell
setRightUtilityButtons:
[
self
rightButtonsWithObj:
indexPath]
WithButtonWidth:
[FileVersionCell
cellHeight
]];
cell.
delegate
= self;
[tableView
addLineforPlainCell:
cell
forRowAtIndexPath:
indexPath
withLeftSpace:
kPaddingLeftWidth
];
return
cell;
}
- (CGFloat)
tableView
:
(UITableView *)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
return
[FileVersionCell
cellHeight
];
}
- (
void
)
tableView
:
(UITableView *)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*)
indexPath
{
[tableView
deselectRowAtIndexPath:
indexPath
animated:
YES
];
[
self
goToFileVersionVC:
_versionList[indexPath.row]];
}
#
pragma mark
Edit Table
- (
NSArray
*)
rightButtonsWithObj
:
(
NSIndexPath
*)
indexPath
{
NSMutableArray
*rightUtilityButtons = [
NSMutableArray
new
];
[rightUtilityButtons
sw_addUtilityButtonWithColor:
[UIColor
colorWithHexString:
@"
0xe6e6e6
"
]
icon:
[UIImage
imageNamed:
@"
icon_file_cell_rename
"
]];
if
(indexPath.
row
!=
0
) {
//
当前版本不能删除
[rightUtilityButtons
sw_addUtilityButtonWithColor:
[UIColor
colorWithHexString:
@"
0xff5846
"
]
icon:
[UIImage
imageNamed:
@"
icon_file_cell_delete
"
]];
}
return
rightUtilityButtons;
}
- (
BOOL
)
swipeableTableViewCellShouldHideUtilityButtonsOnSwipe
:
(SWTableViewCell *)
cell
{
return
YES
;
}
- (
BOOL
)
swipeableTableViewCell
:
(SWTableViewCell *)
cell
canSwipeToState
:
(SWCellState)
state
{
NSIndexPath
*indexPath = [_myTableView
indexPathForCell:
cell];
FileVersion *curVersion = _versionList[indexPath.row];
Coding_DownloadTask *cDownloadTask = [Coding_FileManager
cDownloadTaskForKey:
curVersion.storage_key];
if
(cDownloadTask && cDownloadTask.
task
&& cDownloadTask.
task
.
state
==
NSURLSessionTaskStateRunning
) {
return
NO
;
}
else
{
return
YES
;
}
}
- (
void
)
swipeableTableViewCell
:
(SWTableViewCell *)
cell
didTriggerRightUtilityButtonWithIndex
:
(
NSInteger
)
index
{
[cell
hideUtilityButtonsAnimated:
YES
];
NSIndexPath
*indexPath = [_myTableView
indexPathForCell:
cell];
FileVersion *curVersion = _versionList[indexPath.row];
if
(index ==
0
) {
[
self
remarkFileVersion:
curVersion];
}
else
{
[
self
deleteFileVersion:
curVersion];
}
}
- (
void
)
remarkFileVersion
:
(FileVersion *)
curVersion
{
__weak
typeof
(self) weakSelf = self;
[SettingTextViewController
showSettingFolderNameVCFromVC:
nil
withTitle:
@"
重命名文件夹
"
textValue:
curVersion.remark
type:
SettingTypeFileVersionRemark
doneBlock:
^(
NSString
*textValue) {
[weakSelf
doRemarkFileVersion:
curVersion
withRemarkStr:
textValue];
}];
}
- (
void
)
doRemarkFileVersion
:
(FileVersion *)
curVersion
withRemarkStr
:
(
NSString
*)
remarkStr
{
if
(remarkStr && ![remarkStr
isEqualToString:
curVersion.remark]) {
@
weakify
(self);
[[Coding_NetAPIManager
sharedManager
]
request_RemarkFileVersion:
curVersion
withStr:
remarkStr
andBlock:
^(
id
data,
NSError
*error) {
@
strongify
(self);
if
(data) {
curVersion.
remark
= remarkStr;
[
self
.myTableView
reloadData
];
}
}];
}
}
- (
void
)
deleteFileVersion
:
(FileVersion *)
curVersion
{
__weak
typeof
(self) weakSelf = self;
NSURL
*fileUrl = [Coding_FileManager
diskDownloadUrlForKey:
curVersion.storage_key];
Coding_DownloadTask *cDownloadTask = [Coding_FileManager
cDownloadTaskForKey:
curVersion.storage_key];
UIActionSheet *actionSheet;
if
(fileUrl) {
actionSheet = [UIActionSheet
bk_actionSheetCustomWithTitle:
@"
只是删除本地文件还是连同服务器版本一起删除?
"
buttonTitles:
@[
@"
仅删除本地文件
"
]
destructiveTitle:
@"
一起删除
"
cancelTitle:
@"
取消
"
andDidDismissBlock:
^(UIActionSheet *sheet,
NSInteger
index) {
switch
(index) {
case
0
:
[weakSelf
doDeleteFileVersion:
curVersion
fromDisk:
YES
];
break
;
case
1
:
[weakSelf
doDeleteFileVersion:
curVersion
fromDisk:
NO
];
break
;
default
:
break
;
}
}];
}
else
if
(cDownloadTask){
actionSheet = [UIActionSheet
bk_actionSheetCustomWithTitle:
@"
确定将服务器上的该版本删除?
"
buttonTitles:
@[
@"
只是取消下载
"
]
destructiveTitle:
@"
确认删除
"
cancelTitle:
@"
取消
"
andDidDismissBlock:
^(UIActionSheet *sheet,
NSInteger
index) {
switch
(index) {
case
0
:
[weakSelf
doDeleteFileVersion:
curVersion
fromDisk:
YES
];
break
;
case
1
:
[weakSelf
doDeleteFileVersion:
curVersion
fromDisk:
NO
];
break
;
default
:
break
;
}
}];
}
else
{
actionSheet = [UIActionSheet
bk_actionSheetCustomWithTitle:
@"
确定将服务器上的该版本删除?
"
buttonTitles:
nil
destructiveTitle:
@"
确认删除
"
cancelTitle:
@"
取消
"
andDidDismissBlock:
^(UIActionSheet *sheet,
NSInteger
index) {
if
(index ==
0
) {
[weakSelf
doDeleteFileVersion:
curVersion
fromDisk:
NO
];
}
}];
}
[actionSheet
showInView:
self
.view];
}
- (
void
)
doDeleteFileVersion
:
(FileVersion *)
curVersion
fromDisk
:
(
BOOL
)
fromDisk
{
//
取消当前的下载任务
Coding_DownloadTask *cDownloadTask = [Coding_FileManager
cDownloadTaskForKey:
curVersion.storage_key];
if
(cDownloadTask) {
[Coding_FileManager
cancelCDownloadTaskForKey:
curVersion.storage_key];
}
//
删除本地文件
NSURL
*fileUrl = [Coding_FileManager
diskDownloadUrlForKey:
curVersion.storage_key];
NSString
*filePath = fileUrl.
path
;
NSFileManager
*fm = [
NSFileManager
defaultManager
];
if
([fm
fileExistsAtPath:
filePath]) {
NSError
*fileError;
[fm
removeItemAtPath:
filePath
error:
&fileError];
if
(fileError) {
[
NSObject
showError:
fileError];
}
}
[
self
.myTableView
performSelector:
@selector
(
reloadData
)
withObject:
nil
afterDelay:
0.1
];
//
删除服务器文件
if
(!fromDisk) {
__weak
typeof
(self) weakSelf = self;
[[Coding_NetAPIManager
sharedManager
]
request_DeleteFileVersion:
curVersion
andBlock:
^(
id
data,
NSError
*error) {
[weakSelf
refresh
];
}];
}
}
#
pragma mark
toVC
- (
void
)
goToFileVersionVC
:
(FileVersion *)
curVersion
{
FileViewController *vc = [FileViewController
vcWithFile:
_curFile
andVersion:
curVersion];
[
self
.navigationController
pushViewController:
vc
animated:
YES
];
}
@end
Back
|
FazBrowse Home
|
New Git URL