ShutDownTimeViewController.mm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // ShutDownTimeViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2019/3/18.
  6. // Copyright © 2019年 XM. All rights reserved.
  7. //
  8. #import "ShutDownTimeConfig.h"
  9. #import "ShutDownTimeViewController.h"
  10. #import "ItemTableviewCell.h"
  11. #import "Header.h"
  12. @interface ShutDownTimeViewController ()<ShutDownTimeConfigDelegate,UITableViewDelegate,UITableViewDataSource>{
  13. ShutDownTimeConfig *config;
  14. }
  15. @property (nonatomic, strong) UITableView *myTableView;
  16. @property (nonatomic, assign) int shutDownTime;
  17. @end
  18. @implementation ShutDownTimeViewController
  19. #pragma mark -- LazyLoad
  20. -(UITableView *)myTableView{
  21. if (!_myTableView) {
  22. _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
  23. _myTableView.delegate = self;
  24. _myTableView.dataSource = self;
  25. _myTableView.backgroundColor = [UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:1];
  26. [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"myCell"];
  27. _myTableView.tableFooterView = [UIView new];
  28. }
  29. return _myTableView;
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. [self initData];
  34. [self configSubViews];
  35. [self getBuzzerConfig];
  36. }
  37. #pragma mark -- alarmBellState default NO
  38. -(void)initData{
  39. }
  40. -(void)configSubViews{
  41. [self.view addSubview:self.myTableView];
  42. }
  43. #pragma mark --getConfigAboutDeviceBuzzerState
  44. -(void)getBuzzerConfig{
  45. [SVProgressHUD showWithStatus:TS("")];
  46. if (config == nil) {
  47. config = [[ShutDownTimeConfig alloc] init];
  48. config.delegate = self;
  49. }
  50. [config getShutDownTime];
  51. }
  52. #pragma mark --getConfigAboutDeviceBuzzerStateResult
  53. -(void)getShutDownTimeConfigResult:(int)result {
  54. if (result <0) {
  55. [MessageUI ShowErrorInt:result];
  56. }
  57. [SVProgressHUD dismiss];
  58. self.shutDownTime = config.time;
  59. [self.myTableView reloadData];
  60. }
  61. #pragma mark --setConfigAboutDeviceBuzzerStateResult
  62. - (void)setShutDownTimeConfigResult:(int)result{
  63. if (result <0) {
  64. [MessageUI ShowErrorInt:result];
  65. }else{
  66. [SVProgressHUD showSuccessWithStatus:TS("config_Save_Success") duration:1.5f];
  67. }
  68. }
  69. #pragma mark -- UITableViewDelegate/DataSource
  70. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  71. return 1;
  72. }
  73. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  74. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  75. if (!cell) {
  76. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  77. }
  78. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  79. cell.textLabel.text = TS("Sleep_time");
  80. if (self.shutDownTime >0) {
  81. cell.Labeltext.text = [NSString stringWithFormat:@"%dS",self.shutDownTime];
  82. }
  83. return cell;
  84. }
  85. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  86. ItemTableviewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  87. if (cell.textLabel.text != nil && cell.textLabel.text.length >0) {
  88. UIAlertController *alert = [UIAlertController alertControllerWithTitle:TS("Set_sleep_time") message:nil preferredStyle:UIAlertControllerStyleAlert];
  89. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:TS("Cancel") style:UIAlertActionStyleCancel handler:nil];
  90. UIAlertAction *comfirmAction = [UIAlertAction actionWithTitle:TS("OK") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  91. //设置时长
  92. [SVProgressHUD show];
  93. int time = 15;
  94. //读取设置的时长并做一些防止输入异常的操作
  95. NSString *timeStr = [alert.textFields firstObject].text;
  96. if (timeStr != nil && timeStr.length >0) {
  97. time = [timeStr intValue];
  98. }
  99. if (time <=0) {
  100. time = 15;
  101. }
  102. [config setSutDownTime:time];
  103. self.shutDownTime = time;
  104. [self.myTableView reloadData];
  105. }];
  106. [alert addTextFieldWithConfigurationHandler:nil];
  107. [alert addAction:cancelAction];
  108. [alert addAction:comfirmAction];
  109. [self presentViewController:alert animated:YES completion:nil];
  110. }
  111. }
  112. @end