YMAdolescentModelViewController.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // YMAdolescentModelTipsViewController.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/22.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAdolescentModelViewController.h"
  9. #import "YMAdolescentModelViewModel.h"
  10. #import "YMAdolescentModelTipsView.h"
  11. #import "YMAdolescentModelPasswordView.h"
  12. @interface YMAdolescentModelViewController ()
  13. /// 青少年模式提示VM
  14. @property (nonatomic, strong) YMAdolescentModelViewModel *viewModel;
  15. /// 容器滚动视图
  16. @property (nonatomic, strong) UIScrollView *contentScrollView;
  17. /// 容器视图
  18. @property (nonatomic, strong) UIView *contentView;
  19. /// 青少年模式提示视图
  20. @property (nonatomic, strong) YMAdolescentModelTipsView *adolescentModelTipsView;
  21. /// 青少年模式密码视图
  22. @property (nonatomic, strong) YMAdolescentModelPasswordView *adolescentModelPasswordView;
  23. /// 青少年模式操作按钮
  24. @property (nonatomic, strong) UIButton *adolescentModelOperationBtn;
  25. @end
  26. @implementation YMAdolescentModelViewController
  27. @dynamic viewModel;
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated{
  32. [super viewWillAppear:animated];
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated{
  35. [super viewWillDisappear:animated];
  36. }
  37. - (void)ym_setupViews{
  38. [self.view addSubview:self.contentScrollView];
  39. [self.contentScrollView addSubview:self.contentView];
  40. switch (self.viewModel.adolescentModelType) {
  41. case YMAdolescentModelTypeTips:
  42. {
  43. [self.contentView addSubview:self.adolescentModelTipsView];
  44. }
  45. break;
  46. case YMAdolescentModelTypeSettingPassword:
  47. case YMAdolescentModelTypeConfirmPassword:
  48. case YMAdolescentModelTypeClosePassword:
  49. {
  50. [self.contentView addSubview:self.adolescentModelPasswordView];
  51. }
  52. break;
  53. default:
  54. break;
  55. }
  56. [self.view addSubview:self.adolescentModelOperationBtn];
  57. [self.view setNeedsUpdateConstraints];
  58. [self.view updateConstraintsIfNeeded];
  59. }
  60. - (void)updateViewConstraints{
  61. [self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.top.equalTo(self.view).offset(kYMNavHeight);
  63. make.left.equalTo(self.view);
  64. make.right.equalTo(self.view);
  65. }];
  66. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.edges.equalTo(self.contentScrollView);
  68. make.width.equalTo(self.contentScrollView.mas_width);
  69. }];
  70. switch (self.viewModel.adolescentModelType) {
  71. case YMAdolescentModelTypeTips:
  72. {
  73. [self.adolescentModelTipsView mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(self.contentView);
  75. make.left.equalTo(self.contentView);
  76. make.right.equalTo(self.contentView);
  77. make.bottom.equalTo(self.contentView);
  78. }];
  79. }
  80. break;
  81. case YMAdolescentModelTypeSettingPassword:
  82. case YMAdolescentModelTypeConfirmPassword:
  83. case YMAdolescentModelTypeClosePassword:
  84. {
  85. [self.adolescentModelPasswordView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.equalTo(self.contentView);
  87. make.left.equalTo(self.contentView);
  88. make.right.equalTo(self.contentView);
  89. make.bottom.equalTo(self.contentView);
  90. }];
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96. [self.adolescentModelOperationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.equalTo(self.contentScrollView.mas_bottom).offset(adapt(10));
  98. make.left.equalTo(self.view).offset(adapt(30));
  99. make.right.equalTo(self.view).offset(adapt(-30));
  100. make.bottom.equalTo(self.view).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
  101. make.height.mas_equalTo(adapt(50));
  102. }];
  103. [super updateViewConstraints];
  104. }
  105. - (void)ym_bindViewModel{
  106. [self.adolescentModelTipsView ym_bindViewModel:self.viewModel];
  107. [self.adolescentModelPasswordView ym_bindViewModel:self.viewModel];
  108. @weakify(self)
  109. [[[[RACObserve(self.viewModel, adolescentModelOperationText) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * adolescentModelOperationText) {
  110. @strongify(self)
  111. [self.adolescentModelOperationBtn setTitle:adolescentModelOperationText forState:UIControlStateNormal];
  112. }];
  113. }
  114. - (UIScrollView *)contentScrollView{
  115. if (!_contentScrollView) {
  116. _contentScrollView = [[UIScrollView alloc]init];
  117. _contentScrollView.alwaysBounceVertical = YES;
  118. _contentScrollView.showsVerticalScrollIndicator = NO;
  119. _contentScrollView.showsHorizontalScrollIndicator = NO;
  120. _contentScrollView.backgroundColor = HexColorFromRGB(0xFFFFFF);
  121. _contentScrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
  122. }
  123. return _contentScrollView;
  124. }
  125. - (UIView *)contentView{
  126. if (!_contentView) {
  127. _contentView = [[UIView alloc]init];
  128. }
  129. return _contentView;
  130. }
  131. - (YMAdolescentModelTipsView *)adolescentModelTipsView{
  132. if (!_adolescentModelTipsView) {
  133. _adolescentModelTipsView = [[YMAdolescentModelTipsView alloc]init];
  134. }
  135. return _adolescentModelTipsView;
  136. }
  137. - (YMAdolescentModelPasswordView *)adolescentModelPasswordView{
  138. if (!_adolescentModelPasswordView) {
  139. _adolescentModelPasswordView = [[YMAdolescentModelPasswordView alloc]init];
  140. }
  141. return _adolescentModelPasswordView;
  142. }
  143. - (UIButton *)adolescentModelOperationBtn{
  144. if (!_adolescentModelOperationBtn) {
  145. _adolescentModelOperationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  146. _adolescentModelOperationBtn.titleLabel.font = LCFont(15);
  147. [_adolescentModelOperationBtn setTitle:@"开启青少年模式" forState:UIControlStateNormal];
  148. [_adolescentModelOperationBtn setTitleColor:MAINGRIDTitleC forState:UIControlStateNormal];
  149. [_adolescentModelOperationBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  150. _adolescentModelOperationBtn.layer.cornerRadius = adapt(8);
  151. _adolescentModelOperationBtn.layer.masksToBounds = YES;
  152. WS(weakSelf)
  153. [[[_adolescentModelOperationBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
  154. switch (weakSelf.viewModel.adolescentModelType) {
  155. case YMAdolescentModelTypeTips:
  156. {
  157. YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
  158. ParamsCategoryType:@(YMAdolescentModelTypeSettingPassword)
  159. }];
  160. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
  161. RouterViewModel:adolescentModelVM
  162. } completion:nil];
  163. }
  164. break;
  165. case YMAdolescentModelTypeSettingPassword:
  166. {
  167. if (weakSelf.viewModel.adolescentModelSettingPassword.length <= 3) {
  168. [ZCHUDHelper showTitle:@"请设置4位数密码"];
  169. return;
  170. }
  171. YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
  172. ParamsCategoryType:@(YMAdolescentModelTypeConfirmPassword),
  173. @"settingPassword":weakSelf.viewModel.adolescentModelSettingPassword
  174. }];
  175. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
  176. RouterViewModel:adolescentModelVM
  177. } completion:nil];
  178. }
  179. break;
  180. case YMAdolescentModelTypeConfirmPassword:
  181. {
  182. if (![weakSelf.viewModel.adolescentModelSettingPassword isEqualToString:weakSelf.viewModel.adolescentModelConfirmPassword]) {
  183. [ZCHUDHelper showTitle:@"密码不正确"];
  184. return;
  185. }
  186. [weakSelf.viewModel openAdolescentModel];
  187. }
  188. break;
  189. case YMAdolescentModelTypeClosePassword:
  190. {
  191. if (OCStringIsEmpty(weakSelf.viewModel.adolescentModelConfirmPassword)) {
  192. [ZCHUDHelper showTitle:@"密码不正确"];
  193. return;
  194. }
  195. [self.viewModel closeAdolescentModel];
  196. }
  197. break;
  198. default:
  199. break;
  200. }
  201. }];
  202. }
  203. return _adolescentModelOperationBtn;
  204. }
  205. @end