CloudPhotoDownloadViewController.mm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // CloudPhotoDownloadViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2019/1/4.
  6. // Copyright © 2019年 XM. All rights reserved.
  7. //
  8. #import "CloudPhotoDownloadViewController.h"
  9. #import "ItemTableviewCell.h"
  10. #import "Header.h"
  11. @interface CloudPhotoDownloadViewController ()
  12. <UITableViewDelegate,UITableViewDataSource,CloudPhotoConfigDelegate>
  13. {
  14. CloudPhotoConfig *config;
  15. XMAlarmMsgResource *resource;
  16. UITableView *tableV;
  17. NSString *thumbPath;
  18. NSString *picPath;
  19. float progres;
  20. }
  21. @end
  22. @implementation CloudPhotoDownloadViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self configSubView];
  26. }
  27. #pragma mark - 开始下载设备图片
  28. - (void)startDownloadCloudPicture:(XMAlarmMsgResource*)msgResource {
  29. resource = msgResource;
  30. if (config == nil) {
  31. config = [[CloudPhotoConfig alloc] init];
  32. config.delegate = self;
  33. }
  34. //下载小缩略图
  35. [config downloadSmallCloudPicture:resource];
  36. //下载原图
  37. [config downloadCloudPicture:resource];
  38. }
  39. #pragma mark -下载图片结果回调
  40. // 下载云存储缩略图
  41. - (void)downloadSmallCloudPictureResult:(int)result path:(NSString*)path {
  42. if (result < 0) {
  43. [MessageUI ShowErrorInt:(int)result];
  44. }else{
  45. [SVProgressHUD dismiss];
  46. thumbPath = path;
  47. [tableV reloadData];
  48. }
  49. }
  50. #pragma mark - 下载云存储原图回调 云存储下载图片没有进度信息回调,只有结果(速度比设备端下载块)
  51. - (void)downloadCloudPictureResult:(int)result path:(NSString*)path {
  52. picPath = path;
  53. [tableV reloadData];
  54. }
  55. #pragma mark - tableView代理方法
  56. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  57. if (indexPath.row == 3) {
  58. return 300;
  59. }
  60. return 60;
  61. }
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  63. return 4;
  64. }
  65. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  67. if (!cell) {
  68. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  69. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  70. }
  71. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  72. cell.textLabel.numberOfLines = 0;
  73. cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
  74. if (indexPath.row == 0) {
  75. //云图片日期时间
  76. cell.textLabel.text = resource.startTime;
  77. }else if (indexPath.row == 1) {
  78. //云图片缩略图和大小
  79. cell.textLabel.text = [NSString stringWithFormat:@"fileSize:%dK",resource.size];
  80. if (thumbPath && thumbPath.length >1) {
  81. NSData *data = [NSData dataWithContentsOfFile:thumbPath];
  82. cell.imageView.image = [UIImage imageWithData:data];
  83. }
  84. }else if (indexPath.row == 2) {
  85. //云视频原图下载进度
  86. cell.textLabel.text = [NSString stringWithFormat:@"DownloadProgress: %04f%@",progres*100,@"%"];
  87. }else if (indexPath.row == 3) {
  88. //云视频原图显示
  89. if (picPath && picPath.length >1) {
  90. NSData *data = [NSData dataWithContentsOfFile:picPath];
  91. UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 300, 300)];
  92. imageV.image = [UIImage imageWithData:data];
  93. [cell addSubview:imageV];
  94. }
  95. }
  96. return cell;
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  99. }
  100. #pragma mark - 界面和数据初始化
  101. - (void)configSubView {
  102. self.title = TS("picture_download");
  103. [self.view addSubview:self.tableV];
  104. }
  105. - (UITableView *)tableV {
  106. if (!tableV) {
  107. tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  108. tableV.delegate = self;
  109. tableV.dataSource = self;
  110. [tableV registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  111. }
  112. return tableV;
  113. }
  114. - (void)didReceiveMemoryWarning {
  115. [super didReceiveMemoryWarning];
  116. // Dispose of any resources that can be recreated.
  117. }
  118. @end