SKMainViewController+watch.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // SKMainViewController+watch.m
  3. // Overseas Watch
  4. //
  5. // Created by 刘振兴 on 2024/1/8.
  6. // Copyright © 2024 BaH Cy. All rights reserved.
  7. //
  8. #import "SKMainViewController+watch.h"
  9. @implementation SKMainViewController (watch)
  10. - (void)initStep {
  11. [self.mSteps setText:NSLocalizedString(@"Main.Step", nil)];
  12. }
  13. - (void)refreshStep {
  14. NSInteger count = [DataManager shared].mSelectChildModel.stepCount;
  15. NSString* s = count > 0 ? [NSString stringWithFormat:@"%ld", count] : @"-";
  16. [self.mStepsCount setText:s];
  17. }
  18. - (void)initWeather {
  19. [EUtil setViewShadow:self.mWeatherWhiteView color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:3];
  20. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  21. effectView.frame = self.mWeatherWhiteView.frame;
  22. [effectView.layer setMasksToBounds:YES];
  23. [effectView.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
  24. [self.mWeatherWhiteView addSubview:effectView];
  25. [EUtil setViewShadow:self.mWeatherChangeWhiteView color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:3];
  26. UIVisualEffectView *effectView2 = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  27. effectView2.frame = self.mWeatherChangeWhiteView.frame;
  28. [effectView2.layer setMasksToBounds:YES];
  29. [effectView2.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
  30. [self.mWeatherChangeWhiteView addSubview:effectView2];
  31. }
  32. - (void)initWatchInfo {
  33. [self.mWatchInfoView.layer setMasksToBounds:NO];
  34. [self.mWatchInfoView.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
  35. [EUtil setViewShadow:self.mWatchInfoView color:[UIColor colorWithRed:0/255.0f green:1/255.0f blue:75/255.0f alpha:0.2] offset:CGSizeMake(0, 2) opacity:1 radius:3];
  36. [self.mWatchInfoEffectView.layer setMasksToBounds:YES];
  37. [self.mWatchInfoEffectView.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
  38. self.mWatchInfoEffectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  39. }
  40. - (void)refreshWeather {
  41. BaseWeatherModel* model = [DataManager shared].mSelectChildModel.weather;
  42. if (!model || model.textCode.length <= 0) {
  43. [self.mWeatherView setHidden:YES];
  44. return;
  45. }
  46. //有天气数据
  47. [self.mWeatherView setHidden:NO];
  48. //空气质量
  49. NSInteger _airDegrees = model.air;
  50. NSInteger _airState = 0;
  51. if (_airDegrees <= 50)
  52. _airState = 1;
  53. else if (_airDegrees > 50 && _airDegrees <= 100)
  54. _airState = 2;
  55. else if (_airDegrees > 100 && _airDegrees <= 150)
  56. _airState = 3;
  57. else if (_airDegrees > 150 && _airDegrees <= 200)
  58. _airState = 4;
  59. else if (_airDegrees > 200 && _airDegrees <= 300)
  60. _airState = 5;
  61. else
  62. _airState = 6;
  63. NSInteger type = [model.textCode integerValue];
  64. NSString* imageName = [NSString stringWithFormat:@"%@%ld", @"weather_type_", type];
  65. [self.mWeatherState setImage:[UIImage imageNamed:imageName]];
  66. //0:代表摄氏 1代表华氏
  67. NSInteger temperature = model.now;
  68. NSNumber* weatherType = [EUtil getUserDefaults:@"KEY_TYPE_WEATHER"];
  69. if ([weatherType intValue] == 1){
  70. temperature = temperature*9/5 + 32;
  71. }
  72. if (type <= 0) {
  73. [self.mWeatherDegrees setText:@"N/A"];
  74. } else {
  75. [self.mWeatherDegrees setText:[NSString stringWithFormat:@"%ld", (long)temperature]];
  76. }
  77. UIColor* normal = [UIColor colorWithRed:0/255.0f green:1/255.0f blue:0/255.0f alpha:0.4];
  78. UIColor* high = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1];
  79. [self.mWeatherChangeDegreesC setTextColor:[weatherType intValue] == 0? high:normal];
  80. [self.mWeatherChangeDegreesF setTextColor:[weatherType intValue] == 1? high:normal];
  81. [self.mAirState setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@%ld", @"weather_aqi_", (long)_airState]]];
  82. [self.mAirDegrees setText:[NSString stringWithFormat:@"%@%ld", NSLocalizedString(@"Main.Weather.Air", nil), (long)_airDegrees]];
  83. }
  84. - (void)refreshSignals {
  85. NSString* imageName = @"";
  86. DeviceModel* model = [[DataManager shared] getSelectDevice];
  87. if (model.startup == 0 || model.battery <= 0) {
  88. imageName = [NSString stringWithFormat:@"ic_signal_%d", 0];
  89. } else {
  90. if (model.signalMax >= 5) {
  91. imageName = [NSString stringWithFormat:@"ic_signal_%ld", model.signal];
  92. } else {
  93. imageName = [NSString stringWithFormat:@"ic_signal_%ld", model.signal];
  94. }
  95. }
  96. [self.mSignalsImage setImage:[UIImage imageNamed:imageName]];
  97. }
  98. - (void)refreshSignalsEx {
  99. NSString* imageName = @"";
  100. DeviceModel* model = [[DataManager shared] getSelectDevice];
  101. if (model.signal < -197 || model.battery <= 0 || model.startup == 0) {
  102. imageName = @"ic_signal_0";
  103. } else if ( model.signal > - 197 && model.signal < -103) {
  104. imageName = @"ic_signal_1";
  105. } else if(model.signal >= -103 && model.signal < -97){
  106. imageName = @"ic_signal_2";
  107. } else if(model.signal >= -97 && model.signal < -89){
  108. imageName = @"ic_signal_3";
  109. } else if(model.signal >= -89){
  110. imageName = @"ic_signal_4";
  111. }
  112. [self.mSignalsImage setImage:[UIImage imageNamed:imageName]];
  113. }
  114. - (void)refreshBattery {
  115. DeviceModel* model = [[DataManager shared] getSelectDevice];
  116. NSInteger battery = model.battery;
  117. CGSize percentageSize = self.mBatteryImage.frame.size;
  118. UIImage *image;
  119. if(battery <= 0 || model.startup == 0) {
  120. image = [EUtil imageWithColorPercent:[UIColor clearColor] colorPercent:0 andSize:percentageSize];
  121. } else if(battery <= 25) {
  122. UIColor *color = [UIColor colorWithRed:253/255.0 green:26/255.0 blue:119/255.0 alpha:1.0f];
  123. image = [EUtil imageWithColorPercent:color colorPercent:battery/100.0 andSize:percentageSize];
  124. } else {
  125. if(battery > 100)
  126. battery = 100;
  127. UIColor *color = [UIColor colorWithRed:44/255.0 green:221/255.0 blue:103/255.0 alpha:1.0f];
  128. image = [EUtil imageWithColorPercent:color colorPercent:battery/100.0 andSize:percentageSize];
  129. }
  130. [self.mBatteryImage setImage:image];
  131. }
  132. - (IBAction)onWeatherChangeAction:(id)sender {
  133. NSNumber* number = [EUtil getUserDefaults:@"KEY_TYPE_WEATHER"];
  134. if (number) {
  135. //0:代表摄氏 1代表华氏
  136. [EUtil setUserDefaults:@"KEY_TYPE_WEATHER" number:[number intValue] == 0 ? @(1):@(0)];
  137. }
  138. [self refreshWeather];
  139. }
  140. @end