AddExtDocumentViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // AddExtDocumentViewController.m
  3. // Granite Expo eSign
  4. //
  5. // Created by Ray on 01/03/2017.
  6. // Copyright © 2017 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "AddExtDocumentViewController.h"
  9. #import "MenuViewController.h"
  10. #import "RAMenu.h"
  11. #import "ImageUtils.h"
  12. #import "PDFViewController.h"
  13. @interface AddExtDocumentViewController ()
  14. @end
  15. @implementation AddExtDocumentViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.edgesForExtendedLayout = UIRectEdgeNone;
  19. self.arr_documents = [[NSMutableArray alloc]init];
  20. // Do any additional setup after loading the view.
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. // Dispose of any resources that can be recreated.
  25. }
  26. - (IBAction)onScanClicked:(id)sender {
  27. }
  28. - (IBAction)onAddImageClicked:(id)sender {
  29. __weak typeof(self) weakself = self;
  30. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add Image From" message:nil preferredStyle:UIAlertControllerStyleAlert];
  31. //block代码块取代了delegate
  32. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  33. // textField.text = self.save_name;
  34. //
  35. //
  36. // }];
  37. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Album" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  38. NSUInteger sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
  39. UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
  40. imagePickerController.delegate = weakself;
  41. imagePickerController.allowsEditing = YES;
  42. imagePickerController.sourceType = sourceType;
  43. [self presentViewController:imagePickerController animated:YES completion:^{}];
  44. }];
  45. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Take a photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  46. if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
  47. {
  48. return;
  49. }
  50. NSUInteger sourceType=UIImagePickerControllerSourceTypeCamera;
  51. UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
  52. imagePickerController.delegate = weakself;
  53. imagePickerController.allowsEditing = YES;
  54. imagePickerController.sourceType = sourceType;
  55. [self presentViewController:imagePickerController animated:YES completion:^{}];
  56. }];
  57. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  58. }];
  59. [alertControl addAction:actionOne];
  60. [alertControl addAction:action2];
  61. [alertControl addAction:alertthree];
  62. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  63. [self presentViewController:alertControl animated:YES completion:nil];
  64. return;
  65. NSMutableArray* menuItem = [NSArray arrayWithObjects:@"aaa",@"bbb",nil];
  66. UIView* v= sender;
  67. RAMenu * menu= [[RAMenu alloc]initWithFrame:CGRectMake(v.frame.origin.x, v.frame.origin.y, 120, 88)];
  68. // menu.backgroundColor= [UIColor whiteColor];
  69. menu.arr_menuItems = menuItem;
  70. [self.view addSubview:menu];
  71. menu.hidden = false;
  72. return;
  73. MenuViewController *menuVC = [[MenuViewController alloc]init];
  74. menuVC.arr_menuItems = [menuItem mutableCopy];
  75. //
  76. // menuVC.title=@"menu";
  77. // signatureVC.signatureData = self.signatureData;
  78. //
  79. // signatureVC.blk_Add = ^()
  80. // {
  81. //
  82. // __block UIImage* signimg=nil;
  83. // SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
  84. //
  85. // vc.onReturnImg = ^(UIImage* img)
  86. // {
  87. //
  88. //
  89. // signimg = img;
  90. //
  91. // // if(signimg!=nil)
  92. // // [PDFUtils addSignature:signimg to:self.signatureData];
  93. //
  94. //
  95. //
  96. //
  97. // };
  98. //
  99. // // orderinfoVC.url_type = URL_REMOTE;
  100. // // orderinfoVC.request_url=URL_CARTDELIVERY;
  101. // //
  102. // // orderinfoVC.params = params;
  103. // //
  104. // // orderinfoVC.delegate=self;
  105. // //
  106. // // if(checked.count==count)
  107. // // {
  108. // // orderinfoVC.have_tail = true
  109. // // }
  110. //
  111. // [self.navigationController pushViewController:vc animated:true];
  112. //
  113. //
  114. //
  115. // };
  116. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:menuVC];
  117. navi.modalPresentationStyle=UIModalPresentationPopover;
  118. UIPopoverPresentationController* popPc = navi.popoverPresentationController;
  119. popPc.permittedArrowDirections = UIPopoverArrowDirectionUp;
  120. popPc.sourceView = sender;
  121. popPc.delegate = nil;
  122. [self presentViewController:navi animated:true completion:nil];
  123. }
  124. - (IBAction)onAddFileClicked:(id)sender {
  125. }
  126. - (IBAction)onUploadClicked:(id)sender {
  127. }
  128. #pragma mark - Table view data source
  129. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  130. {
  131. return 44;
  132. }
  133. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  134. {
  135. return 1;
  136. }
  137. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  138. //{
  139. // return 44;
  140. //}
  141. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  142. {
  143. return self.arr_documents.count;
  144. }
  145. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  146. {
  147. NSString *CellIdentifier = @"ADTableViewCell";
  148. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  149. if (cell == nil) {
  150. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  151. }
  152. NSDictionary * item_json = self.arr_documents[indexPath.row];
  153. NSString* type = item_json[@"type"];
  154. NSString* file_name = item_json[@"file_name"];
  155. NSString* upload_date = item_json[@"upload_date"];
  156. NSString* url = item_json[@"url"];
  157. if([type isEqualToString:@"file"])
  158. cell.imageView.image = [UIImage imageNamed:@"file_icon"];
  159. else
  160. cell.imageView.image = [UIImage imageNamed:@"picture_icon"];
  161. cell.textLabel.text = file_name;
  162. cell.detailTextLabel.text = upload_date;
  163. return cell;
  164. }
  165. #pragma mark tableview delegate
  166. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  167. {
  168. NSDictionary * item_json = self.arr_documents[indexPath.row];
  169. NSString* url = item_json[@"url"];
  170. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  171. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  172. ViewController.url = url;
  173. ViewController.canSave = false;
  174. ViewController.isLocalfile=isLocalFile;
  175. ViewController.defaultStyle = true;
  176. ViewController.hidenavi = false;
  177. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:ViewController] ;
  178. navi.modalPresentationStyle = UIModalPresentationFullScreen;//有三种状态,自己看看是哪种
  179. [self presentViewController:navi animated:YES completion:^{
  180. }];
  181. }
  182. #pragma mark - imagePicker delegate
  183. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
  184. // self.dirty = true;
  185. /*-------------------------------相机拍照--------------------------------------*/
  186. if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
  187. UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
  188. image=[ImageUtils img_compress:image kbsize:512];
  189. NSString *path = NSTemporaryDirectory();
  190. NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]];
  191. [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES];
  192. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  193. item[@"type"]=@"image";
  194. item[@"url"]= filePath;
  195. item[@"file_name"]= [filePath lastPathComponent];
  196. [self.arr_documents addObject:item];
  197. [self.tableView reloadData];
  198. [picker dismissViewControllerAnimated:YES completion:^{
  199. }];
  200. } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
  201. /**
  202. * UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES
  203. * UIImagePickerControllerOriginalImage 取得的是相册中原始图片
  204. */
  205. UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];
  206. image=[ImageUtils img_compress:image kbsize:512];
  207. NSString *path = NSTemporaryDirectory();
  208. NSString *filePath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg",[[NSUUID UUID] UUIDString]]];
  209. [UIImageJPEGRepresentation(image, 1.0) writeToFile:filePath atomically:YES];
  210. NSMutableDictionary* item = [[NSMutableDictionary alloc]init];
  211. item[@"type"]=@"image";
  212. item[@"url"]= filePath;
  213. item[@"file_name"]= [filePath lastPathComponent];
  214. [self.arr_documents addObject:item];
  215. [self.tableView reloadData];
  216. [picker dismissViewControllerAnimated:YES completion:nil];
  217. }
  218. }
  219. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
  220. [picker dismissViewControllerAnimated:YES completion:nil];
  221. // [picker presentViewController:cameraPicker animated:YES completion:nil];
  222. // DebugLog(@"%s",__FUNCTION__);
  223. }
  224. /*
  225. #pragma mark - Navigation
  226. // In a storyboard-based application, you will often want to do a little preparation before navigation
  227. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  228. // Get the new view controller using [segue destinationViewController].
  229. // Pass the selected object to the new view controller.
  230. }
  231. */
  232. @end