// // TFSignAlertView.m // TFReader // // Created by 谢腾飞 on 2020/12/17. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFSignAlertView.h" #import "TFCollectionManager.h" @interface TFSignAlertView () @property (nonatomic ,strong) UIView *bookBackView; @end @implementation TFSignAlertView - (void)createSubviews { [super createSubviews]; self.bookBackView = [[UIView alloc] init]; self.bookBackView.backgroundColor = [UIColor clearColor]; [self.alertBackView addSubview:self.bookBackView]; self.cancelTitle = TFLocalizedString(@"不用了"); self.confirmTitle = TFLocalizedString(@"全部加入书架"); WS(weakSelf) self.confirmButtonClickBlock = ^{ [weakSelf addBooks]; }; } - (void)showAlertView { if (_bookList.count == 0) { [self closeAlertView]; return; } [super showAlertView]; CGFloat bookWidth = (self.alertViewWidth - 2 * kMargin - 2 * kHalfMargin) / 3; CGFloat bookHeigh = kGeometricHeight(bookWidth, 3, 4); [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(30); }]; [self.bookBackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(kMargin); make.top.mas_equalTo(self.contentLabel.mas_bottom).with.offset(kMargin); make.width.mas_equalTo(self.alertBackView.mas_width).with.offset(- 2 * kMargin); make.height.mas_equalTo(bookHeigh + 40); }]; [self.cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(0); make.top.mas_equalTo(self.bookBackView.mas_bottom).with.offset(kMargin); make.height.mas_equalTo(self.alertViewBtnHeight); make.width.mas_equalTo(self.alertViewWidth / 2); }]; [self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0); make.top.mas_equalTo(self.bookBackView.mas_bottom).with.offset(kMargin); make.height.mas_equalTo(self.alertViewBtnHeight); make.width.mas_equalTo(self.alertViewWidth / 2); }]; } - (void)setBookList:(NSArray *)bookList { _bookList = bookList; if (kObjectIsEmpty(bookList)) return; CGFloat bookWidth = (self.alertViewWidth - (2 * kMargin) - (2 * kHalfMargin)) / 3.0; CGFloat bookHeigh = kGeometricHeight(bookWidth, 3, 4); int buttonNum = 3;//每行多少按钮 CGFloat button_W = bookWidth;//按钮宽 CGFloat space_X = kHalfMargin;//按钮间距 UIView *backView = [[UIView alloc] init]; backView.backgroundColor = [UIColor clearColor]; [self.bookBackView addSubview:backView]; [backView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self.bookBackView); }]; int max = (int)(bookList.count < 3 ? bookList.count : 3); for (int i = 0; i < max; i ++) { int loc = i % buttonNum;//列号 CGFloat button_X = (space_X + button_W) * loc; TFProductionModel *t_model = [bookList objectOrNilAtIndex:i]; // 图片 TFProductionCoverView *bookImageView = [[TFProductionCoverView alloc] initWithProductionType:t_model.productionType coverDirection:TFProductionCoverDirectionVertical]; bookImageView.userInteractionEnabled = YES; bookImageView.coverImageUrl = t_model.cover; [backView addSubview:bookImageView]; [bookImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(button_X); make.width.mas_equalTo(bookWidth); make.height.mas_equalTo(bookHeigh); if (i == max - 1) { make.right.equalTo(backView); } }]; // 书名 UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.numberOfLines = 1; titleLabel.text = [NSString stringWithFormat:@"%@\n", t_model.name]; titleLabel.backgroundColor = kWhiteColor; titleLabel.font = kFont12; titleLabel.textAlignment = NSTextAlignmentLeft; [backView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(bookImageView.mas_centerX); make.top.mas_equalTo(bookImageView.mas_bottom); make.width.mas_equalTo(bookImageView.mas_width); make.height.mas_equalTo(20); make.bottom.equalTo(backView); }]; UILabel *connerLabel = [[UILabel alloc] init]; connerLabel.font = kFont8; connerLabel.layer.cornerRadius = 4.0f; connerLabel.textAlignment = NSTextAlignmentCenter; connerLabel.textColor = kWhiteColor; connerLabel.clipsToBounds = YES; [bookImageView addSubview:connerLabel]; [connerLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(bookImageView.mas_right).with.offset(- kQuarterMargin); make.top.mas_equalTo(bookImageView.mas_top).with.offset(kQuarterMargin); make.width.mas_equalTo(30); make.height.mas_equalTo(15); }]; if (t_model.productionType == TFProductionTypeNovel) { connerLabel.backgroundColor = kMainColor; connerLabel.text = TFLocalizedString(@"小说"); [connerLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]); }]; } if (t_model.productionType == TFProductionTypeComic) { connerLabel.backgroundColor = kRedColor; connerLabel.text = TFLocalizedString(@"漫画"); [connerLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]); }]; } if (t_model.productionType == TFProductionTypeAudio) { connerLabel.backgroundColor = [UIColor colorWithHexString:@"#56a0ef"]; connerLabel.text = TFLocalizedString(@"听书"); [connerLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]); }]; } } } - (void)addBooks { for (TFProductionModel *t_model in self.bookList) { switch (t_model.productionType) { case TFProductionTypeNovel: [[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:t_model atIndex:0]; break; case TFProductionTypeComic: [[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:t_model]; break; case TFProductionTypeAudio: [[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:t_model]; break; default: break; } } if (self.bookList) { [[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Rack_Production object:nil]; } } @end