Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5beb7c5

Browse filesBrowse files
committed
文件上传【退出再进入页面后,下载完成无刷新】
1 parent 7cc2612 commit 5beb7c5
Copy full SHA for 5beb7c5

File tree

Expand file treeCollapse file tree

11 files changed

+47
-44
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

11 files changed

+47
-44
lines changed
Open diff view settings
Collapse file

‎Coding_iOS/Controllers/FileListViewController.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Controllers/FileListViewController.m
+24-21Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
#import "QBImagePickerController.h"
2525
#import "Helper.h"
2626
#import "FileListUploadCell.h"
27+
#import "Coding_FileManager.h"
2728

2829

29-
@interface FileListViewController () <SWTableViewCellDelegate, EaseToolBarDelegate, QBImagePickerControllerDelegate>
30+
@interface FileListViewController () <SWTableViewCellDelegate, EaseToolBarDelegate, QBImagePickerControllerDelegate, Coding_FileManagerDelegate>
3031
@property (nonatomic, strong) UITableView *myTableView;
3132
@property (nonatomic, strong) ODRefreshControl *refreshControl;
3233
@property (strong, nonatomic) ProjectFiles *myFiles;
@@ -86,6 +87,8 @@ - (void)loadView{
8687

8788
_refreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
8889
[_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
90+
91+
[Coding_FileManager sharedManager].delegate = self;
8992
if (!self.rootFolders) {
9093
self.rootFolders = [ProjectFolders emptyFolders];
9194
}
@@ -267,35 +270,35 @@ - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePicker
267270

268271
#pragma mark uploadTask
269272
- (void)addUploadTaskWithFileName:(NSString *)fileName{
270-
__weak typeof(self) weakSelf = self;
271-
272273
Coding_FileManager *manager = [Coding_FileManager sharedManager];
273-
[manager addUploadTaskWithFileName:fileName completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
274-
if (error) {
275-
[weakSelf showError:error];
276-
}else{
277-
ProjectFile *curFile = responseObject;
278-
if (curFile.name && curFile.name.length > 0) {
279-
curFile.project_id = weakSelf.curProject.id;
280-
[weakSelf.myFiles.list insertObject:curFile atIndex:0];
281-
}
282-
}
283-
[weakSelf configuploadFiles];
284-
}];
285-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
286-
[self configuploadFiles];
287-
});
274+
[manager addUploadTaskWithFileName:fileName];
275+
[self configuploadFiles];
288276
}
289277

290278
- (void)removeUploadTaskWithFileName:(NSString *)fileName{
291279
Coding_FileManager *manager = [Coding_FileManager sharedManager];
292280
[manager removeCUploadTaskForFile:fileName hasError:NO];
293-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
294-
[self configuploadFiles];
295-
});
281+
[self configuploadFiles];
296282
}
297283

284+
- (void)completionUploadWithResult:(id)responseObject error:(NSError *)error{
285+
if (error) {
286+
[self showError:error];
287+
}else{
288+
ProjectFile *curFile = responseObject;
289+
if (curFile.name && curFile.name.length > 0) {
290+
curFile.project_id = self.curProject.id;
291+
[self.myFiles.list insertObject:curFile atIndex:0];
292+
self.curFolder.count = @(self.curFolder.count.integerValue +1);
293+
}
294+
}
295+
[self configuploadFiles];
296+
}
298297

298+
#pragma mark Coding_FileManagerDelegate
299+
- (void)completionUploadResponse:(NSURLResponse *)response withResponseObject:(id)responseObject andError:(NSError *)error{
300+
[self completionUploadWithResult:responseObject error:error];
301+
}
299302

