CCBancomat.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // CCBancomat.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2014 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 "CCBancomat.h"
  24. #import "AppDelegate.h"
  25. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCBancomat()
  31. {
  32. XLFormDescriptor *form ;
  33. NSTimer* myTimer;
  34. NSMutableDictionary *field;
  35. CCTemplates *templates;
  36. NSString *_saveFileID;
  37. }
  38. @end
  39. @implementation CCBancomat
  40. - (id)initWithDelegate:(id <CCBancomatDelegate>)delegate fileName:(NSString *)fileName uuid:(NSString *)uuid fileID:(NSString *)fileID isLocal:(BOOL)isLocal serverUrl:(NSString *)serverUrl
  41. {
  42. self = [super init];
  43. if (self){
  44. self.delegate = delegate;
  45. self.fileName = fileName;
  46. self.isLocal = isLocal;
  47. self.fileID = fileID;
  48. self.uuid = uuid;
  49. self.serverUrl = serverUrl;
  50. // if fileName read Crypto File
  51. if (fileName)
  52. field = [[CCCrypto sharedManager] getDictionaryEncrypted:fileName uuid:uuid isLocal:isLocal directoryUser:app.directoryUser];
  53. XLFormSectionDescriptor * section;
  54. XLFormRowDescriptor * row;
  55. // Information - Section
  56. form = [XLFormDescriptor formDescriptor];
  57. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_title_", nil)];
  58. [form addFormSection:section];
  59. if (!fileName) form.assignFirstResponderOnShow = YES;
  60. // Title
  61. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"titolo" rowType:XLFormRowDescriptorTypeText];
  62. [row.cellConfig setObject:[NCColorBrand sharedInstance].cryptocloud forKey:@"textField.textColor"];
  63. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  64. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  65. row.value = [field objectForKey:@"titolo"];
  66. row.required = YES;
  67. [section addFormRow:row];
  68. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_add_atm_card_", nil)];
  69. [form addFormSection:section];
  70. // Nome Banca
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"nomebanca" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_bank_name:_", nil)];
  72. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  75. row.value = [field objectForKey:@"nomebanca"];
  76. [section addFormRow:row];
  77. // CODE
  78. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"code" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_code:_", nil)];
  79. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  80. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  82. row.value = [field objectForKey:@"code"];
  83. [section addFormRow:row];
  84. // Secur Code
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"securcode" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_security_code:_", nil)];
  86. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  88. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  89. row.value = [field objectForKey:@"securcode"];
  90. [section addFormRow:row];
  91. // PIN
  92. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"pin" rowType:XLFormRowDescriptorTypeText title:NSLocalizedString(@"_pin:_", nil)];
  93. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textField.textColor"];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  95. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textField.font"];
  96. row.value = [field objectForKey:@"pin"];
  97. [section addFormRow:row];
  98. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_notes_", nil)];
  99. [form addFormSection:section];
  100. // Note
  101. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"note" rowType:XLFormRowDescriptorTypeTextView];
  102. row.value = [field objectForKey:@"note"];
  103. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textView.textColor"];
  104. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textView.font"];
  105. [section addFormRow:row];
  106. self.form = form;
  107. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPressed:)];
  108. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePressed:)];
  109. }
  110. return self;
  111. }
  112. - (void)viewDidLoad
  113. {
  114. [super viewDidLoad];
  115. templates = [[CCTemplates alloc] init];
  116. [templates setImageTitle:NSLocalizedString(@"_atm_card_", nil) conNavigationItem:self.navigationItem reachability:[app.reachability isReachable]];
  117. // Color
  118. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  119. }
  120. - (void)viewDidAppear:(BOOL)animated
  121. {
  122. [super viewDidAppear:animated];
  123. if (self.fileName && !field) [self performSelector:@selector(cancelPressed:) withObject:nil afterDelay:0.5];
  124. }
  125. - (void)didSelectFormRow:(XLFormRowDescriptor *)formRow
  126. {
  127. [super didSelectFormRow:formRow];
  128. if ([formRow.tag isEqual:@"mytag"]) {
  129. // do your thing for your row.
  130. }
  131. }
  132. #pragma --------------------------------------------------------------------------------------------
  133. #pragma mark - ==== IBAction ====
  134. #pragma --------------------------------------------------------------------------------------------
  135. - (IBAction)cancelPressed:(UIBarButtonItem * __unused)button
  136. {
  137. [self dismissViewControllerAnimated:YES completion:nil];
  138. }
  139. - (IBAction)savePressed:(UIBarButtonItem * __unused)button
  140. {
  141. NSString *fileNameModel;
  142. NSArray *validationErrors = [self formValidationErrors];
  143. if (validationErrors.count > 0){
  144. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_enter_title_", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"_ok_", nil) otherButtonTitles:nil];
  145. [alertView show];
  146. return;
  147. }
  148. [self.tableView endEditing:YES];
  149. fileNameModel = [templates salvaForm:form fileName:self.fileName uuid:self.uuid modello:@"bancomat" icona:@"bancomat"];
  150. if (fileNameModel) {
  151. XLFormRowDescriptor *titolo = [self.form formRowWithTag:@"titolo"];
  152. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  153. metadataNet.action = actionUploadTemplate;
  154. metadataNet.serverUrl = self.serverUrl;
  155. metadataNet.fileName = [CCUtility trasformedFileNamePlistInCrypto:fileNameModel];
  156. metadataNet.fileNamePrint = titolo.value;
  157. metadataNet.pathFolder = NSTemporaryDirectory();
  158. metadataNet.session = k_upload_session_foreground;
  159. metadataNet.taskStatus = k_taskStatusResume;
  160. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  161. }
  162. }
  163. - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  164. {
  165. if (![_saveFileID isEqualToString:fileID]) {
  166. _saveFileID = fileID;
  167. [app messageNotification:@"_upload_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  168. // remove the file
  169. [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount]];
  170. [self.delegate readFolderWithForced:YES serverUrl:self.serverUrl];
  171. }
  172. }
  173. - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  174. {
  175. [self dismissViewControllerAnimated:YES completion:nil];
  176. }
  177. @end