Skip to content

Commit 3270942

Browse files
committed
文档 - 历史版本&动态
1 parent b588d7b commit 3270942

27 files changed

Lines changed: 915 additions & 309 deletions

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@
385385
4EAE06C21B7B51AF00179F4B /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EAE06BE1B7B51AF00179F4B /* [email protected] */; };
386386
4EAE06C31B7B51AF00179F4B /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EAE06BF1B7B51AF00179F4B /* [email protected] */; };
387387
4EAE06C51B7B587200179F4B /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EAE06C41B7B587200179F4B /* [email protected] */; };
388+
4EAE06C81B7C9EFF00179F4B /* FileVersionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EAE06C71B7C9EFF00179F4B /* FileVersionCell.m */; };
388389
4EB0C2001A807ED00042FC4F /* NSURL+Common.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EB0C1FF1A807ED00042FC4F /* NSURL+Common.m */; };
389390
4EB845331AB83C3B0030DC69 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EB845301AB83C3B0030DC69 /* [email protected] */; };
390391
4EB845341AB83C3B0030DC69 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EB845311AB83C3B0030DC69 /* [email protected] */; };
@@ -1436,6 +1437,8 @@
14361437
4EAE06BE1B7B51AF00179F4B /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
14371438
4EAE06BF1B7B51AF00179F4B /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
14381439
4EAE06C41B7B587200179F4B /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
1440+
4EAE06C61B7C9EFF00179F4B /* FileVersionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileVersionCell.h; sourceTree = "<group>"; };
1441+
4EAE06C71B7C9EFF00179F4B /* FileVersionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileVersionCell.m; sourceTree = "<group>"; };
14391442
4EB0C1FE1A807ED00042FC4F /* NSURL+Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+Common.h"; sourceTree = "<group>"; };
14401443
4EB0C1FF1A807ED00042FC4F /* NSURL+Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+Common.m"; sourceTree = "<group>"; };
14411444
4EB845301AB83C3B0030DC69 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
@@ -4241,6 +4244,8 @@
42414244
4EAE06B31B7B325600179F4B /* FileCommentCell.m */,
42424245
4EAE06B51B7B330900179F4B /* FileActivityCell.h */,
42434246
4EAE06B61B7B330900179F4B /* FileActivityCell.m */,
4247+
4EAE06C61B7C9EFF00179F4B /* FileVersionCell.h */,
4248+
4EAE06C71B7C9EFF00179F4B /* FileVersionCell.m */,
42444249
);
42454250
path = Cell;
42464251
sourceTree = "<group>";
@@ -4936,6 +4941,7 @@
49364941
4E996BE51ABAB1D700C704F1 /* ProjectListTaCell.m in Sources */,
49374942
8EE72BE519E3F2E8002C11D9 /* UIImageView+MJWebCache.m in Sources */,
49384943
8EA6D1B119E240C40076D59C /* Commit.m in Sources */,
4944+
4EAE06C81B7C9EFF00179F4B /* FileVersionCell.m in Sources */,
49394945
4EA7F1661A6D192B00A046BD /* UIView+WebCacheOperation.m in Sources */,
49404946
8EF643D119FF7E2900F7EEB0 /* TweetSendTextCell.m in Sources */,
49414947
8EA6D22319E240C40076D59C /* XTSegmentControl.m in Sources */,

Coding_iOS/Controllers/FileActivitiesViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ - (void)viewDidLoad
4646

