PictureDownloadViewController.mm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // PictureDownloadViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/16.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "PictureDownloadViewController.h"
  9. #import "PictureFileDownloadConfig.h"
  10. #import "ItemTableviewCell.h"
  11. #import "Header.h"
  12. @interface PictureDownloadViewController () <UITableViewDelegate,UITableViewDataSource,PictureDownloadDelegate>
  13. {
  14. PictureFileDownloadConfig *config;
  15. UITableView *tableV;
  16. PictureInfo *picInfo;
  17. NSString *thumbPath;
  18. NSString *picPath;
  19. float progres;
  20. }
  21. @end
  22. @implementation PictureDownloadViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self configSubView];
  26. }
  27. #pragma mark - 开始下载设备图片
  28. - (void)startDownloadPicture:(PictureInfo*)pictureInfo {
  29. picInfo = pictureInfo;
  30. if (config == nil) {
  31. config = [[PictureFileDownloadConfig alloc] init];
  32. config.delegate = self;
  33. }
  34. //下载小缩略图
  35. [config downloadSmallPicture:picInfo];
  36. //下载原图
  37. [config downloadPicture:picInfo];
  38. }
  39. #pragma mark - 缩略图下载回调
  40. - (void)thumbDownloadResult:(NSInteger)result path:(NSString*)thumbPaths {
  41. if (result < 0) {
  42. [MessageUI ShowErrorInt:(int)result];
  43. }else{
  44. [SVProgressHUD dismiss];
  45. thumbPath = thumbPaths;
  46. [tableV reloadData];
  47. }
  48. }
  49. #pragma mark -下载原图片开始回调
  50. - (void)pictureDownloadStartResult:(NSInteger)result {
  51. if (result <0) {
  52. [MessageUI ShowErrorInt:(int)result];
  53. }
  54. }
  55. #pragma mark -下载进度回调
  56. - (void)pictureDownloadProgressResult:(float)progress {
  57. progres = progress;
  58. NSIndexPath *path = [NSIndexPath indexPathForRow:2 inSection:0];
  59. NSArray *array = [NSArray arrayWithObject:path];
  60. [tableV reloadRowsAtIndexPaths:array withRowAnimation:nil];
  61. }
  62. #pragma mark -下载原图片完成回调
  63. - (void)pictureDownloadEndResultPath:(NSString*)path {
  64. progres = 1;
  65. picPath = path;
  66. [tableV reloadData];
  67. }
  68. #pragma mark - tableView代理方法
  69. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  70. if (indexPath.row == 3) {
  71. return 300;
  72. }
  73. return 60;
  74. }
  75. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  76. return 4;
  77. }
  78. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  80. if (!cell) {
  81. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  82. }
  83. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  84. cell.textLabel.numberOfLines = 0;
  85. cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  86. if (indexPath.row == 0) {
  87. cell.textLabel.text = picInfo.fileName;
  88. }else if (indexPath.row == 1) {
  89. cell.textLabel.text = [NSString stringWithFormat:@"fileSize:%ldK",picInfo.fileSize];
  90. if (thumbPath && thumbPath.length >1) {
  91. NSData *data = [NSData dataWithContentsOfFile:thumbPath];
  92. cell.imageView.image = [UIImage imageWithData:data];
  93. }
  94. }else if (indexPath.row == 2) {
  95. cell.textLabel.text = [NSString stringWithFormat:@"DownloadProgress: %04f%@",progres*100,@"%"];
  96. }else if (indexPath.row == 3) {
  97. if (picPath && picPath.length >1) {
  98. NSData *data = [NSData dataWithContentsOfFile:picPath];
  99. UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 300, 300)];
  100. imageV.image = [UIImage imageWithData:data];
  101. [cell addSubview:imageV];
  102. }
  103. }
  104. return cell;
  105. }
  106. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  107. }
  108. #pragma mark - 界面和数据初始化
  109. - (void)configSubView {
  110. self.title = TS("picture_download");
  111. [self.view addSubview:self.tableV];
  112. }
  113. - (UITableView *)tableV {
  114. if (!tableV) {
  115. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  116. tableV.delegate = self;
  117. tableV.dataSource = self;
  118. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  119. }
  120. return tableV;
  121. }
  122. - (void)didReceiveMemoryWarning {
  123. [super didReceiveMemoryWarning];
  124. // Dispose of any resources that can be recreated.
  125. }
  126. @end