CCUploadFromOtherUpp.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // CCUploadFromOtherUpp.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 01/12/14.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCUploadFromOtherUpp.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCUploadFromOtherUpp()
  27. {
  28. NSString *serverUrlLocal;
  29. NSString *destinationTitle;
  30. }
  31. @end
  32. @implementation CCUploadFromOtherUpp
  33. - (void)viewDidLoad
  34. {
  35. [super viewDidLoad];
  36. self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"_cancel_", nil);
  37. self.title = NSLocalizedString(@"_upload_", nil);
  38. serverUrlLocal= [CCUtility getHomeServerUrlActiveUrl:app.activeUrl];
  39. destinationTitle = NSLocalizedString(@"_home_", nil);
  40. // Color
  41. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  42. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  43. }
  44. - (void)didReceiveMemoryWarning
  45. {
  46. [super didReceiveMemoryWarning];
  47. }
  48. // E' apparsa
  49. - (void)viewDidAppear:(BOOL)animated
  50. {
  51. [super viewDidAppear:animated];
  52. [self.tableView reloadData];
  53. }
  54. #pragma --------------------------------------------------------------------------------------------
  55. #pragma mark == tableView ==
  56. #pragma --------------------------------------------------------------------------------------------
  57. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  58. {
  59. if (section == 0) return NSLocalizedString(@"_file_to_upload_", nil);
  60. else if (section == 2) return NSLocalizedString(@"_destination_", nil);
  61. else if (section == 4) return NSLocalizedString(@"_upload_file_", nil);
  62. return @"";
  63. }
  64. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  67. cell.accessoryType = UITableViewCellAccessoryNone;
  68. UILabel *nameLabel;
  69. NSUInteger section = [indexPath section];
  70. NSUInteger row = [indexPath row];
  71. switch (section)
  72. {
  73. case 0:
  74. if (row == 0) {
  75. NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, app.fileNameUpload] error:nil];
  76. NSString *fileSize = [CCUtility transformedSize:[[fileAttributes objectForKey:NSFileSize] longValue]];
  77. nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = [NSString stringWithFormat:@"%@ - %@", app.fileNameUpload, fileSize];
  78. }
  79. break;
  80. case 2:
  81. if (row == 0) {
  82. nameLabel = (UILabel *)[cell viewWithTag:101]; nameLabel.text = destinationTitle;
  83. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  84. UIImageView *img = (UIImageView *)[cell viewWithTag:201];
  85. img.image = [UIImage imageNamed:@"folder"];
  86. }
  87. break;
  88. case 4:
  89. if (row == 0) {
  90. nameLabel = (UILabel *)[cell viewWithTag:102]; nameLabel.text = NSLocalizedString(@"_upload_file_", nil);
  91. }
  92. break;
  93. }
  94. return cell;
  95. }
  96. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  97. {
  98. NSUInteger section = [indexPath section];
  99. NSUInteger row = [indexPath row];
  100. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  101. switch (section) {
  102. case 2:
  103. if (row == 0) {
  104. [self changeFolder];
  105. }
  106. break;
  107. case 4:
  108. if (row == 0) {
  109. [self upload];
  110. }
  111. break;
  112. }
  113. }
  114. #pragma --------------------------------------------------------------------------------------------
  115. #pragma mark == IBAction ==
  116. #pragma --------------------------------------------------------------------------------------------
  117. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title
  118. {
  119. if (serverUrlTo) {
  120. serverUrlLocal = serverUrlTo;
  121. if (title) destinationTitle = title;
  122. else destinationTitle = NSLocalizedString(@"_home_", nil);
  123. }
  124. }
  125. - (void)changeFolder
  126. {
  127. UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  128. CCMove *viewController = (CCMove *)navigationController.topViewController;
  129. viewController.delegate = self;
  130. viewController.move.title = NSLocalizedString(@"_select_", nil);
  131. viewController.tintColor = [NCBrandColor sharedInstance].navigationBarText;
  132. viewController.barTintColor = [NCBrandColor sharedInstance].brand;
  133. viewController.tintColorTitle = [NCBrandColor sharedInstance].navigationBarText;
  134. viewController.networkingOperationQueue = app.netQueue;
  135. [self presentViewController:navigationController animated:YES completion:nil];
  136. }
  137. -(void)upload
  138. {
  139. [[CCNetworking sharedNetworking] uploadFile:app.fileNameUpload serverUrl:serverUrlLocal session:k_upload_session taskStatus: k_taskStatusResume selector:@"" selectorPost:@"" errorCode:0 delegate:nil];
  140. [self dismissViewControllerAnimated:YES completion:nil];
  141. }
  142. - (IBAction)Annula:(UIBarButtonItem *)sender
  143. {
  144. [self dismissViewControllerAnimated:YES completion:nil];
  145. }
  146. @end