Permalink
Browse files

Improve file download method with progress block, returned operation

Update demo app to display progress view when downloading files
Reformat code and comments
Update copyright notice for 2013
  • Loading branch information...
1 parent 35c134f commit 5170a0384f981839a9d61db6be41cf38a593e5e8 @vtourraine vtourraine committed Jun 4, 2013
Showing with 1,224 additions and 1,092 deletions.
  1. +31 −31 Examples/MendeleySDKDemo/MendeleySDKDemo.xcodeproj/project.pbxproj
  2. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLAppDelegate.h
  3. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLAppDelegate.m
  4. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLCategoriesViewController.h
  5. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLCategoriesViewController.m
  6. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLCategoryViewController.h
  7. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLCategoryViewController.m
  8. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentCreatorViewController.h
  9. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentCreatorViewController.m
  10. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentDetailsViewController.h
  11. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentDetailsViewController.m
  12. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentSearchResultsViewController.h
  13. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentSearchResultsViewController.m
  14. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentSearchViewController.h
  15. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLDocumentSearchViewController.m
  16. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLFilesViewController.h
  17. +37 −5 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLFilesViewController.m
  18. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLFoldersViewController.h
  19. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLFoldersViewController.m
  20. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLGroupViewController.h
  21. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLGroupViewController.m
  22. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLGroupsViewController.h
  23. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLGroupsViewController.m
  24. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLMenuViewController.h
  25. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLMenuViewController.m
  26. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLNewFolderViewController.h
  27. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLNewFolderViewController.m
  28. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLNewGroupViewController.h
  29. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLNewGroupViewController.m
  30. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLTopViewController.h
  31. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLTopViewController.m
  32. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLUserProfileViewController.h
  33. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLUserProfileViewController.m
  34. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLUsersViewController.h
  35. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/classes/MDLUsersViewController.m
  36. +1 −1 Examples/MendeleySDKDemo/MendeleySDKDemo/main.m
  37. +1 −1 Examples/MendeleySDKDemo/Pods/Pods-Acknowledgements.markdown
  38. +1 −1 Examples/MendeleySDKDemo/Pods/Pods-Acknowledgements.plist
  39. +948 −948 Examples/MendeleySDKDemo/Pods/Pods.xcodeproj/project.pbxproj
  40. +1 −1 LICENSE
  41. +1 −1 MendeleySDK/MDLAuthor.h
  42. +1 −1 MendeleySDK/MDLAuthor.m
  43. +1 −1 MendeleySDK/MDLCategory.h
  44. +1 −1 MendeleySDK/MDLCategory.m
  45. +1 −1 MendeleySDK/MDLDocument.h
  46. +1 −1 MendeleySDK/MDLDocument.m
  47. +13 −4 MendeleySDK/MDLFile.h
  48. +13 −8 MendeleySDK/MDLFile.m
  49. +1 −1 MendeleySDK/MDLFolder.h
  50. +1 −1 MendeleySDK/MDLFolder.m
  51. +1 −1 MendeleySDK/MDLGroup.h
  52. +1 −1 MendeleySDK/MDLGroup.m
  53. +70 −24 MendeleySDK/MDLMendeleyAPIClient.h
  54. +57 −17 MendeleySDK/MDLMendeleyAPIClient.m
  55. +1 −1 MendeleySDK/MDLPublication.h
  56. +1 −1 MendeleySDK/MDLPublication.m
  57. +1 −1 MendeleySDK/MDLSubcategory.h
  58. +1 −1 MendeleySDK/MDLSubcategory.m
  59. +1 −1 MendeleySDK/MDLTag.h
  60. +1 −1 MendeleySDK/MDLTag.m
  61. +1 −1 MendeleySDK/MDLUser.h
  62. +1 −1 MendeleySDK/MDLUser.m

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,7 +1,7 @@
//
// MDLAppDelegate.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLAppDelegate.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLCategoriesViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLCategoriesViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLCategoryViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLCategoryViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentCreatorViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentCreatorViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentDetailsViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentDetailsViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentSearchResultsViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentSearchResultsViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentSearchViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLDocumentSearchViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLFilesViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLFilesViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -23,15 +23,28 @@
#import "MDLFilesViewController.h"
#import "MDLFile.h"
+#import <AFNetworking.h>
@interface MDLFilesViewController () <UIDocumentInteractionControllerDelegate>
+@property (strong, nonatomic) AFHTTPRequestOperation *operation;
+
- (void)showAlertViewWithError:(NSError *)error;
@end
@implementation MDLFilesViewController
+#pragma mark - View lifecycle
+
+- (void)viewWillDisappear:(BOOL)animated
+{
+ [super viewWillDisappear:animated];
+
+ [self.navigationController setToolbarHidden:YES animated:animated];
+ [self.operation cancel];
+}
+
- (void)showAlertViewWithError:(NSError *)error
{
[[[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
@@ -54,11 +67,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MDLFileCell" forIndexPath:indexPath];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
+ dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterLongStyle;
dateFormatter.doesRelativeDateFormatting = YES;
- dateFormatter.timeStyle = NSDateFormatterShortStyle;
+
MDLFile *file = self.files[indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"%@ file", [file.extension uppercaseString]];
+ cell.textLabel.text = [NSString stringWithFormat:@"%@ file", [file.extension uppercaseString]];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%d Kb)", [dateFormatter stringFromDate:file.dateAdded], [file.size intValue]/1000];
return cell;
@@ -68,13 +82,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
+ UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
+ progressView.frame = CGRectMake(0, 0, self.view.frame.size.width - 30, 20);
+ UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:progressView];
+ self.toolbarItems = @[barButtonItem];
+ self.navigationController.toolbar.tintColor = self.navigationController.navigationBar.tintColor;
+ [self.navigationController setToolbarHidden:NO animated:YES];
+
+ [self.operation cancel];
+
MDLFile *file = self.files[indexPath.row];
NSString *path = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"file"] stringByAppendingPathExtension:file.extension];
- [file downloadToFileAtPath:path success:^{
+ self.operation = [file downloadToFileAtPath:path progress:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
+ progressView.progress = (float)totalBytesRead/totalBytesExpectedToRead;
+ } success:^{
+ [self.navigationController setToolbarHidden:YES animated:YES];
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
interactionController.delegate = self;
[interactionController presentPreviewAnimated:YES];
- } failure:^(NSError *error) { [self showAlertViewWithError:error]; }];
+ } failure:^(NSError *error) {
+ if (error.code != NSURLErrorCancelled)
+ {
+ [self.navigationController setToolbarHidden:YES animated:YES];
+ [self showAlertViewWithError:error];
+ }
+ }];
}
#pragma mark - Document interaction controller delegate
@@ -1,7 +1,7 @@
//
// MDLFoldersViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLFoldersViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLGroupViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLGroupViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLGroupsViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLGroupsViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLMenuViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLMenuViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLNewFolderViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLNewFolderViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLNewGroupViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLNewGroupViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLTopViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLTopViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLUserProfileViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLUserProfileViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLUsersViewController.h
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// MDLUsersViewController.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
//
// main.m
//
-// Copyright (c) 2012 shazino (shazino SAS), http://www.shazino.com/
+// Copyright (c) 2012-2013 shazino (shazino SAS), http://www.shazino.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Oops, something went wrong.

0 comments on commit 5170a03

Please sign in to comment.