123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // FKBookPreferController.m
- // FirstLink
- //
- // Created by jack on 16/5/11.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKBookPreferController.h"
- #import "FKPreferScrollView.h"
- #import "FKPreferItem.h"
- #import "FKBookPreferReform.h"
- #import "FKBookPreferRequest.h"
- @interface FKBookPreferController () <FLNetworkDelegate>
- @property (nonatomic, strong) UIButton *confirmBtn;
- @property (nonatomic, strong) FKPreferScrollView *scollView;
- @property (nonatomic, strong) UIView *bottomContainer;
- @property (nonatomic, copy) void (^preferDone)(void);
- @property (nonatomic, strong) NSArray *preferListArray;
- @end
- @implementation FKBookPreferController
- - (instancetype)initWithPreferDone:(void (^)(void))preferDone{
- if (self = [super init]) {
- self.preferDone = preferDone;
- }
- return self;
- }
- - (void)viewDidLoad{
- [super viewDidLoad];
-
- self.view.backgroundColor = UIColorFromRGB(0xffffff);
- [self.view addSubview:self.scollView];
- [self.view addSubview:self.bottomContainer];
- [self.bottomContainer addSubview:self.confirmBtn];
-
- [self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.left.right.equalTo(self.view);
- make.height.mas_equalTo(75);
- }];
-
- [self.scollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.view);
- make.bottom.equalTo(self.confirmBtn.mas_top).offset(- 20);
- }];
-
- [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.bottomContainer);
- make.size.mas_equalTo(CGSizeMake(256, 35));
- }];
-
- [self reqPreferList];
- }
- - (void)reqPreferList{
-
- [self.hudView show:YES];
- [FKBookPreferRequest reqPreferListWithIdentify:K_BOOK_PREFER_LIST_REQ delegate:self];
- }
- #pragma mark - response
- - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header {
-
- [self.hudView hide:NO];
- if (header.code.integerValue == RESPONSE_MSG_NORMAL){
- if (identify == K_BOOK_PREFER_LIST_REQ){
- self.bottomContainer.hidden = NO;
- self.preferListArray = [FKBookPreferReform parserPreferListWithDict:response];
- self.scollView.modelArray = self.preferListArray;
- }else if (identify == K_BOOK_PREFER_SAVE_REQ){
-
- [FLProgressHUDHelper showText:@"已保存设置" inView:self.view];
- WeakSelf(weakSelf);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- if (weakSelf.preferDone){
- weakSelf.preferDone();
- }
- });
- }
- }else{
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
- [self.hudView hide:NO];
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- #pragma mark - method
- - (void)changeSelect:(BOOL)select index:(NSUInteger)index{
- FKPreferItem *item = [self preferItemAtIndex:index];
- if (item){
- item.selected = select;
- }
- }
- - (FKPreferItem *)preferItemAtIndex:(NSUInteger)index{
- if (index < self.preferListArray.count){
- return self.preferListArray[index];
- }
- return nil;
- }
- #pragma mark - action
- - (void)clickConfirmBtn:(UIButton *)sender{
-
- [self.hudView show:YES];
- [FKBookPreferRequest requestCreatePreferList:self.preferListArray
- identify:K_BOOK_PREFER_SAVE_REQ
- delegate:self];
- }
- #pragma mark - property
- - (FKPreferScrollView *)scollView{
- if (_scollView == nil) {
- _scollView = [[FKPreferScrollView alloc]init];
-
- WeakSelf(weakSelf);
- _scollView.changeSelect = ^(NSUInteger index, BOOL selected){
- [weakSelf changeSelect:selected index:index];
- };
- }
- return _scollView;
- }
- - (UIButton *)confirmBtn{
- if (_confirmBtn == nil) {
- _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_confirmBtn setTitle:@"只看这些" forState:UIControlStateNormal];
- [_confirmBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
-
- [_confirmBtn addTarget:self
- action:@selector(clickConfirmBtn:)
- forControlEvents:UIControlEventTouchUpInside];
-
- _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- _confirmBtn.backgroundColor = UIColorFromRGB(0xff6362);
- _confirmBtn.layer.cornerRadius = 5.0f;
- }
- return _confirmBtn;
- }
- - (UIView *)bottomContainer{
- if (_bottomContainer == nil) {
- _bottomContainer = [[UIView alloc]init];
- _bottomContainer.backgroundColor = UIColorFromRGB(0xf8f8f8);
- _bottomContainer.hidden = YES;
- }
- return _bottomContainer;
- }
- @end
|