4747
_myTableView = ({
4848
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
49-
tableView.backgroundColor = kColorTableBG;
49+
tableView.backgroundColor = [UIColor clearColor];
5050
tableView.delegate = self;
5151
tableView.dataSource = self;
5252
[tableView registerClass:[FileCommentCell class] forCellReuseIdentifier:kCellIdentifier_FileCommentCell];

Coding_iOS/Controllers/FileListViewController.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ - (void)reverseSelect{
136136
}
137137

138138
- (void)configuploadFiles{
139-
self.uploadFiles = [[Coding_FileManager sharedManager] uploadFilesInProject:self.curProject.id.stringValue andFolder:self.curFolder.file_id.stringValue];
139+
self.uploadFiles = [Coding_FileManager uploadFilesInProject:self.curProject.id.stringValue andFolder:self.curFolder.file_id.stringValue];
140140
if (!self.uploadFiles) {
141141
self.uploadFiles = [NSArray array];
142142
}
@@ -369,7 +369,7 @@ - (void)downloadFilesBtnClicked{
369369
DebugLog(@"%@: 已在队列", file.name);
370370
}else{
371371
addDownloadCount++;
372-
[manager addDownloadTaskForFile:file completionHandler:nil];
372+
[manager addDownloadTaskForObj:file completionHandler:nil];
373373
}
374374
}
375375
if (addDownloadCount == 0) {
@@ -447,8 +447,7 @@ - (void)uploadFileWithFileName:(NSString *)fileName{
447447
}
448448

449449
- (void)removeUploadTaskWithFileName:(NSString *)fileName{
450-
Coding_FileManager *manager = [Coding_FileManager sharedManager];
451-
[manager removeCUploadTaskForFile:fileName hasError:NO];
450+
[Coding_FileManager cancelCUploadTaskForFile:fileName hasError:NO];
452451
[self configuploadFiles];
453452
}
454453

@@ -706,7 +705,7 @@ - (void)deleteFile:(ProjectFile *)file fromDisk:(BOOL)fromDisk{
706705
// 取消当前的下载任务
707706
Coding_DownloadTask *cDownloadTask = [file cDownloadTask];
708707
if (cDownloadTask) {
709-
[[Coding_FileManager sharedManager] removeCDownloadTaskForKey:file.storage_key];
708+
[Coding_FileManager cancelCDownloadTaskForKey:file.storage_key];
710709
}
711710
// 删除本地文件
712711
NSURL *fileUrl = [file hasBeenDownload];
@@ -762,8 +761,7 @@ - (void)goToVCWithFolder:(ProjectFolder *)folder inProject:(Project *)project{
762761
}
763762

764763
- (void)goToFileVC:(ProjectFile *)file{
765-
FileViewController *vc = [[FileViewController alloc] init];
766-
vc.curFile = file;
764+
FileViewController *vc = [FileViewController vcWithFile:file andVersion:nil];
767765
[self.navigationController pushViewController:vc animated:YES];
768766
}
769767

Coding_iOS/Controllers/FileVersionsViewController.m

Lines changed: 238 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,25 @@
77
//
88

99
#import "FileVersionsViewController.h"
10+
#import "SettingTextViewController.h"
11+
#import "FileViewController.h"
1012

11-
@interface FileVersionsViewController ()
13+
#import "ODRefreshControl.h"
14+
#import "Coding_NetAPIManager.h"
15+
#import "Coding_FileManager.h"
16+
17+
18+
#import "FileVersionCell.h"
19+
20+
21+
@interface FileVersionsViewController ()<UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate>
1222
@property (strong, nonatomic) ProjectFile *curFile;
23+
@property (strong, nonatomic) NSMutableArray *versionList;
24+
25+
@property (nonatomic, strong) UITableView *myTableView;
26+
@property (nonatomic, strong) ODRefreshControl *myRefreshControl;
27+
28+
@property (assign, nonatomic) BOOL isLoading;
1329

1430
@end
1531

@@ -19,4 +35,225 @@ + (instancetype)vcWithFile:(ProjectFile *)file{
1935
vc.curFile = file;
2036
return vc;
2137
}
38+
39+
- (void)viewDidLoad
40+
{
41+
[super viewDidLoad];
42+
// Do any additional setup after loading the view.
43+
self.title = self.curFile.name;
44+
45+
// 添加myTableView
46+
_myTableView = ({
47+
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
48+
tableView.backgroundColor = [UIColor clearColor];
49+
tableView.dataSource = self;
50+
tableView.delegate = self;
51+
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
52+
[tableView registerClass:[FileVersionCell class] forCellReuseIdentifier:kCellIdentifier_FileVersionCell];
53+
[self.view addSubview:tableView];
54+
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
55+
make.edges.equalTo(self.view);
56+
}];
57+
tableView.allowsMultipleSelectionDuringEditing = YES;
58+
tableView;
59+
});
60+
61+
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
62+
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
63+
64+
[self refresh];
65+
}
66+
67+
- (void)viewWillAppear:(BOOL)animated{
68+
[super viewWillAppear:animated];
69+
[self.myTableView reloadData];
70+
}
71+
72+
- (void)refresh{
73+
if (self.isLoading) {
74+
return;
75+
}
76+
[self sendRequest];
77+
}
78+
79+
- (void)sendRequest{
80+
self.isLoading = YES;
81+
if (self.versionList.count <= 0) {
82+
[self.view beginLoading];
83+
}
84+
@weakify(self);
85+
[[Coding_NetAPIManager sharedManager] request_VersionListOfFile:_curFile andBlock:^(id data, NSError *error) {
86+
@strongify(self);
87+
self.isLoading = NO;
88+
[self.myRefreshControl endRefreshing];
89+
[self.view endLoading];
90+
if (data) {
91+
self.versionList = data;
92+
[self.myTableView reloadData];
93+
}
94+
[self.view configBlankPage:EaseBlankPageTypeView hasData:self.versionList.count > 0 hasError:error != nil reloadButtonBlock:^(id sender) {
95+
[self refresh];
96+
}];
97+
}];
98+
}
99+
100+
#pragma mark Table M
101+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
102+
return self.versionList.count;
103+
}
104+
105+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
106+
__weak typeof(self) weakSelf = self;
107+
108+
FileVersionCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_FileVersionCell forIndexPath:indexPath];
109+
FileVersion *curVersion = _versionList[indexPath.row];
110+
cell.curVersion = curVersion;
111+
cell.showDiskFileBlock = ^(NSURL *fileUrl, FileVersion *curVersion){
112+
[weakSelf goToFileVersionVC:curVersion];
113+
};
114+
[cell setRightUtilityButtons:[self rightButtonsWithObj:curVersion] WithButtonWidth:[FileVersionCell cellHeight]];
115+
cell.delegate = self;
116+
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
117+
return cell;
118+
}
119+
120+
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
121+
return [FileVersionCell cellHeight];
122+
}
123+
124+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
125+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
126+
[self goToFileVersionVC:_versionList[indexPath.row]];
127+
}
128+
129+
#pragma mark Edit Table
130+
- (NSArray *)rightButtonsWithObj:(id)obj{
131+
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
132+
[rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:@"0xe6e6e6"] icon:[UIImage imageNamed:@"icon_file_cell_rename"]];
133+
[rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:@"0xff5846"] icon:[UIImage imageNamed:@"icon_file_cell_delete"]];
134+
return rightUtilityButtons;
135+
}
136+
137+
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell{
138+
return YES;
139+
}
140+
- (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{
141+
NSIndexPath *indexPath = [_myTableView indexPathForCell:cell];
142+
FileVersion *curVersion = _versionList[indexPath.row];
143+
Coding_DownloadTask *cDownloadTask = [Coding_FileManager cDownloadTaskForKey:curVersion.storage_key];
144+
if (cDownloadTask && cDownloadTask.task && cDownloadTask.task.state == NSURLSessionTaskStateRunning) {
145+
return NO;
146+
}else{
147+
return YES;
148+
}
149+
}
150+
151+
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
152+
[cell hideUtilityButtonsAnimated:YES];
153+
NSIndexPath *indexPath = [_myTableView indexPathForCell:cell];
154+
FileVersion *curVersion = _versionList[indexPath.row];
155+
if (index == 0) {
156+
[self remarkFileVersion:curVersion];
157+
}else{
158+
[self deleteFileVersion:curVersion];
159+
}
160+
}
161+
162+
- (void)remarkFileVersion:(FileVersion *)curVersion{
163+
__weak typeof(self) weakSelf = self;
164+
[SettingTextViewController showSettingFolderNameVCFromVC:nil withTitle:@"重命名文件夹" textValue:curVersion.remark type:SettingTypeFileVersionRemark doneBlock:^(NSString *textValue) {
165+
[weakSelf doRemarkFileVersion:curVersion withRemarkStr:textValue];
166+
}];
167+
}
168+
169+
- (void)doRemarkFileVersion:(FileVersion *)curVersion withRemarkStr:(NSString *)remarkStr{
170+
if (remarkStr && ![remarkStr isEqualToString:curVersion.remark]) {
171+
@weakify(self);
172+
[[Coding_NetAPIManager sharedManager] request_RemarkFileVersion:curVersion withStr:remarkStr andBlock:^(id data, NSError *error) {
173+
@strongify(self);
174+
if (data) {
175+
curVersion.remark = remarkStr;
176+
[self.myTableView reloadData];
177+
}
178+
}];
179+
}
180+
}
181+
182+
- (void)deleteFileVersion:(FileVersion *)curVersion{
183+
__weak typeof(self) weakSelf = self;
184+
185+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key];
186+
Coding_DownloadTask *cDownloadTask = [Coding_FileManager cDownloadTaskForKey:curVersion.storage_key];
187+
UIActionSheet *actionSheet;
188+
189+
if (fileUrl) {
190+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"只是删除本地文件还是连同服务器版本一起删除?" buttonTitles:@[@"仅删除本地文件"] destructiveTitle:@"一起删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
191+
switch (index) {
192+
case 0:
193+
[weakSelf doDeleteFileVersion:curVersion fromDisk:YES];
194+
break;
195+
case 1:
196+
[weakSelf doDeleteFileVersion:curVersion fromDisk:NO];
197+
break;
198+
default:
199+
break;
200+
}
201+
}];
202+
}else if (cDownloadTask){
203+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该版本删除?" buttonTitles:@[@"只是取消下载"] destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
204+
switch (index) {
205+
case 0:
206+
[weakSelf doDeleteFileVersion:curVersion fromDisk:YES];
207+
break;
208+
case 1:
209+
[weakSelf doDeleteFileVersion:curVersion fromDisk:NO];
210+
break;
211+
default:
212+
break;
213+
}
214+
}];
215+
}else{
216+
actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle:@"确定将服务器上的该版本删除?" buttonTitles:nil destructiveTitle:@"确认删除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
217+
if (index == 0) {
218+
[weakSelf doDeleteFileVersion:curVersion fromDisk:NO];
219+
}
220+
}];
221+
}
222+
[actionSheet showInView:self.view];
223+
}
224+
225+
- (void)doDeleteFileVersion:(FileVersion *)curVersion fromDisk:(BOOL)fromDisk{
226+
// 取消当前的下载任务
227+
Coding_DownloadTask *cDownloadTask = [Coding_FileManager cDownloadTaskForKey:curVersion.storage_key];
228+
if (cDownloadTask) {
229+
[Coding_FileManager cancelCDownloadTaskForKey:curVersion.storage_key];
230+
}
231+
// 删除本地文件
232+
NSURL *fileUrl = [Coding_FileManager diskDownloadUrlForKey:curVersion.storage_key];
233+
NSString *filePath = fileUrl.path;
234+
NSFileManager *fm = [NSFileManager defaultManager];
235+
if ([fm fileExistsAtPath:filePath]) {
236+
NSError *fileError;
237+
[fm removeItemAtPath:filePath error:&fileError];
238+
if (fileError) {
239+
[self showError:fileError];
240+
}
241+
}
242+
[self.myTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
243+
// 删除服务器文件
244+
if (!fromDisk) {
245+
__weak typeof(self) weakSelf = self;
246+
[[Coding_NetAPIManager sharedManager] request_DeleteFileVersion:curVersion andBlock:^(id data, NSError *error) {
247+
[weakSelf refresh];
248+
}];
249+
}
250+
}
251+
252+
#pragma mark toVC
253+
- (void)goToFileVersionVC:(FileVersion *)curVersion{
254+
FileViewController *vc = [FileViewController vcWithFile:_curFile andVersion:curVersion];
255+
[self.navigationController pushViewController:vc animated:YES];
256+
}
257+
258+
22259
@end

Coding_iOS/Controllers/FileViewController.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
#import "ProjectFolder.h"
1111
#import "ProjectFolders.h"
1212
#import "ProjectFile.h"
13+
#import "FileVersion.h"
1314

1415
@interface FileViewController : BaseViewController
15-
@property (strong, nonatomic) ProjectFile *curFile;
16+
@property (strong, nonatomic, readonly) ProjectFile *curFile;
17+
@property (strong, nonatomic, readonly) FileVersion *curVersion;
18+
+ (instancetype)vcWithFile:(ProjectFile *)file andVersion:(FileVersion *)version;
1619
- (void)requestFileData;
1720
@end

0 commit comments

Comments
 (0)