AgreementViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // AgreementViewController.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 10/15/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "AgreementViewController.h"
  9. #import "CustomLabel.h"
  10. #import "CustomCheckBox.h"
  11. #import "CustomTableView.h"
  12. #import "WebBrowseViewController.h"
  13. @implementation AgreementTermTableViewCell
  14. - (void)didMoveToSuperview {
  15. [_lblTitle setUnderLine:_lblTitle.text];
  16. }
  17. @end
  18. @implementation AgreementServiceTableViewCell
  19. - (void)didMoveToSuperview {
  20. [_lblTitle setUnderLine:_lblTitle.text];
  21. }
  22. @end
  23. @implementation AgreementAllTableViewCell
  24. - (void)didMoveToSuperview {
  25. }
  26. @end
  27. @implementation AgreementGuideTableViewCell
  28. - (void)didMoveToSuperview {
  29. // [_lblGuide setUnderLine:_lblGuide.text];
  30. }
  31. @end
  32. @interface AgreementViewController () <CustomCheckBoxDelegate> {
  33. NSArray *_tableZombieValues;
  34. CustomCheckBox *_chkTerm, *_chkService, *_chkAll;
  35. BOOL _isNotFirstLoading;
  36. }
  37. @end
  38. #pragma mark - Class Definition
  39. @implementation AgreementViewController
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. // Do any additional setup after loading the view.
  43. [self initUI];
  44. [self prepareViewDidLoad];
  45. }
  46. - (void)initUI {
  47. _tableZombieValues = @[@"t0", @"t1", @"t2", @"t3"];
  48. [self initTableViewAsDefaultStyle:_tableView];
  49. }
  50. - (void)prepareViewDidLoad {
  51. }
  52. - (void)viewDidAppear:(BOOL)animated {
  53. [super viewDidAppear:animated];
  54. }
  55. #pragma mark - Main Logic
  56. #pragma mark - UITableView DataSource & Delegate
  57. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  58. return 1;
  59. }
  60. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  61. return 4;
  62. }
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. CGFloat height = 65;
  65. if (indexPath.row == 2) {
  66. height = 80;
  67. } else if (indexPath.row == 3) {
  68. height = 120;
  69. }
  70. return height;
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73. UITableViewCell *cell = nil;
  74. NSString *tzombie = _tableZombieValues[indexPath.row];
  75. if (indexPath.row == 0) {
  76. AgreementTermTableViewCell *tcell = (AgreementTermTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"TermCellIdentifier"];
  77. if (!_chkTerm) {
  78. _chkTerm = tcell.chkAgree;
  79. }
  80. tcell.chkAgree.delegate = self;
  81. tcell.chkAgree.value = tzombie;
  82. tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue];
  83. cell = tcell;
  84. } else if (indexPath.row == 1) {
  85. AgreementServiceTableViewCell *tcell = (AgreementServiceTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"ServiceCellIdentifier"];
  86. if (!_chkService) {
  87. _chkService = tcell.chkAgree;
  88. }
  89. tcell.chkAgree.delegate = self;
  90. tcell.chkAgree.value = tzombie;
  91. tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue];
  92. cell = tcell;
  93. } else if (indexPath.row == 2) {
  94. AgreementAllTableViewCell *tcell = (AgreementAllTableViewCell * )[tableView dequeueReusableCellWithIdentifier:@"AllCellIdentifier"];
  95. if (!_chkAll) {
  96. _chkAll = tcell.chkAgree;
  97. }
  98. tcell.chkAgree.delegate = self;
  99. tcell.chkAgree.value = tzombie;
  100. tcell.chkAgree.checked = [tcell.chkAgree getCheckStatusFromValue];
  101. cell = tcell;
  102. } else if (indexPath.row == 3) {//Guide
  103. AgreementGuideTableViewCell *tcell = (AgreementGuideTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"GuideCellIdentifier"];
  104. cell = tcell;
  105. }
  106. return cell;
  107. }
  108. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  109. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  110. if (indexPath.row == 2 || indexPath.row == 3) {
  111. return;
  112. }
  113. NSString *URLString = nil;
  114. if (indexPath.row == 0) {
  115. URLString = [NSString stringWithFormat:@"%@%@", kAPIServer, URL_PATH_TERMS];
  116. } else if (indexPath.row == 1) {
  117. URLString = [NSString stringWithFormat:@"%@%@", kAPIServer, URL_PATH_POLICY];
  118. }
  119. [[JDFacade facade] loadURLExternalBrowser:URLString];
  120. }
  121. #pragma mark - CustomCheckBox Delegate {
  122. - (void)didCheckBoxClicked:(id)sender {
  123. if ([sender isEqual:_chkAll]) {
  124. _chkTerm.checked = _chkService.checked = _chkAll.checked;
  125. } else {
  126. if (_chkTerm.checked && _chkService.checked) {
  127. _chkAll.checked = YES;
  128. } else {
  129. _chkAll.checked = NO;
  130. }
  131. }
  132. }
  133. #pragma mark - UI Events
  134. - (IBAction)btnNextTouched:(id)sender {
  135. if (!_chkAll.checked) {
  136. [[JDFacade facade] toast:@"모든 약관에 동의해주세요"];
  137. return;
  138. }
  139. UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SignUpViewController" storyboardName:@"SignUp"];
  140. vc.providesPresentationContextTransitionStyle = YES;
  141. vc.definesPresentationContext = YES;
  142. [vc setModalPresentationStyle:UIModalPresentationOverCurrentContext];
  143. [self presentViewController:vc animated:YES completion:nil];
  144. }
  145. - (IBAction)btnCancelTouched:(id)sender {
  146. [self dismissViewControllerAnimated:YES completion:nil];
  147. }
  148. #pragma mark - MemoryWarning
  149. - (void)viewDidDisappear:(BOOL)animated {
  150. [super viewDidDisappear:animated];
  151. for (NSString *zombie in _tableZombieValues) {
  152. [[JDFacade facade] setCheckBoxStatus:@NO object:zombie];
  153. }
  154. _tableZombieValues = nil;
  155. }
  156. - (void)didReceiveMemoryWarning
  157. {
  158. [super didReceiveMemoryWarning];
  159. // Dispose of any resources that can be recreated.
  160. }
  161. @end