Ei kuvausta

FKBookPreferController.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // FKBookPreferController.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/5/11.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBookPreferController.h"
  9. #import "FKPreferScrollView.h"
  10. #import "FKPreferItem.h"
  11. #import "FKBookPreferReform.h"
  12. #import "FKBookPreferRequest.h"
  13. @interface FKBookPreferController () <FLNetworkDelegate>
  14. @property (nonatomic, strong) UIButton *confirmBtn;
  15. @property (nonatomic, strong) FKPreferScrollView *scollView;
  16. @property (nonatomic, strong) UIView *bottomContainer;
  17. @property (nonatomic, copy) void (^preferDone)(void);
  18. @property (nonatomic, strong) NSArray *preferListArray;
  19. @end
  20. @implementation FKBookPreferController
  21. - (instancetype)initWithPreferDone:(void (^)(void))preferDone{
  22. if (self = [super init]) {
  23. self.preferDone = preferDone;
  24. }
  25. return self;
  26. }
  27. - (void)viewDidLoad{
  28. [super viewDidLoad];
  29. self.view.backgroundColor = UIColorFromRGB(0xffffff);
  30. [self.view addSubview:self.scollView];
  31. [self.view addSubview:self.bottomContainer];
  32. [self.bottomContainer addSubview:self.confirmBtn];
  33. [self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.bottom.left.right.equalTo(self.view);
  35. make.height.mas_equalTo(75);
  36. }];
  37. [self.scollView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.top.left.right.equalTo(self.view);
  39. make.bottom.equalTo(self.confirmBtn.mas_top).offset(- 20);
  40. }];
  41. [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.center.equalTo(self.bottomContainer);
  43. make.size.mas_equalTo(CGSizeMake(256, 35));
  44. }];
  45. [self reqPreferList];
  46. }
  47. - (void)reqPreferList{
  48. [self.hudView show:YES];
  49. [FKBookPreferRequest reqPreferListWithIdentify:K_BOOK_PREFER_LIST_REQ delegate:self];
  50. }
  51. #pragma mark - response
  52. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header {
  53. [self.hudView hide:NO];
  54. if (header.code.integerValue == RESPONSE_MSG_NORMAL){
  55. if (identify == K_BOOK_PREFER_LIST_REQ){
  56. self.bottomContainer.hidden = NO;
  57. self.preferListArray = [FKBookPreferReform parserPreferListWithDict:response];
  58. self.scollView.modelArray = self.preferListArray;
  59. }else if (identify == K_BOOK_PREFER_SAVE_REQ){
  60. [FLProgressHUDHelper showText:@"已保存设置" inView:self.view];
  61. WeakSelf(weakSelf);
  62. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  63. if (weakSelf.preferDone){
  64. weakSelf.preferDone();
  65. }
  66. });
  67. }
  68. }else{
  69. [FLProgressHUDHelper showText:header.msg inView:self.view];
  70. }
  71. }
  72. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  73. [self.hudView hide:NO];
  74. [FLProgressHUDHelper showText:header.msg inView:self.view];
  75. }
  76. #pragma mark - method
  77. - (void)changeSelect:(BOOL)select index:(NSUInteger)index{
  78. FKPreferItem *item = [self preferItemAtIndex:index];
  79. if (item){
  80. item.selected = select;
  81. }
  82. }
  83. - (FKPreferItem *)preferItemAtIndex:(NSUInteger)index{
  84. if (index < self.preferListArray.count){
  85. return self.preferListArray[index];
  86. }
  87. return nil;
  88. }
  89. #pragma mark - action
  90. - (void)clickConfirmBtn:(UIButton *)sender{
  91. [self.hudView show:YES];
  92. [FKBookPreferRequest requestCreatePreferList:self.preferListArray
  93. identify:K_BOOK_PREFER_SAVE_REQ
  94. delegate:self];
  95. }
  96. #pragma mark - property
  97. - (FKPreferScrollView *)scollView{
  98. if (_scollView == nil) {
  99. _scollView = [[FKPreferScrollView alloc]init];
  100. WeakSelf(weakSelf);
  101. _scollView.changeSelect = ^(NSUInteger index, BOOL selected){
  102. [weakSelf changeSelect:selected index:index];
  103. };
  104. }
  105. return _scollView;
  106. }
  107. - (UIButton *)confirmBtn{
  108. if (_confirmBtn == nil) {
  109. _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  110. [_confirmBtn setTitle:@"只看这些" forState:UIControlStateNormal];
  111. [_confirmBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  112. [_confirmBtn addTarget:self
  113. action:@selector(clickConfirmBtn:)
  114. forControlEvents:UIControlEventTouchUpInside];
  115. _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  116. _confirmBtn.backgroundColor = UIColorFromRGB(0xff6362);
  117. _confirmBtn.layer.cornerRadius = 5.0f;
  118. }
  119. return _confirmBtn;
  120. }
  121. - (UIView *)bottomContainer{
  122. if (_bottomContainer == nil) {
  123. _bottomContainer = [[UIView alloc]init];
  124. _bottomContainer.backgroundColor = UIColorFromRGB(0xf8f8f8);
  125. _bottomContainer.hidden = YES;
  126. }
  127. return _bottomContainer;
  128. }
  129. @end