UpgradeDeviceViewController.mm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // UpgradeDeviceViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/26.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "UpgradeDeviceViewController.h"
  9. #import "UpgradeConfig.h"
  10. #import "ItemTableviewCell.h"
  11. #import "Header.h"
  12. @interface UpgradeDeviceViewController () <UITableViewDelegate,UITableViewDataSource,UpgradeConfigDelegate>
  13. {
  14. UpgradeConfig *config; //设备版本升级
  15. UITableView *tableV;
  16. NSMutableArray *titleArray;
  17. }
  18. @end
  19. @implementation UpgradeDeviceViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. //初始化tableview数据
  23. [self initDataSource];
  24. [self configSubView];
  25. //获取设备版本升级信息
  26. [self upgradeCheckDevice];
  27. }
  28. - (void)viewWillDisappear:(BOOL)animated{
  29. //有加载状态、则取消加载
  30. if ([SVProgressHUD isVisible]){
  31. [SVProgressHUD dismiss];
  32. }
  33. }
  34. #pragma mark - 获取设备版本升级信息
  35. - (void)upgradeCheckDevice {
  36. [SVProgressHUD showWithStatus:TS("")];
  37. if (config == nil) {
  38. config = [[UpgradeConfig alloc] init];
  39. config.delegate = self;
  40. }
  41. //调用获取设备版本升级信息的接口
  42. [config upgradeCheckDevice];
  43. }
  44. #pragma mark - 开始升级设备
  45. -(void)saveConfig{
  46. [SVProgressHUD show];
  47. [config upgradeStartDevice];
  48. }
  49. #pragma mark 设备固件版本检查回调
  50. - (void)upgradeCheckResult:(int)result {
  51. if (result == 0 || result == 1 || result == 2) {
  52. //检查版本成功,刷新界面
  53. [tableV reloadData];
  54. [SVProgressHUD dismiss];
  55. }else{
  56. [MessageUI ShowErrorInt:(int)result];
  57. }
  58. }
  59. #pragma mark 设备固件版本升级结果回调
  60. - (void)upgradeStartDeviceResult:(int)result {
  61. if (result >0) {
  62. //成功
  63. [SVProgressHUD dismissWithSuccess:TS("Resource_Download")];
  64. }else{
  65. [MessageUI ShowErrorInt:(int)result];
  66. }
  67. }
  68. #pragma mark 设备升级进度回调
  69. -(void)upgradeProgressDeviceResult {
  70. //进度有刷新,刷新界面
  71. [tableV reloadData];
  72. }
  73. #pragma mark - tableView代理方法
  74. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  75. return titleArray.count;
  76. }
  77. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  79. if (!cell) {
  80. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  81. }
  82. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  83. NSString *title = [titleArray objectAtIndex:indexPath.row];
  84. cell.textLabel.text = title;
  85. if ([title isEqualToString:TS("device_Version")]) {
  86. cell.Labeltext.text = [config getUpgradeCheckState];
  87. }else if ([title isEqualToString:TS("upgrade_State")]) {
  88. cell.Labeltext.text =[config getUpgradeState];
  89. }else if ([title isEqualToString:TS("upgrade_progress")]) {
  90. float progress = [config getUpgradeProgress];
  91. if (progress == 0) {
  92. return cell;
  93. }
  94. cell.Labeltext.text =[NSString stringWithFormat:@"%.1f",progress] ;
  95. }else if([title isEqualToString:TS("Equipment_Update")]){
  96. }
  97. return cell;
  98. }
  99. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  100. NSString *titleStr = titleArray[indexPath.row];
  101. if ([titleStr isEqualToString:TS("Equipment_Update")]) {
  102. [SVProgressHUD show];
  103. //开始升级设备
  104. [config upgradeStartDevice];
  105. }
  106. }
  107. #pragma mark - 界面和数据初始化
  108. - (void)configSubView {
  109. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(saveConfig)];
  110. self.navigationItem.rightBarButtonItem = rightButton;
  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. #pragma mark - 界面和数据初始化
  123. - (void)initDataSource {
  124. titleArray=(NSMutableArray*)@[TS("device_Version"),TS("upgrade_State"),TS("upgrade_progress"),TS("Equipment_Update")];
  125. }
  126. - (void)didReceiveMemoryWarning {
  127. [super didReceiveMemoryWarning];
  128. // Dispose of any resources that can be recreated.
  129. }
  130. @end