XYAboutViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // XYAboutViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/15.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYAboutViewController.h"
  9. #import "XYAboutViewModel.h"
  10. #import "XYDevelopmentModeViewController.h"
  11. @interface XYAboutViewController ()
  12. @property (nonatomic, strong) XYAboutViewModel *viewModel;
  13. @property (nonatomic, readwrite, strong) UIImageView *logoImageView;
  14. @property (nonatomic, readwrite, strong) UILabel *appNameLabel;
  15. @property (nonatomic, readwrite, strong) UILabel *versionLabel;
  16. @property (nonatomic, readwrite, strong) UILabel *channelLabel;
  17. @property (nonatomic, readwrite, strong) UILabel *introduceLabel;
  18. @property (nonatomic, assign) NSInteger tapIndex;
  19. @end
  20. @implementation XYAboutViewController
  21. /// 重写init方法,配置你想要的属性
  22. - (instancetype)init
  23. {
  24. self = [super init];
  25. if (self) {
  26. }
  27. return self;
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. /// 设置
  32. [self _setup];
  33. /// 设置导航栏
  34. [self _setupNavigationItem];
  35. /// 设置子控件
  36. [self _setupSubViews];
  37. /// 布局子空间
  38. [self _makeSubViewsConstraints];
  39. }
  40. #pragma mark — Override
  41. - (void)bindViewModel {
  42. self.viewModel = XYAboutViewModel.new;
  43. }
  44. - (UIEdgeInsets)contentInset {
  45. return UIEdgeInsetsMake(NAVGATION_HEIGHT + 250.0f, 0, 0, 0);
  46. }
  47. - (void)requestRemoteData {
  48. [self.viewModel loadData:^(id _Nullable responseModel) {
  49. [self reloadData];
  50. } failure:^(ZYLNetworkError * _Nullable error) {
  51. }];
  52. }
  53. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  54. return [EmptyTableViewCell cellWithTableView:tableView];
  55. }
  56. - (void)configureCell:(EmptyTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  57. [cell configureModel:object];
  58. }
  59. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. EmptyCellModel *model = self.viewModel.dataSource[indexPath.row];
  61. return model.cellHeight;
  62. }
  63. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  64. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  65. EmptyCellModel *model = self.viewModel.dataSource[indexPath.row];
  66. if ([model.title isEqualToString:@"软件更新"]) {
  67. [ApplicationDelegate checkVersionUpdates:YES];
  68. }else if ([model.title isEqualToString:@"开发模式"]) {
  69. [self.navigationController pushViewController:XYDevelopmentModeViewController.new animated:YES];
  70. }
  71. }
  72. #pragma mark - 事件处理Or辅助方法
  73. - (void)logoImageTapAction:(id)sender {
  74. _tapIndex++;
  75. if (_tapIndex == 5) {
  76. _tapIndex = 0;
  77. self.viewModel.developmentMode = YES;
  78. [self requestRemoteData];
  79. }
  80. }
  81. #pragma mark - 初始化
  82. - (void)_setup{
  83. self.title = kLocalizedString(@"关于我们");
  84. self.view.backgroundColor = Color_White;
  85. self.tableView.scrollEnabled = NO;
  86. }
  87. #pragma mark - 设置导航栏
  88. - (void)_setupNavigationItem{
  89. }
  90. #pragma mark - 设置子控件
  91. - (void)_setupSubViews{
  92. [self.view addSubview:self.logoImageView];
  93. [self.view addSubview:self.appNameLabel];
  94. [self.view addSubview:self.versionLabel];
  95. [self.view addSubview:self.channelLabel];
  96. [self.view addSubview:self.introduceLabel];
  97. self.logoImageView.image = ImageNamed(@"icon_logo_114");
  98. self.appNameLabel.text = APP_NAME;
  99. self.versionLabel.text = [NSString stringWithFormat:@"v%@_%@", APP_VERSION, APP_BUILD];
  100. self.channelLabel.text = [NSString stringWithFormat:@"c%@", APP_Channel_Id];
  101. self.introduceLabel.text = APP_Introduce;
  102. }
  103. #pragma mark - 布局子控件
  104. - (void)_makeSubViewsConstraints{
  105. [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.top.equalTo(self.view).offset(NAVGATION_HEIGHT + 32.0f);
  107. make.centerX.equalTo(self.view);
  108. make.width.height.equalTo(@80.0f);
  109. }];
  110. [self.appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.left.equalTo(self.view).offset(SPACING_EDGE);
  112. make.right.equalTo(self.view).offset(-SPACING_EDGE);
  113. make.top.equalTo(self.logoImageView.mas_bottom).offset(14.0f);
  114. make.height.equalTo(@25.0f);
  115. }];
  116. [self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.left.equalTo(self.view).offset(SPACING_EDGE);
  118. make.right.equalTo(self.view).offset(-SPACING_EDGE);
  119. make.top.equalTo(self.appNameLabel.mas_bottom).offset(10.0f);
  120. make.height.equalTo(@20.0f);
  121. }];
  122. [self.channelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.equalTo(self.view).offset(SPACING_EDGE);
  124. make.right.equalTo(self.view).offset(-SPACING_EDGE);
  125. make.top.equalTo(self.versionLabel.mas_bottom).offset(0.0f);
  126. make.height.equalTo(@20.0f);
  127. }];
  128. [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.equalTo(self.view).offset(SPACING_EDGE);
  130. make.right.equalTo(self.view).offset(-SPACING_EDGE);
  131. make.top.equalTo(self.channelLabel.mas_bottom).offset(20.0f);
  132. make.bottom.lessThanOrEqualTo(self.view).offset(-20.0f);
  133. }];
  134. [self.logoImageView addViewBorder:Color_Clear redian:5];
  135. }
  136. #pragma mark - Setter & Getter
  137. - (UIImageView *)logoImageView {
  138. if (!_logoImageView) {
  139. _logoImageView = [UIImageView new];
  140. _logoImageView.userInteractionEnabled = YES;
  141. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logoImageTapAction: )];
  142. [_logoImageView addGestureRecognizer:tap];
  143. }
  144. return _logoImageView;
  145. }
  146. - (UILabel *)appNameLabel {
  147. if (!_appNameLabel) {
  148. _appNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(18)];
  149. _appNameLabel.textAlignment = NSTextAlignmentCenter;
  150. }
  151. return _appNameLabel;
  152. }
  153. - (UILabel *)versionLabel {
  154. if (!_versionLabel) {
  155. _versionLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(15)];
  156. _versionLabel.textAlignment = NSTextAlignmentCenter;
  157. }
  158. return _versionLabel;
  159. }
  160. - (UILabel *)channelLabel {
  161. if (!_channelLabel) {
  162. _channelLabel = [UILabel createLabelTextColor:Color_LightGray fount:Font_B(15)];
  163. _channelLabel.textAlignment = NSTextAlignmentCenter;
  164. }
  165. return _channelLabel;
  166. }
  167. - (UILabel *)introduceLabel {
  168. if (!_introduceLabel) {
  169. _introduceLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(14)];
  170. _introduceLabel.numberOfLines = 0;
  171. }
  172. return _introduceLabel;
  173. }
  174. @end