300303
#pragma mark Table M
301304
- (NSInteger)totalDataRow{
Collapse file

‎Coding_iOS/Controllers/FileViewController.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Controllers/FileViewController.m
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ - (void)loadWebView:(NSURL *)fileUrl{
139139
[self.view addSubview:_contentWebView];
140140
}
141141
if ([self.curFile.fileType isEqualToString:@"md"]){
142-
// NSData *mdData = [NSData dataWithContentsOfURL:fileUrl];
143-
// NSString *mdStr = [[NSString alloc] initWithData:mdData encoding:NSUTF8StringEncoding];
144142
NSError *error = nil;
145143
NSString *htmlStr;
146144
@try {
Collapse file

‎Coding_iOS/Models/ProjectFile.h‎

Copy file name to clipboardExpand all lines: Coding_iOS/Models/ProjectFile.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#import <Foundation/Foundation.h>
1010
#import "User.h"
11-
#import "Coding_FileManager.h"
1211

1312

1413
typedef NS_ENUM(NSInteger, DownloadState){
Collapse file

‎Coding_iOS/Models/ProjectFile.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Models/ProjectFile.m
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "ProjectFile.h"
10+
#import "Coding_FileManager.h"
1011

1112
@implementation ProjectFile
1213

Collapse file

‎Coding_iOS/Util/Manager/Coding_FileManager.h‎

Copy file name to clipboardExpand all lines: Coding_iOS/Util/Manager/Coding_FileManager.h
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
@class Coding_DownloadTask;
1515
@class Coding_UploadTask;
1616
@class ProjectFile;
17+
@protocol Coding_FileManagerDelegate;
1718

1819
@interface Coding_FileManager : NSObject
20+
@property (nonatomic, weak) id<Coding_FileManagerDelegate> delegate;
1921

2022
//download
2123
+ (Coding_FileManager *)sharedManager;
@@ -36,7 +38,7 @@
3638
- (NSURL *)diskUploadUrlForFile:(NSString *)fileName;
3739
- (void)removeCUploadTaskForFile:(NSString *)fileName hasError:(BOOL)hasError;
3840
- (Coding_UploadTask *)cUploadTaskForFile:(NSString *)fileName;
39-
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler;
41+
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName;
4042
- (NSArray *)uploadFilesInProject:(NSString *)project_id andFolder:(NSString *)folder_id;
4143
@end
4244

@@ -54,4 +56,10 @@
5456
@property (strong, nonatomic) NSString *fileName;
5557
+ (Coding_UploadTask *)cUploadTaskWithTask:(NSURLSessionUploadTask *)task progress:(NSProgress *)progress fileName:(NSString *)fileName;
5658
- (void)cancel;
59+
@end
60+
61+
62+
@protocol Coding_FileManagerDelegate <NSObject>
63+
@optional
64+
- (void)completionUploadResponse:(NSURLResponse *)response withResponseObject:(id)responseObject andError:(NSError *)error;
5765
@end
Collapse file

‎Coding_iOS/Util/Manager/Coding_FileManager.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Util/Manager/Coding_FileManager.m
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ + (BOOL)writeUploadDataWithName:(NSString*)fileName andAsset:(ALAsset*)asset{
204204
free(buffer);
205205
return YES;
206206
}
207-
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler{
207+
- (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName{
208208
if (!fileName) {
209209
return nil;
210210
}
@@ -234,8 +234,8 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName completion
234234

235235
if (error) {
236236
[manager showError:error];
237-
if (completionHandler) {
238-
completionHandler(response, nil, error);
237+
if (manager.delegate && [manager.delegate respondsToSelector:@selector(completionUploadResponse:withResponseObject:andError:)]) {
238+
[manager.delegate completionUploadResponse:response withResponseObject:nil andError:error];
239239
}
240240
}else{
241241
NSString *block_project_id = [[[[response.URL.absoluteString componentsSeparatedByString:@"/project/"] lastObject] componentsSeparatedByString:@"/file/"] firstObject];
@@ -257,8 +257,8 @@ - (Coding_UploadTask *)addUploadTaskWithFileName:(NSString *)fileName completion
257257
[[Coding_FileManager sharedManager] removeCUploadTaskForFile:block_fileName hasError:(error != nil)];
258258

259259
//处理completionHandler
260-
if (completionHandler) {
261-
completionHandler(response, curFile, nil);
260+
if (manager.delegate && [manager.delegate respondsToSelector:@selector(completionUploadResponse:withResponseObject:andError:)]) {
261+
[manager.delegate completionUploadResponse:response withResponseObject:curFile andError:nil];
262262
}
263263
}
264264
}];
@@ -298,6 +298,7 @@ - (NSArray *)uploadFilesInProject:(NSString *)project_id andFolder:(NSString *)f
298298
if (!project_id || !folder_id) {
299299
return nil;
300300
}
301+
[self directoryDidChange:self.docUploadWatcher];
301302
NSMutableArray *uploadFiles = [NSMutableArray array];
302303
for (NSString *fileName in [self.diskUploadDict allKeys]) {
303304
NSArray *fileInfos = [fileName componentsSeparatedByString:@"|||"];
Collapse file

‎Coding_iOS/Util/OC_Category/NSDate+Common.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Util/OC_Category/NSDate+Common.m
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ - (NSInteger)secondsAgo{
2222
fromDate:self
2323
toDate:[NSDate date]
2424
options:0];
25-
NSDate *now = [NSDate date];
2625
return [components second];
2726
}
2827
- (NSInteger)minutesAgo{
Collapse file

‎Coding_iOS/Vendor/FontAwesome+iOS/FAImageView.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Vendor/FontAwesome+iOS/FAImageView.m
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (UILabel*)defaultView
5454
//The default icon is the ban icon
5555
[self setDefaultIcon:FAIconBanCircle];
5656

57-
_defaultView.font = [UIFont iconicFontOfSize:self.bounds.size.height];
57+
_defaultView.font = [UIFont fontAwesomeFontOfSize:self.bounds.size.height];
5858
_defaultView.textAlignment = NSTextAlignmentCenter;
5959
_defaultView.adjustsFontSizeToFitWidth = YES;
6060

Collapse file

‎Coding_iOS/Views/Cell/FileListUploadCell.h‎

Copy file name to clipboardExpand all lines: Coding_iOS/Views/Cell/FileListUploadCell.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@property (strong, nonatomic) NSString *fileName;
1313
@property (nonatomic,copy) void(^reUploadBlock)(NSString *fileName);
1414
@property (nonatomic,copy) void(^cancelUploadBlock)(NSString *fileName);
15-
@property (nonatomic,copy) void(^doneUploadBlock)();
1615

1716
+ (CGFloat)cellHeight;
1817
@end
Collapse file

‎Coding_iOS/Views/Cell/FileListUploadCell.m‎

Copy file name to clipboardExpand all lines: Coding_iOS/Views/Cell/FileListUploadCell.m
+5-11Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ - (void)setProgress:(NSProgress *)progress{
9292
__weak typeof(self) weakSelf = self;
9393
if (_progress) {
9494
[_progressView setTrackTintColor:[UIColor colorWithHexString:@"0xd5d5d5"]];
95-
96-
[[RACObserve(self, progress.fractionCompleted) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(NSNumber *fractionCompleted) {
95+
96+
[[RACObserve(self, progress.fractionCompleted) takeUntil:
97+
[RACSignal combineLatest:@[self.rac_prepareForReuseSignal, self.rac_willDeallocSignal]]]
98+
subscribeNext:^(NSNumber *fractionCompleted) {
9799
dispatch_async(dispatch_get_main_queue(), ^{
98-
[weakSelf updatePregress:fractionCompleted.doubleValue];
100+
weakSelf.progressView.progress = fractionCompleted.doubleValue;
99101
});
100102
}];
101103
}else{
@@ -107,14 +109,6 @@ - (void)setProgress:(NSProgress *)progress{
107109
- (void)updatePregress:(double)fractionCompleted{
108110
//更新进度
109111
self.progressView.progress = fractionCompleted;
110-
if (ABS(fractionCompleted - 1.0) < 0.0001) {
111-
//已完成
112-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
113-
if (self && self.doneUploadBlock) {
114-
self.doneUploadBlock();
115-
}
116-
});
117-
}
118112
}
119113

120114
- (void)buttonClicked:(id)sender{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.