小说绘上架版本
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// WXYZ_GiftMonthlyPassModel.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class WXYZ_GiftMonthlyPassInfoModel, WXYZ_GiftMonthlyPassListModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_GiftMonthlyPassModel : NSObject
|
||||
|
||||
/// 月票信息
|
||||
@property (nonatomic, strong) WXYZ_GiftMonthlyPassInfoModel *info;
|
||||
|
||||
/// 月票列表
|
||||
@property (nonatomic, strong) NSArray<WXYZ_GiftMonthlyPassListModel *> *list;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_GiftMonthlyPassInfoModel : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger book_id;
|
||||
|
||||
/// 作品名称
|
||||
@property (nonatomic, copy) NSString *name;
|
||||
|
||||
@property (nonatomic, copy) NSString *cover;
|
||||
|
||||
/// 本月获得月票数量
|
||||
@property (nonatomic, copy) NSString *stickerNumber;
|
||||
|
||||
/// 排名
|
||||
@property (nonatomic, copy) NSString *ranking;
|
||||
|
||||
/// 和上一名排行的距离
|
||||
@property (nonatomic, copy) NSString *last_distance;
|
||||
|
||||
/// 剩余的月票
|
||||
@property (nonatomic, copy) NSString *ticket_remain;
|
||||
|
||||
/// 月票规则
|
||||
@property (nonatomic, copy) NSString *ticket_rule;
|
||||
|
||||
/// 是否可投
|
||||
@property (nonatomic, assign) NSInteger can_vote;
|
||||
|
||||
/// 投票说明
|
||||
@property (nonatomic, copy) NSString *monthly_tips;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_GiftMonthlyPassListModel : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
|
||||
/// 月票展示数量
|
||||
@property (nonatomic, assign) NSInteger num;
|
||||
|
||||
/// 是否可选中
|
||||
@property (nonatomic, assign, getter=isEnabled) NSInteger enabled;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// WXYZ_GiftMonthlyPassModel.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_GiftMonthlyPassModel.h"
|
||||
|
||||
@implementation WXYZ_GiftMonthlyPassModel
|
||||
|
||||
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
|
||||
return @{
|
||||
@"info" : @"ticket_info",
|
||||
@"list" : @"ticket_option"
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
|
||||
return @{
|
||||
@"info" : WXYZ_GiftMonthlyPassInfoModel.class,
|
||||
@"list" : WXYZ_GiftMonthlyPassListModel.class
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_GiftMonthlyPassInfoModel
|
||||
|
||||
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
|
||||
return @{
|
||||
@"stickerNumber" : @"current_month_get",
|
||||
@"ranking" : @"rank_tips",
|
||||
@"ticket_remain" : @"user_remain",
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_GiftMonthlyPassListModel
|
||||
|
||||
@end
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// WXYZ_GiftMonthlyPassView.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class WXYZ_GiftView;
|
||||
|
||||
@class TFProductionModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_GiftMonthlyPassView : UIView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel;
|
||||
|
||||
/// 月票余额返回
|
||||
@property (nonatomic, copy) void(^ticketNumBlock)(NSInteger ticketNumber);
|
||||
|
||||
@property (nonatomic, weak) WXYZ_GiftView *giftView;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+320
@@ -0,0 +1,320 @@
|
||||
//
|
||||
// WXYZ_GiftMonthlyPassView.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_GiftMonthlyPassView.h"
|
||||
|
||||
#import "WXYZ_GiftMonthlyPassModel.h"
|
||||
#import "NSObject+Observer.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "WXYZ_TickectAlertModel.h"
|
||||
#import "TFProductionCoverView.h"
|
||||
|
||||
#import "WXYZ_GiftView.h"
|
||||
#import "TFRechargeViewController.h"
|
||||
#import "TFWebViewController.h"
|
||||
#import "TFGiftAlertView.h"
|
||||
|
||||
@interface WXYZ_GiftMonthlyPassView ()
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *bookModel;
|
||||
|
||||
@property (nonatomic, strong) WXYZ_GiftMonthlyPassModel *monthlyPassModel;
|
||||
|
||||
/// 当前选择按钮的下标
|
||||
@property (nonatomic, assign) NSInteger selectedIndex;
|
||||
|
||||
@property (nonatomic, strong) NSArray<UIButton *> *tickectBtnArray;
|
||||
|
||||
@property (nonatomic, weak) UIView *alertView;
|
||||
|
||||
@property (nonatomic, weak) UIButton *voteBtn;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_GiftMonthlyPassView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.bookModel = bookModel;
|
||||
[self initialize];
|
||||
[self netRequest];
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
TFProductionCoverView *coverImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
|
||||
[self addSubview:coverImageView];
|
||||
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self).offset(kMargin);
|
||||
make.left.equalTo(self).offset(kMoreHalfMargin);
|
||||
make.size.mas_equalTo(CGSizeMake(55.0, 74.0));
|
||||
}];
|
||||
|
||||
UILabel *nameLabel = [[UILabel alloc] init];
|
||||
nameLabel.backgroundColor = [UIColor clearColor];
|
||||
nameLabel.textColor = kBlackColor;
|
||||
nameLabel.font = kFont14;
|
||||
[self addSubview:nameLabel];
|
||||
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(coverImageView).offset(16);
|
||||
make.left.equalTo(coverImageView.mas_right).offset(kHalfMargin);
|
||||
}];
|
||||
|
||||
UILabel *tickerLabel = [[UILabel alloc] init];
|
||||
tickerLabel.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:tickerLabel];
|
||||
|
||||
UILabel *rankLabel = [[UILabel alloc] init];
|
||||
rankLabel.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:rankLabel];
|
||||
|
||||
UILabel *last_distanceLabel = [[UILabel alloc] init];
|
||||
last_distanceLabel.backgroundColor = [UIColor clearColor];
|
||||
last_distanceLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self addSubview:last_distanceLabel];
|
||||
|
||||
NSArray<UILabel *> *labelArr = @[tickerLabel, rankLabel, last_distanceLabel];
|
||||
[labelArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:80 tailSpacing:0];
|
||||
[labelArr mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(coverImageView).offset(-kHalfMargin);
|
||||
}];
|
||||
|
||||
|
||||
UIView *bottomView = [[UIView alloc] init];
|
||||
bottomView.backgroundColor = kGrayViewColor;
|
||||
[self addSubview:bottomView];
|
||||
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.bottom.equalTo(self);
|
||||
make.height.mas_equalTo(65.0 + PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
|
||||
UILabel *remainLabel = [[UILabel alloc] init];
|
||||
remainLabel.backgroundColor = [UIColor clearColor];
|
||||
[bottomView addSubview:remainLabel];
|
||||
[remainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(bottomView).offset(kMoreHalfMargin + 1.0f);
|
||||
make.left.equalTo(bottomView).offset(kMoreHalfMargin);
|
||||
}];
|
||||
|
||||
UIImageView *helpImageView = [[UIImageView alloc] init];
|
||||
helpImageView.image = [UIImage imageNamed:@"book_help"];
|
||||
[bottomView addSubview:helpImageView];
|
||||
[helpImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(remainLabel);
|
||||
make.left.equalTo(remainLabel.mas_right).offset(kHalfMargin);
|
||||
make.size.mas_equalTo(CGSizeMake(kMoreHalfMargin, kMoreHalfMargin));
|
||||
}];
|
||||
helpImageView.userInteractionEnabled = YES;
|
||||
WS(weakSelf)
|
||||
[helpImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
|
||||
[weakSelf.giftView removeFromSuperview];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""];
|
||||
TFWebViewController *vc = [[TFWebViewController alloc] init];
|
||||
vc.URLString = weakSelf.monthlyPassModel.info.ticket_rule;
|
||||
vc.navTitle = TFLocalizedString(@"月票说明");
|
||||
vc.isPresentState = NO;
|
||||
[[TFViewHelper getCurrentNavigationController] pushViewController:vc animated:YES];
|
||||
}]];
|
||||
helpImageView.hidden = YES;
|
||||
|
||||
UILabel *detailLabel = [[UILabel alloc] init];
|
||||
detailLabel.numberOfLines = 2;
|
||||
detailLabel.backgroundColor = [UIColor clearColor];
|
||||
[bottomView addSubview:detailLabel];
|
||||
[detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(remainLabel.mas_bottom).offset(2.5);
|
||||
make.left.equalTo(remainLabel);
|
||||
}];
|
||||
|
||||
UIButton *voteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.voteBtn = voteBtn;
|
||||
[voteBtn setImage:[UIImage imageNamed:TFLocalizedString(@"book_ticketBtn")] forState:UIControlStateNormal];
|
||||
voteBtn.layer.cornerRadius = 19.0f;
|
||||
voteBtn.layer.masksToBounds = YES;
|
||||
[voteBtn addTarget:self action:@selector(voteEvent) forControlEvents:UIControlEventTouchUpInside];
|
||||
[bottomView addSubview:voteBtn];
|
||||
[voteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(bottomView).offset(kMoreHalfMargin);
|
||||
make.right.equalTo(bottomView).offset(-kMoreHalfMargin);
|
||||
make.size.mas_equalTo(CGSizeMake(105.0f, 38.0f));
|
||||
}];
|
||||
|
||||
[detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(voteBtn.mas_left).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
[remainLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(voteBtn.mas_left).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
|
||||
[self addObserver:KEY_PATH(self, monthlyPassModel) complete:^(WXYZ_GiftMonthlyPassView * _Nonnull obj, id _Nullable oldVal, WXYZ_GiftMonthlyPassModel * _Nullable newVal) {
|
||||
coverImageView.coverImageUrl = newVal.info.cover;
|
||||
nameLabel.text = newVal.info.name ? : @"";
|
||||
tickerLabel.attributedText = [obj attributeStringWithStr:newVal.info.stickerNumber ? : @"" speFont:kFont16 speColor:kBlackColor];
|
||||
rankLabel.attributedText = [obj attributeStringWithStr:newVal.info.ranking ? : @"" speFont:kFont16 speColor:kBlackColor];
|
||||
last_distanceLabel.attributedText = [obj attributeStringWithStr:newVal.info.last_distance ? : @"" speFont:kFont16 speColor:kBlackColor];
|
||||
NSString *prefix = TFLocalizedString(@"拥有");
|
||||
NSString *suffix = TFLocalizedString(@"月票");
|
||||
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@", prefix, newVal.info.ticket_remain, suffix] attributes:@{NSFontAttributeName : kFont14, NSForegroundColorAttributeName : kBlackColor}];
|
||||
[atr addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, newVal.info.ticket_remain.length)];
|
||||
remainLabel.attributedText = atr;
|
||||
detailLabel.attributedText = [obj attributeStringWithStr:newVal.info.monthly_tips speFont:kFont11 speColor:kMainColor];
|
||||
|
||||
if (newVal.info.can_vote == 1) {
|
||||
voteBtn.alpha = 1;
|
||||
voteBtn.enabled = YES;
|
||||
} else {
|
||||
voteBtn.alpha = 0.5;
|
||||
voteBtn.enabled = NO;
|
||||
}
|
||||
|
||||
NSMutableArray<UIButton *> *btnArr = [NSMutableArray array];
|
||||
if (obj.tickectBtnArray.count == 0) {
|
||||
obj.tickectBtnArray = btnArr;
|
||||
NSInteger index = 0;
|
||||
for (WXYZ_GiftMonthlyPassListModel *model in newVal.list) {
|
||||
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
NSString *text = [NSString stringWithFormat:@"%@\n%@", model.title, TFLocalizedString(@"月票")];
|
||||
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName : kBlackColor, NSFontAttributeName : kFont11}];
|
||||
[atr addAttribute:NSFontAttributeName value:kFont15 range:NSMakeRange(0, model.title.length)];
|
||||
if (model.enabled == 0) {
|
||||
[atr addAttribute:NSForegroundColorAttributeName value:kColorRGB(153, 153, 153) range:NSMakeRange(0, atr.length)];
|
||||
button.enabled = NO;
|
||||
}
|
||||
[button setAttributedTitle:atr forState:UIControlStateNormal];
|
||||
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5.0, 0, 5.0)];
|
||||
button.titleLabel.numberOfLines = 0;
|
||||
button.titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
button.layer.cornerRadius = 2.5;
|
||||
button.layer.masksToBounds = YES;
|
||||
button.layer.borderWidth = 0.5;
|
||||
button.layer.borderColor = kColorRGB(221, 221, 221).CGColor;
|
||||
button.tag = index;
|
||||
[button addTarget:obj action:@selector(tickectOptionEvent:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[obj addSubview:button];
|
||||
[btnArr addObject:button];
|
||||
index++;
|
||||
}
|
||||
|
||||
[btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:kQuarterMargin leadSpacing:15.0 tailSpacing:15.0];
|
||||
[btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(coverImageView.mas_bottom).offset(24.0);
|
||||
make.height.equalTo(btnArr.firstObject.mas_width);
|
||||
}];
|
||||
[btnArr.firstObject sendActionsForControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)tickectOptionEvent:(UIButton *)button {
|
||||
|
||||
if (self.monthlyPassModel.list[button.tag].enabled == 1) {
|
||||
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithAttributedString:button.currentAttributedTitle];
|
||||
[str setAttribute:NSForegroundColorAttributeName value:kMainColor];
|
||||
[button setAttributedTitle:str forState:UIControlStateNormal];
|
||||
button.layer.borderColor = kMainColor.CGColor;
|
||||
self.selectedIndex = button.tag;
|
||||
}
|
||||
|
||||
for (UIButton *obj in self.tickectBtnArray) {
|
||||
if (obj != button) {
|
||||
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithAttributedString:obj.currentAttributedTitle];
|
||||
[str setAttribute:NSForegroundColorAttributeName value:self.monthlyPassModel.list[obj.tag].enabled ? kBlackColor : kColorRGB(153, 153, 153)];
|
||||
[obj setAttributedTitle:str forState:UIControlStateNormal];
|
||||
obj.layer.borderColor = kColorRGB(221, 221, 221).CGColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.monthlyPassModel.info.can_vote == 1) {
|
||||
self.voteBtn.alpha = 1;
|
||||
self.voteBtn.enabled = YES;
|
||||
} else {
|
||||
self.voteBtn.alpha = 0.5;
|
||||
self.voteBtn.enabled = NO;
|
||||
}
|
||||
}
|
||||
|
||||
// 投月票
|
||||
- (void)voteEvent {
|
||||
if (self.selectedIndex == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TFUserInfoManager.isLogin) {
|
||||
[TFLoginOptionsViewController presentLoginView:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
WXYZ_GiftMonthlyPassListModel *model = self.monthlyPassModel.list[self.selectedIndex];
|
||||
NSDictionary *params = @{
|
||||
@"book_id" : @(self.bookModel.production_id),
|
||||
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
|
||||
@"num" : @(model.num),
|
||||
};
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Book_Reward_Ticket_Vote parameters:params model:WXYZ_TickectAlertModel.class success:^(BOOL isSuccess, WXYZ_TickectAlertModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
[weakSelf netRequest];
|
||||
NSString *text = [NSString stringWithFormat:@"%@", requestModel.data[@"ticket_num"]];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeTicket" object:text];
|
||||
!weakSelf.ticketNumBlock ?: weakSelf.ticketNumBlock([text integerValue]);
|
||||
[TFReaderBookManager sharedManager].ticket_num = text ?: @"";
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"投票成功")];
|
||||
} else if (Compare_Json_isEqualTo(requestModel.code, 902)) {
|
||||
[weakSelf showAlert:t_model t_model:weakSelf.monthlyPassModel.list[weakSelf.selectedIndex] production_id:weakSelf.bookModel.production_id ticketNumBlock:weakSelf.ticketNumBlock];
|
||||
[weakSelf.giftView hide];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)attributeStringWithStr:(NSString *)str speFont:(UIFont *)speFont speColor:(UIColor *)speColor {
|
||||
NSRange range = [str rangeOfString:@"###.*###" options:NSRegularExpressionSearch];
|
||||
if (range.length == 0) range = NSMakeRange(0, 0);
|
||||
NSString *suffix = [[str substringWithRange:range] stringByReplacingOccurrencesOfString:@"#" withString:@""];
|
||||
suffix = [NSString stringWithFormat:@" %@ ", suffix];
|
||||
NSMutableString *prefix = [NSMutableString stringWithString:[str stringByReplacingCharactersInRange:range withString:@""]];
|
||||
[prefix insertString:suffix atIndex:range.location];
|
||||
|
||||
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:prefix attributes:@{NSFontAttributeName : kFont11, NSForegroundColorAttributeName : kGrayTextColor}];
|
||||
[atr addAttributes:@{NSFontAttributeName : speFont, NSForegroundColorAttributeName : speColor} range:NSMakeRange(range.location, suffix.length)];
|
||||
return atr;
|
||||
}
|
||||
|
||||
- (void)netRequest {
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Book_Gift_Montyly_Pass parameters:@{@"book_id":@(self.bookModel.production_id)} model:WXYZ_GiftMonthlyPassModel.class success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
weakSelf.monthlyPassModel = t_model;
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showAlert:(WXYZ_TickectAlertModel *)model t_model:(WXYZ_GiftMonthlyPassListModel *)t_model production_id:(NSInteger)production_id ticketNumBlock:(void(^)(NSInteger number))ticketNumBlock
|
||||
{
|
||||
TFGiftAlertView *alertView = [[TFGiftAlertView alloc] init];
|
||||
[alertView setAlertModel:model giftModel:t_model production_id:production_id ticketBlock:ticketNumBlock];
|
||||
[alertView showAlertView];
|
||||
}
|
||||
|
||||
@end
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// WXYZ_GiftRewardList.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class WXYZ_GiftRewardListModel, WXYZ_GiftUserModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_GiftRewardModel : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSArray<WXYZ_GiftRewardListModel *> *list;
|
||||
|
||||
@property (nonatomic, copy) NSArray<NSString *> *announce_list;
|
||||
|
||||
@property (nonatomic, strong) WXYZ_GiftUserModel *user;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_GiftRewardListModel : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger gift_id;
|
||||
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
|
||||
@property (nonatomic, copy) NSString *icon;
|
||||
|
||||
/// 奖励文案
|
||||
@property (nonatomic, copy) NSString *gift_price;
|
||||
|
||||
/// 角标
|
||||
@property (nonatomic, copy) NSString *flag;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_GiftUserModel : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger goldRemain;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// WXYZ_GiftRewardList.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_GiftRewardModel.h"
|
||||
|
||||
@implementation WXYZ_GiftRewardModel
|
||||
|
||||
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
|
||||
return @{
|
||||
@"list" : @"gift_option",
|
||||
@"announce_list" : @"broadcast_list"
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
|
||||
return @{
|
||||
@"list" : WXYZ_GiftRewardListModel.class
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_GiftRewardListModel
|
||||
|
||||
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
|
||||
return @{
|
||||
@"awardTitle" : @"award_money"
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_GiftUserModel
|
||||
|
||||
@end
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// WXYZ_GiftRewardView.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class WXYZ_GiftView;
|
||||
|
||||
@class WXYZ_GiftRewardListModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_GiftRewardView : UIView
|
||||
|
||||
@property (nonatomic, weak) WXYZ_GiftView *giftView;
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *bookModel;
|
||||
|
||||
/// 打赏余额返回
|
||||
@property (nonatomic, copy) void(^giftNumBlock)(NSInteger giftNumber);
|
||||
|
||||
- (instancetype)initWithBookModel:(TFProductionModel *)bookModel;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_GiftRewardCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) WXYZ_GiftRewardListModel *giftRewardModel;
|
||||
|
||||
- (void)setSelected:(BOOL)selected;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+354
@@ -0,0 +1,354 @@
|
||||
//
|
||||
// WXYZ_GiftRewardView.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/28.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_GiftRewardView.h"
|
||||
|
||||
#import "NSObject+Observer.h"
|
||||
#import "WXYZ_GiftRewardModel.h"
|
||||
|
||||
#import "LLPageControl.h"
|
||||
#import "WXYZ_AnnouncementView.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "TFRechargeViewController.h"
|
||||
|
||||
#import "WXYZ_GiftView.h"
|
||||
|
||||
@interface WXYZ_GiftRewardView ()<UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) NSArray<WXYZ_GiftRewardListModel *> *dataSourceArray;
|
||||
|
||||
@property (nonatomic, strong) WXYZ_GiftRewardModel *giftRewardModel;
|
||||
|
||||
@property (nonatomic, weak) UICollectionView *mainCollectionView;
|
||||
|
||||
@property (nonatomic, weak) LLPageControl *pageControl;
|
||||
|
||||
@property (nonatomic, weak) WXYZ_AnnouncementView *announcementView;
|
||||
|
||||
@property (nonatomic, weak) UILabel *remainLabel;
|
||||
|
||||
@property (nonatomic, assign) NSInteger selectedIndex;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_GiftRewardView
|
||||
|
||||
- (instancetype)initWithBookModel:(TFProductionModel *)bookModel {
|
||||
if (self = [super init]) {
|
||||
self.bookModel = bookModel;
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
[self netRequest];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:Notification_Login_Success object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||
flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 2.0 * kMoreHalfMargin - 3 * kHalfMargin) / 4.0, 127.0);
|
||||
flowLayout.minimumInteritemSpacing = kHalfMargin;
|
||||
flowLayout.minimumLineSpacing = kHalfMargin;
|
||||
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
|
||||
UICollectionView *mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
|
||||
self.mainCollectionView = mainCollectionView;
|
||||
mainCollectionView.showsHorizontalScrollIndicator = NO;
|
||||
mainCollectionView.showsVerticalScrollIndicator = NO;
|
||||
mainCollectionView.backgroundColor = [UIColor clearColor];
|
||||
mainCollectionView.pagingEnabled = YES;
|
||||
mainCollectionView.dataSource = self;
|
||||
mainCollectionView.delegate = self;
|
||||
mainCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, kMoreHalfMargin);
|
||||
[mainCollectionView registerClass:WXYZ_GiftRewardCell.class forCellWithReuseIdentifier:@"Identifier"];
|
||||
[self addSubview:mainCollectionView];
|
||||
[mainCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self).offset(15);
|
||||
make.right.equalTo(self).offset(0);
|
||||
make.top.equalTo(self).offset(kMoreHalfMargin);
|
||||
make.height.mas_equalTo(127.0);
|
||||
}];
|
||||
|
||||
// [mainCollectionView addObserver:KEY_PATH(mainCollectionView, contentSize) complete:^(UICollectionView * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
|
||||
// CGSize size = [newVal CGSizeValue];
|
||||
// [obj mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
// make.height.mas_equalTo(size.height);
|
||||
// }];
|
||||
// [obj.superview setNeedsLayout];
|
||||
// [obj.superview layoutIfNeeded];
|
||||
// }];
|
||||
|
||||
LLPageControl *pageControl = [LLPageControl pageControlWithRadius:3.5 spacing:6.0f numberOfPages:1];
|
||||
self.pageControl = pageControl;
|
||||
pageControl.currentPageIndicatorTintColor = kMainColor;
|
||||
pageControl.pageIndicatorTintColor = kColorRGB(225, 225, 225);
|
||||
[self addSubview:pageControl];
|
||||
[pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(mainCollectionView.mas_bottom).offset(12.0);
|
||||
make.centerX.equalTo(self);
|
||||
}];
|
||||
|
||||
WXYZ_AnnouncementView *announcementView = [[WXYZ_AnnouncementView alloc] init];
|
||||
self.announcementView = announcementView;
|
||||
announcementView.backgroundColor = kColorRGB(249, 248, 253);
|
||||
announcementView.layer.cornerRadius = 14.0f;
|
||||
announcementView.layer.masksToBounds = YES;
|
||||
announcementView.textFont = kFont11;
|
||||
announcementView.textColor = kGrayTextColor;
|
||||
announcementView.isCenter = YES;
|
||||
announcementView.duration = 5.0f;
|
||||
announcementView.userInteractionEnabled = NO;
|
||||
[self addSubview:announcementView];
|
||||
[announcementView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(pageControl.mas_bottom).offset(17.0f);
|
||||
make.left.equalTo(self).offset(kMoreHalfMargin);
|
||||
make.right.equalTo(self).offset(-kMoreHalfMargin);
|
||||
make.height.equalTo(announcementView.mas_width).multipliedBy(28.0 / 345.0);
|
||||
}];
|
||||
|
||||
UIView *bottomView = [[UIView alloc] init];
|
||||
bottomView.backgroundColor = kColorRGB(249, 248, 253);
|
||||
[self addSubview:bottomView];
|
||||
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(announcementView.mas_bottom).offset(17.0f);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(65.0f);
|
||||
}];
|
||||
|
||||
UILabel *remainLabel = [[UILabel alloc] init];
|
||||
self.remainLabel = remainLabel;
|
||||
remainLabel.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:remainLabel];
|
||||
[remainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(bottomView).offset(kMoreHalfMargin);
|
||||
make.top.equalTo(bottomView.mas_top).offset(15.0);
|
||||
}];
|
||||
|
||||
UIButton *rewardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
rewardBtn.layer.cornerRadius = 19.0f;
|
||||
[rewardBtn setImage:[UIImage imageNamed:TFLocalizedString(@"book_giftBtn")] forState:UIControlStateNormal];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rewardEvent)];
|
||||
[rewardBtn addGestureRecognizer:tap];
|
||||
[bottomView addSubview:rewardBtn];
|
||||
[rewardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(bottomView).offset(6.0);
|
||||
make.right.equalTo(bottomView).offset(-kMoreHalfMargin);
|
||||
make.size.mas_equalTo(CGSizeMake(105, 38));
|
||||
}];
|
||||
|
||||
UIView *splitLine = [[UIView alloc] init];
|
||||
splitLine.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:splitLine];
|
||||
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(0.1);
|
||||
make.left.right.bottom.equalTo(self);
|
||||
make.top.equalTo(bottomView.mas_bottom).priorityLow();
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
return self.dataSourceArray.count;
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
WXYZ_GiftRewardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Identifier" forIndexPath:indexPath];
|
||||
[cell setGiftRewardModel:self.dataSourceArray[indexPath.row]];
|
||||
[cell setSelected:self.selectedIndex == indexPath.row];
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
self.selectedIndex = indexPath.row;
|
||||
[collectionView reloadData];
|
||||
}
|
||||
|
||||
- (void)loginSuccess {
|
||||
NSString *prefix = TFLocalizedString(@"余额:");
|
||||
NSString *remain = [NSString stringWithFormat:@"%zd", TFUserInfoManager.shareInstance.masterRemain];
|
||||
NSString *suffix = TFSystemInfoManager.masterUnit;
|
||||
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@ %@", prefix, remain, suffix] attributes:@{NSForegroundColorAttributeName: kGrayTextColor, NSFontAttributeName: kFont14}];
|
||||
[str addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, remain.length)];
|
||||
self.remainLabel.attributedText = str;
|
||||
}
|
||||
|
||||
- (void)rewardEvent {
|
||||
if (!TFUserInfoManager.isLogin) {
|
||||
[TFLoginOptionsViewController presentLoginView:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
WXYZ_GiftRewardListModel *model = self.dataSourceArray[self.selectedIndex];
|
||||
NSDictionary *params = @{
|
||||
@"book_id" : @(self.bookModel.production_id),
|
||||
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
|
||||
@"gift_id" : @(model.gift_id)
|
||||
};
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Book_Reward_Gift_Send parameters:params model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
if (isSuccess) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"打赏成功")];
|
||||
NSString *text = [NSString stringWithFormat:@"%@", t_model[@"data"][@"reward_num"]];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeReward" object:text];
|
||||
!weakSelf.giftNumBlock ?: weakSelf.giftNumBlock([text integerValue]);
|
||||
[weakSelf.giftView hide];
|
||||
} else if (Compare_Json_isEqualTo(requestModel.code, 802)) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""];
|
||||
[[TFViewHelper getCurrentNavigationController] pushViewController:[[TFRechargeViewController alloc] init] animated:YES];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||
// 计算偏移量更新分页控件
|
||||
NSUInteger page = CGRectGetMinX(scrollView.bounds) / scrollView.contentOffset.x;
|
||||
if (scrollView.contentOffset.x == 0) {
|
||||
page = 0;
|
||||
}
|
||||
self.pageControl.currentPage = page;
|
||||
}
|
||||
|
||||
- (void)netRequest {
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:Gift_List parameters:@{@"book_id":@(self.bookModel.production_id)} model:WXYZ_GiftRewardModel.class success:^(BOOL isSuccess, WXYZ_GiftRewardModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
if (isSuccess) {
|
||||
weakSelf.giftRewardModel = t_model;
|
||||
weakSelf.dataSourceArray = t_model.list;
|
||||
weakSelf.pageControl.numberOfPages = ceil(weakSelf.dataSourceArray.count / 4.0);
|
||||
NSMutableArray<TFAnnouncementModel *> *arr = [NSMutableArray array];
|
||||
for (NSString *str in t_model.announce_list) {
|
||||
TFAnnouncementModel *tt_model = [[TFAnnouncementModel alloc] init];
|
||||
tt_model.content = @"";
|
||||
tt_model.title = str;
|
||||
[arr addObject:tt_model];
|
||||
}
|
||||
weakSelf.announcementView.modelArr = arr;
|
||||
NSString *prefix = TFLocalizedString(@"余额:");
|
||||
NSString *remain = [NSString stringWithFormat:@"%zd", t_model.user.goldRemain];
|
||||
NSString *suffix = TFSystemInfoManager.masterUnit;
|
||||
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@ %@", prefix, remain, suffix] attributes:@{NSForegroundColorAttributeName: kGrayTextColor, NSFontAttributeName: kFont14}];
|
||||
[str addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, remain.length)];
|
||||
weakSelf.remainLabel.attributedText = str;
|
||||
[weakSelf.mainCollectionView reloadData];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_GiftRewardCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
self.contentView.layer.cornerRadius = 2.5;
|
||||
self.contentView.layer.borderColor = kMainColor.CGColor;
|
||||
self.contentView.layer.borderWidth = 0.0f;
|
||||
self.contentView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
UILabel *flagLabel = [[UILabel alloc] init];
|
||||
flagLabel.font = kFont10;
|
||||
flagLabel.textColor = [UIColor whiteColor];
|
||||
flagLabel.backgroundColor = kColorRGB(255, 83, 81);
|
||||
flagLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.contentView.bounds) - kHalfMargin;
|
||||
flagLabel.textAlignment = NSTextAlignmentCenter;
|
||||
flagLabel.layer.cornerRadius = 2.0f;
|
||||
flagLabel.numberOfLines = 0;
|
||||
flagLabel.layer.masksToBounds = YES;
|
||||
[self.contentView addSubview:flagLabel];
|
||||
[flagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.right.equalTo(self.contentView);
|
||||
}];
|
||||
|
||||
UIImageView *coverImageView = [[UIImageView alloc] init];
|
||||
coverImageView.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:coverImageView];
|
||||
[self.contentView sendSubviewToBack:coverImageView];
|
||||
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.contentView).offset(kMargin);
|
||||
make.centerX.equalTo(self.contentView);
|
||||
make.size.mas_equalTo(CGSizeMake(50.0, 50.0));
|
||||
}];
|
||||
|
||||
UILabel *subtitle = [[UILabel alloc] init];
|
||||
subtitle.textColor = kGrayTextColor;
|
||||
subtitle.font = kFont10;
|
||||
subtitle.textAlignment = NSTextAlignmentCenter;
|
||||
subtitle.numberOfLines = 0;
|
||||
subtitle.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:subtitle];
|
||||
[subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.contentView).offset(-kQuarterMargin);
|
||||
make.left.equalTo(self.contentView).offset(kQuarterMargin);
|
||||
make.right.equalTo(self.contentView).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
UILabel *titleLabel = [[UILabel alloc] init];
|
||||
titleLabel.textColor = kBlackColor;
|
||||
titleLabel.font = kFont13;
|
||||
titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
titleLabel.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:titleLabel];
|
||||
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(subtitle.mas_top).offset(- kQuarterMargin);
|
||||
make.left.equalTo(self.contentView).offset(kQuarterMargin);
|
||||
make.right.equalTo(self.contentView).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
[self addObserver:KEY_PATH(self, giftRewardModel) complete:^(WXYZ_GiftRewardCell * _Nonnull obj, id _Nullable oldVal, WXYZ_GiftRewardListModel * _Nullable newVal) {
|
||||
flagLabel.text = newVal.flag ?: @"";
|
||||
CGFloat maxWidth = CGRectGetWidth(obj.contentView.bounds) - kHalfMargin;
|
||||
if (flagLabel.intrinsicContentSize.width + 12 < maxWidth) {
|
||||
maxWidth = flagLabel.intrinsicContentSize.width + 12;
|
||||
}
|
||||
[flagLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(maxWidth);
|
||||
make.height.mas_equalTo(flagLabel.intrinsicContentSize.height + kQuarterMargin);
|
||||
}];
|
||||
flagLabel.hidden = newVal.flag.length == 0;
|
||||
[coverImageView setImageWithURL:[NSURL URLWithString:newVal.icon ?: @""] placeholder:HoldImage];
|
||||
titleLabel.text = newVal.title ?: @"";
|
||||
subtitle.text = newVal.gift_price ?: @"";
|
||||
}];
|
||||
}
|
||||
|
||||
//- (UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
|
||||
// [self setNeedsLayout];
|
||||
// [self layoutIfNeeded];
|
||||
// CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
|
||||
// CGRect cellFrame = layoutAttributes.frame;
|
||||
// cellFrame.size.height = size.height;
|
||||
// layoutAttributes.frame = cellFrame;
|
||||
// return layoutAttributes;
|
||||
//}
|
||||
|
||||
- (void)setSelected:(BOOL)selected {
|
||||
if (selected) {
|
||||
self.contentView.layer.borderWidth = 1.0f;
|
||||
} else {
|
||||
self.contentView.layer.borderWidth = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// WXYZ_GiftView.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class TFProductionModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 阅读器礼物视图
|
||||
@interface WXYZ_GiftView : UIView
|
||||
|
||||
/// 月票余额返回
|
||||
@property (nonatomic, copy) void(^ticketNumBlock)(NSInteger ticketNumber);
|
||||
|
||||
/// 打赏余额返回
|
||||
@property (nonatomic, copy) void(^giftNumBlock)(NSInteger giftNumber);
|
||||
|
||||
/// 是否选中月票页面
|
||||
@property (nonatomic, assign) BOOL isTicket;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel;
|
||||
|
||||
- (void)hide;
|
||||
|
||||
- (void)show;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// WXYZ_GiftView.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_GiftView.h"
|
||||
|
||||
#import "UIView+LayoutCallback.h"
|
||||
|
||||
#import "SGPageTitleView.h"
|
||||
#import "WXYZ_GiftRewardView.h"
|
||||
#import "WXYZ_GiftMonthlyPassView.h"
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface WXYZ_GiftView ()<SGPageTitleViewDelegate, UIScrollViewDelegate>
|
||||
|
||||
@property (nonatomic, weak) UIView *mainView;
|
||||
|
||||
@property (nonatomic, weak) UIView *backView;
|
||||
|
||||
@property (nonatomic, weak) SGPageTitleView *pageTitleView;
|
||||
|
||||
@property (nonatomic, weak) UIScrollView *scrollView;
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *bookModel;
|
||||
|
||||
@property (nonatomic, weak) WXYZ_GiftRewardView *rewardView;
|
||||
|
||||
@property (nonatomic, weak) WXYZ_GiftMonthlyPassView *monthlyPassView;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<NSString *> *titleArr;
|
||||
|
||||
/// mainView视图约束
|
||||
@property (nonatomic, strong) MASConstraint *mainViewConstraint;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_GiftView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
self.bookModel = bookModel;
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
self.backgroundColor = kBlackTransparentColor;
|
||||
[[TFViewHelper getCurrentViewController].view addSubview:self];
|
||||
[self mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo([TFViewHelper getCurrentViewController].view);
|
||||
}];
|
||||
|
||||
UIView *backView = [[UIView alloc] init];
|
||||
self.backView = backView;
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
||||
[backView addGestureRecognizer:tap];
|
||||
backView.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:backView];
|
||||
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
UIView *mainView = [[UIView alloc] init];
|
||||
self.mainView = mainView;
|
||||
mainView.backgroundColor = [UIColor whiteColor];
|
||||
mainView.frameBlock = ^(UIView * _Nonnull view) {
|
||||
UIBezierPath *corner = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12.0, 12.0)];
|
||||
CAShapeLayer *layer = [CAShapeLayer layer];
|
||||
layer.path = corner.CGPath;
|
||||
view.layer.mask = layer;
|
||||
};
|
||||
[self addSubview:mainView];
|
||||
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
self.mainViewConstraint = make.top.equalTo(backView.mas_bottom);
|
||||
make.left.width.equalTo(backView);
|
||||
}];
|
||||
|
||||
SGPageTitleViewConfigure *pageConfigure = [[SGPageTitleViewConfigure alloc] init];
|
||||
pageConfigure.indicatorColor = kColorRGB(253, 154, 99);
|
||||
pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
|
||||
pageConfigure.indicatorHeight = 3;
|
||||
pageConfigure.indicatorFixedWidth = 20;
|
||||
pageConfigure.indicatorDynamicWidth = 20;
|
||||
pageConfigure.indicatorCornerRadius = 3.0;
|
||||
pageConfigure.indicatorToBottomDistance = 5;
|
||||
pageConfigure.titleFont = kFont15;
|
||||
pageConfigure.titleSelectedFont = kFont16;
|
||||
pageConfigure.titleColor = kGrayTextColor;
|
||||
pageConfigure.titleSelectedColor = kBlackColor;
|
||||
pageConfigure.showBottomSeparator = NO;
|
||||
|
||||
AppDelegate *app = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
|
||||
NSMutableArray<NSString *> *titleArr = [NSMutableArray array];
|
||||
self.titleArr = titleArr;
|
||||
if (app.checkSettingModel.system_setting.novel_reward_switch == 1) {
|
||||
[titleArr addObject:TFLocalizedString(@"打赏")];
|
||||
}
|
||||
|
||||
if (app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
|
||||
[titleArr addObject:TFLocalizedString(@"月票")];
|
||||
}
|
||||
|
||||
CGFloat width1 = [TFViewHelper getDynamicWidthWithLabelFont:kFont14 labelHeight:50.0 labelText:TFLocalizedString(@"打赏") maxWidth:200.0];
|
||||
CGFloat width2 = [TFViewHelper getDynamicWidthWithLabelFont:kFont17 labelHeight:50.0 labelText:TFLocalizedString(@"月票") maxWidth:200.0];
|
||||
CGFloat width = width1 + width2 + kLabelHeight + kMargin;
|
||||
|
||||
SGPageTitleView *pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectZero delegate:self titleNames:titleArr configure:pageConfigure];
|
||||
self.pageTitleView = pageTitleView;
|
||||
pageTitleView.backgroundColor = [UIColor clearColor];
|
||||
[mainView addSubview:pageTitleView];
|
||||
[pageTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(mainView).offset(0);
|
||||
make.centerX.equalTo(mainView);
|
||||
make.width.mas_equalTo(width);
|
||||
make.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
UIView *pageTitleSplitLine = [[UIView alloc] init];
|
||||
pageTitleSplitLine.backgroundColor = kGrayLineColor;
|
||||
[mainView addSubview:pageTitleSplitLine];
|
||||
[pageTitleSplitLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.width.equalTo(mainView);
|
||||
make.top.equalTo(pageTitleView.mas_bottom);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
}];
|
||||
|
||||
UIScrollView *scrollView = [[UIScrollView alloc] init];
|
||||
self.scrollView = scrollView;
|
||||
scrollView.backgroundColor = [UIColor clearColor];
|
||||
scrollView.bounces = NO;
|
||||
scrollView.showsVerticalScrollIndicator = NO;
|
||||
scrollView.showsHorizontalScrollIndicator = NO;
|
||||
scrollView.delegate = self;
|
||||
scrollView.pagingEnabled = YES;
|
||||
[mainView addSubview:scrollView];
|
||||
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(pageTitleSplitLine.mas_bottom);
|
||||
make.left.width.equalTo(mainView);
|
||||
make.height.mas_equalTo(271 + PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
|
||||
WXYZ_GiftRewardView *rewardView = [[WXYZ_GiftRewardView alloc] initWithBookModel:self.bookModel];
|
||||
self.rewardView = rewardView;
|
||||
rewardView.giftView = self;
|
||||
rewardView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
WXYZ_GiftMonthlyPassView *monthlyPassView = [[WXYZ_GiftMonthlyPassView alloc] initWithFrame:CGRectZero bookModel:self.bookModel];
|
||||
self.monthlyPassView = monthlyPassView;
|
||||
monthlyPassView.giftView = self;
|
||||
monthlyPassView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
|
||||
if (app.checkSettingModel.system_setting.novel_reward_switch == 1 && app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
|
||||
[scrollView addSubview:rewardView];
|
||||
[scrollView addSubview:monthlyPassView];
|
||||
[rewardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.width.height.equalTo(scrollView);
|
||||
}];
|
||||
[monthlyPassView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.height.right.equalTo(scrollView);
|
||||
make.left.equalTo(rewardView.mas_right);
|
||||
make.width.equalTo(rewardView);
|
||||
}];
|
||||
} else if (app.checkSettingModel.system_setting.novel_reward_switch == 1) {
|
||||
[scrollView addSubview:rewardView];
|
||||
[rewardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.width.height.equalTo(scrollView);
|
||||
make.right.equalTo(scrollView);
|
||||
}];
|
||||
// monthlyPassView.hidden = YES;
|
||||
} else if (app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
|
||||
[scrollView addSubview:monthlyPassView];
|
||||
[monthlyPassView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.width.height.equalTo(scrollView);
|
||||
make.right.equalTo(scrollView);
|
||||
}];
|
||||
// rewardView.hidden = YES;
|
||||
}
|
||||
|
||||
UIView *splitLine = [[UIView alloc] init];
|
||||
splitLine.backgroundColor = [UIColor clearColor];
|
||||
[mainView addSubview:splitLine];
|
||||
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(0.1);
|
||||
make.left.right.bottom.equalTo(mainView);
|
||||
make.top.equalTo(scrollView.mas_bottom).priorityLow();
|
||||
}];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)setGiftNumBlock:(void (^)(NSInteger))giftNumBlock {
|
||||
_giftNumBlock = giftNumBlock;
|
||||
self.rewardView.giftNumBlock = giftNumBlock;
|
||||
}
|
||||
|
||||
- (void)setTicketNumBlock:(void (^)(NSInteger))ticketNumBlock {
|
||||
_ticketNumBlock = ticketNumBlock;
|
||||
self.monthlyPassView.ticketNumBlock = ticketNumBlock;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
||||
// 计算偏移量更新分页控件
|
||||
NSUInteger page = scrollView.contentOffset.x / CGRectGetWidth(scrollView.bounds);
|
||||
self.pageTitleView.resetSelectedIndex = page;
|
||||
}
|
||||
|
||||
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
|
||||
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * selectedIndex, 0) animated:YES];
|
||||
}
|
||||
|
||||
- (void)setIsTicket:(BOOL)isTicket {
|
||||
if (isTicket) {
|
||||
if (self.titleArr.count > 1) {
|
||||
self.pageTitleView.resetSelectedIndex = 1;
|
||||
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * 1, 0) animated:NO];
|
||||
}
|
||||
} else {
|
||||
|
||||
self.pageTitleView.resetSelectedIndex = 0;
|
||||
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * 0, 0) animated:NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)show {
|
||||
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.mainViewConstraint uninstall];
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
self.mainViewConstraint = make.top.equalTo(self.mas_bottom).offset(-CGRectGetHeight(self.mainView.frame));
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)hide {
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.mainViewConstraint uninstall];
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
self.mainViewConstraint = make.top.equalTo(self.mas_bottom);
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// WXYZ_TickectAlertModel.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/6/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class WXYZ_TickectAlertItemsModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_TickectAlertModel : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
|
||||
@property (nonatomic, copy) NSArray<NSString *> *desc;
|
||||
|
||||
@property (nonatomic, copy) NSArray<WXYZ_TickectAlertItemsModel *> *items;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface WXYZ_TickectAlertItemsModel : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
|
||||
/// 动作 recharge去充值 exchange金币抵扣
|
||||
@property (nonatomic, copy) NSString *action;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// WXYZ_TickectAlertModel.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/6/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_TickectAlertModel.h"
|
||||
|
||||
@implementation WXYZ_TickectAlertModel
|
||||
|
||||
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
|
||||
return @{
|
||||
@"items" : WXYZ_TickectAlertItemsModel.class
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_TickectAlertItemsModel
|
||||
|
||||
@end
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// WXYZ_BookReaderBottomBar.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface WXYZ_BookReaderBottomBar : UIView
|
||||
|
||||
// 正在自动阅读
|
||||
@property (nonatomic, assign) BOOL autoReading;
|
||||
|
||||
// 显示工具栏
|
||||
- (void)showToolBar;
|
||||
|
||||
// 隐藏工具栏
|
||||
- (void)hiddenToolBar;
|
||||
|
||||
// 显示底部菜单按钮
|
||||
- (void)showMenuView;
|
||||
|
||||
// 显示自动阅读栏
|
||||
- (void)showAutoReadToolBar;
|
||||
|
||||
// 停止自动阅读
|
||||
- (void)stopAutoRead;
|
||||
|
||||
@end
|
||||
+426
@@ -0,0 +1,426 @@
|
||||
//
|
||||
// WXYZ_BookReaderBottomBar.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_BookReaderBottomBar.h"
|
||||
#import "TFSliderView.h"
|
||||
#import "WXYZ_BookReaderMenuBar.h"
|
||||
#import "WXYZ_BookReaderBottomSettingBar.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "TFWebViewController.h"
|
||||
|
||||
#define ToolBar_Normal_Height (60 + PUB_TABBAR_OFFSET)
|
||||
|
||||
#define ToolBarSettingView_Height ((50 * 4) + kHalfMargin)
|
||||
|
||||
#define ToolBarAutoReadView_Height (ToolBar_Normal_Height + 20 + kMargin)
|
||||
|
||||
#define ToolBar_Large_Height (ToolBar_Normal_Height + ToolBarSettingView_Height)
|
||||
|
||||
#define animateDuration 0.2f
|
||||
|
||||
@interface WXYZ_BookReaderBottomBar () <TFSliderViewDelegate>
|
||||
{
|
||||
// 菜单按钮
|
||||
UIView *menuView;
|
||||
|
||||
// 菜单栏设置背景
|
||||
WXYZ_BookReaderBottomSettingBar *settingBackView;
|
||||
|
||||
// 自动阅读按钮
|
||||
TFButton *autoReadButton;
|
||||
|
||||
// 分割线
|
||||
UIView *grayLine;
|
||||
|
||||
// 亮度滑块
|
||||
TFSliderView *brightnessSlider;
|
||||
|
||||
// 阅读速度滑块
|
||||
TFSliderView *autoReadSpeedSlider;
|
||||
|
||||
// 夜间模式
|
||||
UIButton *nightModeButton;
|
||||
|
||||
TFReaderSettingHelper *functionalManager;
|
||||
|
||||
TFButton *directoryButton;
|
||||
TFButton *brightnessButton;
|
||||
TFButton *fontSetButton;
|
||||
|
||||
#if TF_Comments_Mode
|
||||
TFButton *commentButton;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_BookReaderBottomBar
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
|
||||
[self initialize];
|
||||
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
functionalManager = [TFReaderSettingHelper sharedManager];
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
UIImageView *topLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, - 10, self.width, 10)];
|
||||
topLine.image = [UIImage imageNamed:@"tapbar_top_line"];
|
||||
topLine.userInteractionEnabled = YES;
|
||||
[self addSubview:topLine];
|
||||
|
||||
menuView = [[UIView alloc] init];
|
||||
menuView.backgroundColor = [UIColor whiteColor];
|
||||
[self addSubview:menuView];
|
||||
|
||||
[menuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.bottom.mas_equalTo(self.mas_bottom).offset(- PUB_TABBAR_OFFSET);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.height.mas_equalTo(ToolBar_Normal_Height - PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
|
||||
#pragma mark - 目录按钮
|
||||
directoryButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"目录") buttonImageName:@"book_menu_directory" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
directoryButton.tag = 0;
|
||||
directoryButton.graphicDistance = 5;
|
||||
directoryButton.buttonImageScale = 0.5;
|
||||
[directoryButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:directoryButton];
|
||||
|
||||
#pragma mark - 亮度
|
||||
brightnessButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"亮度") buttonImageName:@"book_menu_brightness_higher" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
brightnessButton.tag = 1;
|
||||
brightnessButton.graphicDistance = 5;
|
||||
brightnessButton.buttonImageScale = 0.5;
|
||||
[brightnessButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:brightnessButton];
|
||||
|
||||
#pragma mark - 字体设置
|
||||
fontSetButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"设置") buttonImageName:@"book_menu_setting" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
fontSetButton.tag = 2;
|
||||
fontSetButton.graphicDistance = 5.5;
|
||||
fontSetButton.buttonImageScale = 0.45;
|
||||
[fontSetButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:fontSetButton];
|
||||
|
||||
#pragma mark - 评论
|
||||
|
||||
#if TF_Comments_Mode
|
||||
commentButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"评论") buttonImageName:@"book_menu_comment_icon" buttonIndicator:TFButtonIndicatorTitleBottom];
|
||||
commentButton.tag = 3;
|
||||
commentButton.graphicDistance = 5;
|
||||
commentButton.buttonImageScale = 0.45;
|
||||
[commentButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:commentButton];
|
||||
#endif
|
||||
|
||||
NSArray *buttonMenuArr = [NSArray arrayWithObjects:directoryButton, brightnessButton, fontSetButton,
|
||||
#if TF_Comments_Mode
|
||||
commentButton,
|
||||
#endif
|
||||
nil];
|
||||
|
||||
[buttonMenuArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:(SCREEN_WIDTH / buttonMenuArr.count) leadSpacing:0 tailSpacing:0];
|
||||
[buttonMenuArr mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(8);
|
||||
make.height.mas_equalTo(menuView.mas_height).with.offset(- 16);
|
||||
}];
|
||||
|
||||
|
||||
#pragma mark - 亮度调节按钮
|
||||
brightnessSlider = [[TFSliderView alloc] initWithFrame:CGRectMake(kMargin, kMargin, SCREEN_WIDTH - 2 * kMargin, ToolBar_Normal_Height - 2 * kMargin - PUB_TABBAR_OFFSET) sliderCutPointCount:1];
|
||||
brightnessSlider.minimumValue = 0.01;
|
||||
brightnessSlider.tag = 0;
|
||||
brightnessSlider.hidden = YES;
|
||||
brightnessSlider.sliderValue = [functionalManager getBrightness];
|
||||
brightnessSlider.delegate = self;
|
||||
brightnessSlider.minimumTintColor = kMainColor;
|
||||
brightnessSlider.leftImageName = @"book_menu_brightness_lower";
|
||||
brightnessSlider.rightImageName = @"book_menu_brightness_higher";
|
||||
[self addSubview:brightnessSlider];
|
||||
|
||||
#pragma mark - 菜单栏设置背景
|
||||
settingBackView = [[WXYZ_BookReaderBottomSettingBar alloc] initWithFrame:CGRectMake(0, 0, self.width, ToolBarSettingView_Height)];
|
||||
settingBackView.hidden = YES;
|
||||
[self addSubview:settingBackView];
|
||||
|
||||
#pragma mark - 自动阅读按钮
|
||||
autoReadButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"开启自动阅读") buttonImageName:@"book_menu_auto_read_icon" buttonIndicator:TFButtonIndicatorTitleRight];
|
||||
autoReadButton.graphicDistance = 0;
|
||||
autoReadButton.buttonImageScale = 0.4;
|
||||
autoReadButton.hidden = YES;
|
||||
autoReadButton.buttonTintColor = kBlackColor;
|
||||
[autoReadButton addTarget:self action:@selector(autoReadButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:autoReadButton];
|
||||
|
||||
[autoReadButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
|
||||
make.centerX.mas_equalTo(settingBackView.mas_centerX);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.height.mas_equalTo(45);
|
||||
}];
|
||||
|
||||
// 横线
|
||||
grayLine = [[UIView alloc] init];
|
||||
grayLine.hidden = YES;
|
||||
grayLine.backgroundColor = kColorRGBA(247, 247, 247, 1);
|
||||
[self addSubview:grayLine];
|
||||
|
||||
[grayLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.bottom.mas_equalTo(autoReadButton.mas_top);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.height.mas_equalTo(5);
|
||||
}];
|
||||
|
||||
#pragma mark - 阅读速度调节
|
||||
autoReadSpeedSlider = [[TFSliderView alloc] initWithFrame:CGRectMake(kMargin, kHalfMargin, SCREEN_WIDTH - 2 * kMargin, 30) sliderCutPointCount:10];
|
||||
autoReadSpeedSlider.tag = 1;
|
||||
autoReadSpeedSlider.hidden = YES;
|
||||
autoReadSpeedSlider.stepSlider = YES;
|
||||
autoReadSpeedSlider.delegate = self;
|
||||
autoReadSpeedSlider.invertedValue = YES;
|
||||
autoReadSpeedSlider.sliderValue = 10 - [functionalManager getReadSpeed] / 5;
|
||||
autoReadSpeedSlider.leftImageName = @"book_menu_auto_read_slow";
|
||||
autoReadSpeedSlider.rightImageName = @"book_menu_auto_read_fast";
|
||||
[self addSubview:autoReadSpeedSlider];
|
||||
|
||||
nightModeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
nightModeButton.tag = 10000;
|
||||
nightModeButton.adjustsImageWhenHighlighted = NO;
|
||||
nightModeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
nightModeButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
|
||||
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
|
||||
} else {
|
||||
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
|
||||
}
|
||||
[nightModeButton addTarget:self action:@selector(nightModeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:nightModeButton];
|
||||
|
||||
[nightModeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(40);
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||||
make.bottom.mas_equalTo(menuView.mas_top).with.offset(- kMargin);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)reloadTabbar
|
||||
{
|
||||
[self removeAllSubviews];
|
||||
|
||||
[self createSubViews];
|
||||
}
|
||||
|
||||
// 菜单栏按钮点击
|
||||
- (void)toolBarButtonClick:(UIButton *)sender
|
||||
{
|
||||
switch (sender.tag) {
|
||||
case 0:// 目录
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"WXBookDirectoryViewController"];
|
||||
[self hiddenToolBar];
|
||||
break;
|
||||
case 1:// 亮度
|
||||
brightnessSlider.hidden = NO;
|
||||
break;
|
||||
case 2:// 设置
|
||||
settingBackView.hidden = NO;
|
||||
[self showLargeToolBar];
|
||||
break;
|
||||
case 3:// 评论
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFCommentsViewController"];
|
||||
[self hiddenToolBar];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[self hiddenMenuView];
|
||||
}
|
||||
|
||||
// 显示底部菜单按钮
|
||||
- (void)showMenuView
|
||||
{
|
||||
menuView.hidden = NO;
|
||||
}
|
||||
|
||||
// 隐藏底部菜单按钮
|
||||
- (void)hiddenMenuView
|
||||
{
|
||||
[self hiddenNavBar];
|
||||
menuView.hidden = YES;
|
||||
}
|
||||
|
||||
// 夜间模式
|
||||
- (void)nightModeClick:(UIButton *)sender
|
||||
{
|
||||
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
|
||||
[functionalManager setNightModeState:TFReaderPatternModeDaytime];
|
||||
[sender setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
|
||||
} else {
|
||||
[functionalManager setNightModeState:TFReaderPatternModeNight];
|
||||
[sender setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
|
||||
}
|
||||
|
||||
// 隐藏导航栏
|
||||
- (void)hiddenNavBar
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_ToolNav object:nil];
|
||||
}
|
||||
|
||||
// 显示工具栏
|
||||
- (void)showToolBar
|
||||
{
|
||||
self.hidden = NO;
|
||||
menuView.hidden = NO;
|
||||
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
|
||||
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
|
||||
} else {
|
||||
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
|
||||
}
|
||||
[UIView animateWithDuration:animateDuration animations:^{
|
||||
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBar_Normal_Height, SCREEN_WIDTH, ToolBar_Normal_Height);
|
||||
self->nightModeButton.alpha = 1;
|
||||
} completion:^(BOOL finished) {
|
||||
|
||||
}];
|
||||
|
||||
autoReadButton.buttonTitle = TFLocalizedString(@"开启自动阅读");
|
||||
[autoReadButton setNeedsLayout];
|
||||
[autoReadButton layoutIfNeeded];
|
||||
directoryButton.buttonTitle = TFLocalizedString(@"目录");
|
||||
brightnessButton.buttonTitle = TFLocalizedString(@"亮度");
|
||||
fontSetButton.buttonTitle = TFLocalizedString(@"设置");
|
||||
commentButton.buttonTitle = TFLocalizedString(@"评论");
|
||||
}
|
||||
|
||||
// 显示自动阅读栏
|
||||
- (void)showAutoReadToolBar
|
||||
{
|
||||
nightModeButton.alpha = 0;
|
||||
self.hidden = NO;
|
||||
[UIView animateWithDuration:animateDuration animations:^{
|
||||
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBarAutoReadView_Height, SCREEN_WIDTH, ToolBarAutoReadView_Height);
|
||||
} completion:^(BOOL finished) {
|
||||
self->autoReadButton.hidden = NO;
|
||||
self->autoReadSpeedSlider.hidden = NO;
|
||||
self->settingBackView.hidden = YES;
|
||||
self->grayLine.hidden = NO;
|
||||
}];
|
||||
}
|
||||
|
||||
// 显示多选工具栏
|
||||
- (void)showLargeToolBar
|
||||
{
|
||||
nightModeButton.alpha = 0;
|
||||
[UIView animateWithDuration:animateDuration animations:^{
|
||||
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBar_Large_Height, SCREEN_WIDTH, ToolBar_Large_Height);
|
||||
} completion:^(BOOL finished) {
|
||||
self->grayLine.hidden = NO;
|
||||
self->autoReadButton.hidden = NO;
|
||||
}];
|
||||
}
|
||||
|
||||
// 隐藏工具栏
|
||||
- (void)hiddenToolBar
|
||||
{
|
||||
brightnessSlider.hidden = YES;
|
||||
settingBackView.hidden = YES;
|
||||
grayLine.hidden = YES;
|
||||
autoReadButton.hidden = YES;
|
||||
autoReadSpeedSlider.hidden = YES;
|
||||
|
||||
if (_autoReading && functionalManager.state == TFReaderAutoReadStatePause) {
|
||||
[functionalManager setAutoReaderState:TFReaderAutoReadStateResume];
|
||||
}
|
||||
|
||||
[UIView animateWithDuration:animateDuration animations:^{
|
||||
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ToolBar_Normal_Height);
|
||||
self->nightModeButton.alpha = 0;
|
||||
} completion:^(BOOL finished) {
|
||||
self.hidden = YES;
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 按钮点击事件
|
||||
- (void)sliderValueEndChanged:(CGFloat)endValue slider:(TFSliderView *)sender
|
||||
{
|
||||
// 设置亮度
|
||||
if (sender.tag == 0) {
|
||||
[functionalManager setBrightness:endValue];
|
||||
|
||||
} else {// 设置阅读速度
|
||||
[functionalManager setReadSpeed:(NSInteger)((endValue + 1) * 5)];
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭自动阅读
|
||||
- (void)stopAutoRead
|
||||
{
|
||||
if (_autoReading) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"自动阅读已关闭")];
|
||||
}
|
||||
_autoReading = NO;
|
||||
[functionalManager setAutoReaderState:TFReaderAutoReadStateStop];
|
||||
autoReadButton.buttonImageName = @"book_menu_auto_read_icon";
|
||||
autoReadButton.buttonTitle = TFLocalizedString(@"开启自动阅读");
|
||||
autoReadButton.buttonTintColor = kBlackColor;
|
||||
[self hiddenToolBar];
|
||||
[self hiddenNavBar];
|
||||
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
|
||||
}
|
||||
|
||||
// 自动阅读
|
||||
- (void)autoReadButtonClick
|
||||
{
|
||||
if (_autoReading) {
|
||||
[self stopAutoRead];
|
||||
} else {
|
||||
_autoReading = YES;
|
||||
autoReadButton.buttonImageName = @"book_menu_auto_read_exit";
|
||||
autoReadButton.buttonTitle = TFLocalizedString(@"关闭自动阅读");
|
||||
autoReadButton.buttonTintColor = [UIColor colorWithRed: 241.0/255.0 green: 83.0/255.0 blue: 29.0/255.0 alpha: 1.0];
|
||||
[functionalManager setAutoReaderState:TFReaderAutoReadStateStart];
|
||||
[self hiddenToolBar];
|
||||
[self hiddenNavBar];
|
||||
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
UIView *view = [super hitTest:point withEvent:event];
|
||||
if (view == nil) {
|
||||
// 超出父视图的按钮tag值为10000
|
||||
CGPoint tempoint = [[self viewWithTag:10000] convertPoint:point fromView:self];
|
||||
if (CGRectContainsPoint([self viewWithTag:10000].bounds, tempoint)) {
|
||||
view = [self viewWithTag:10000];
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// WXYZ_BookReaderBottomSettingBar.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface WXYZ_BookReaderBottomSettingBar : UIView
|
||||
|
||||
@end
|
||||
+522
@@ -0,0 +1,522 @@
|
||||
//
|
||||
// WXYZ_BookReaderBottomSettingBar.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_BookReaderBottomSettingBar.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
|
||||
#define ToolBarSettingView_Height ((50 * 4) + kHalfMargin)
|
||||
|
||||
@implementation WXYZ_BookReaderBottomSettingBar
|
||||
{
|
||||
// 字号显示
|
||||
UILabel *fontSizeLabel;
|
||||
UIButton *decreaseFontBtn;
|
||||
UIButton *increaseFontBtn;
|
||||
|
||||
TFReaderSettingHelper *functionalManager;
|
||||
|
||||
|
||||
UIScrollView *backgroundScorll;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
functionalManager = [TFReaderSettingHelper sharedManager];
|
||||
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
CGFloat titleHeight = 50;
|
||||
CGFloat titleWidth = 50;
|
||||
CGFloat factoryButtonWidth = (SCREEN_WIDTH - titleWidth - 6 * kHalfMargin) / 4;
|
||||
CGFloat factoryButtonHeight = 30;
|
||||
|
||||
#pragma mark - 字号
|
||||
UILabel *fontTitle = [[UILabel alloc] init];
|
||||
fontTitle.text = TFLocalizedString(@"字号");
|
||||
fontTitle.textAlignment = NSTextAlignmentCenter;
|
||||
fontTitle.textColor = kGrayTextColor;
|
||||
fontTitle.font = kFont13;
|
||||
[self addSubview:fontTitle];
|
||||
|
||||
[fontTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(self.mas_top).with.offset(kHalfMargin);
|
||||
make.width.mas_equalTo(titleWidth);
|
||||
make.height.mas_equalTo(titleHeight);
|
||||
}];
|
||||
|
||||
#pragma mark - 字号减小
|
||||
|
||||
decreaseFontBtn = [self factorySettingButtonWithBackViewImageName:@"book_menu_font_sub" buttonTitle:nil tag:0 fitImageView:YES];
|
||||
decreaseFontBtn.adjustsImageWhenHighlighted = NO;
|
||||
[decreaseFontBtn addTarget:self action:@selector(fontSizeChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[decreaseFontBtn addTarget:self action:@selector(fontSizeChangeHighlighted:) forControlEvents:UIControlEventTouchDown];
|
||||
[self addSubview:decreaseFontBtn];
|
||||
|
||||
[decreaseFontBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(fontTitle.mas_right).with.offset(kHalfMargin);
|
||||
make.centerY.mas_equalTo(fontTitle.mas_centerY);
|
||||
make.width.mas_equalTo(factoryButtonWidth);
|
||||
make.height.mas_equalTo(factoryButtonHeight);
|
||||
}];
|
||||
|
||||
#pragma mark - 字号增加
|
||||
increaseFontBtn = [self factorySettingButtonWithBackViewImageName:@"book_menu_font_add" buttonTitle:nil tag:1 fitImageView:YES];
|
||||
increaseFontBtn.adjustsImageWhenHighlighted = NO;
|
||||
[increaseFontBtn addTarget:self action:@selector(fontSizeChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[increaseFontBtn addTarget:self action:@selector(fontSizeChangeHighlighted:) forControlEvents:UIControlEventTouchDown];
|
||||
[self addSubview:increaseFontBtn];
|
||||
|
||||
[increaseFontBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||||
make.centerY.mas_equalTo(decreaseFontBtn.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
if ([functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
|
||||
decreaseFontBtn.imageView.tintColor = kGrayTextColor;
|
||||
} else if ([functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
|
||||
increaseFontBtn.imageView.tintColor = kGrayTextColor;
|
||||
}
|
||||
|
||||
#pragma mark - 显示字号
|
||||
fontSizeLabel = [[UILabel alloc] init];
|
||||
fontSizeLabel.textAlignment = NSTextAlignmentCenter;
|
||||
fontSizeLabel.font = kFont15;
|
||||
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
|
||||
fontSizeLabel.textColor = kBlackColor;
|
||||
[self addSubview:fontSizeLabel];
|
||||
|
||||
[fontSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(decreaseFontBtn.mas_right);
|
||||
make.right.mas_equalTo(increaseFontBtn.mas_left);
|
||||
make.centerY.mas_equalTo(decreaseFontBtn.mas_centerY);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 字体间距
|
||||
UILabel *spaceLineTitle = [[UILabel alloc] init];
|
||||
spaceLineTitle.text = TFLocalizedString(@"间距");
|
||||
spaceLineTitle.textAlignment = NSTextAlignmentCenter;
|
||||
spaceLineTitle.textColor = kGrayTextColor;
|
||||
spaceLineTitle.font = kFont13;
|
||||
[self addSubview:spaceLineTitle];
|
||||
|
||||
[spaceLineTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(fontTitle.mas_bottom);
|
||||
make.width.mas_equalTo(titleWidth);
|
||||
make.height.mas_equalTo(titleHeight);
|
||||
}];
|
||||
|
||||
#pragma mark - 字体间距大
|
||||
UIButton *lineSpacingSmall = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_big" buttonTitle:nil tag:10 fitImageView:YES];
|
||||
[lineSpacingSmall addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:lineSpacingSmall];
|
||||
|
||||
[lineSpacingSmall mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(decreaseFontBtn.mas_left);
|
||||
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 字体间距中
|
||||
UIButton *lineSpacingMedium = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_medium" buttonTitle:nil tag:11 fitImageView:YES];
|
||||
[lineSpacingMedium addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:lineSpacingMedium];
|
||||
|
||||
[lineSpacingMedium mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(fontSizeLabel.mas_centerX);
|
||||
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 字体间距小
|
||||
UIButton *lineSpacingBig = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_small" buttonTitle:nil tag:12 fitImageView:YES];
|
||||
[lineSpacingBig addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:lineSpacingBig];
|
||||
|
||||
[lineSpacingBig mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||||
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
CGFloat t_lineSpacing = [functionalManager getReaderLinesSpacing];
|
||||
if (t_lineSpacing == line_spacing_small) {
|
||||
lineSpacingSmall.backgroundColor = kMainColor;
|
||||
lineSpacingSmall.imageView.tintColor = kWhiteColor;
|
||||
} else if (t_lineSpacing == line_spacing_medium) {
|
||||
lineSpacingMedium.backgroundColor = kMainColor;
|
||||
lineSpacingMedium.imageView.tintColor = kWhiteColor;
|
||||
} else {
|
||||
lineSpacingBig.backgroundColor = kMainColor;
|
||||
lineSpacingBig.imageView.tintColor = kWhiteColor;
|
||||
}
|
||||
|
||||
#pragma mark - 翻页
|
||||
UILabel *pageTitle = [[UILabel alloc] init];
|
||||
pageTitle.text = TFLocalizedString(@"翻页");
|
||||
pageTitle.textAlignment = NSTextAlignmentCenter;
|
||||
pageTitle.textColor = kGrayTextColor;
|
||||
pageTitle.font = kFont13;
|
||||
[self addSubview:pageTitle];
|
||||
|
||||
[pageTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(spaceLineTitle.mas_bottom);
|
||||
make.width.mas_equalTo(titleWidth);
|
||||
make.height.mas_equalTo(titleHeight);
|
||||
}];
|
||||
|
||||
#pragma mark - 仿真
|
||||
UIButton *pageCurlButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"仿真") tag:100 fitImageView:YES];
|
||||
[pageCurlButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:pageCurlButton];
|
||||
|
||||
[pageCurlButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(decreaseFontBtn.mas_left);
|
||||
make.centerY.mas_equalTo(pageTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 滚动
|
||||
UIButton *scrollButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"滑动") tag:101 fitImageView:YES];
|
||||
[scrollButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:scrollButton];
|
||||
|
||||
[scrollButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(pageCurlButton.mas_right).with.offset(7);
|
||||
make.centerY.mas_equalTo(pageTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 覆盖
|
||||
UIButton *coverButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"覆盖") tag:102 fitImageView:YES];
|
||||
[coverButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:coverButton];
|
||||
|
||||
[coverButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(scrollButton.mas_right).with.offset(7);
|
||||
make.centerY.mas_equalTo(pageTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
#pragma mark - 无效果
|
||||
UIButton *noneButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"无") tag:103 fitImageView:YES];
|
||||
[noneButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:noneButton];
|
||||
|
||||
[noneButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(coverButton.mas_right).with.offset(7);
|
||||
make.centerY.mas_equalTo(pageTitle.mas_centerY);
|
||||
make.width.mas_equalTo(decreaseFontBtn.mas_width);
|
||||
make.height.mas_equalTo(decreaseFontBtn.mas_height);
|
||||
}];
|
||||
|
||||
switch ([functionalManager getTransitionStyle]) {
|
||||
case TFReaderTransitionStylePageCurl:
|
||||
pageCurlButton.selected = YES;
|
||||
pageCurlButton.backgroundColor = kMainColor;
|
||||
break;
|
||||
case TFReaderTransitionStyleScroll:
|
||||
scrollButton.selected = YES;
|
||||
scrollButton.backgroundColor = kMainColor;
|
||||
break;
|
||||
case TFReaderTransitionStyleCover:
|
||||
coverButton.selected = YES;
|
||||
coverButton.backgroundColor = kMainColor;
|
||||
break;
|
||||
case TFReaderTransitionStyleNone:
|
||||
noneButton.selected = YES;
|
||||
noneButton.backgroundColor = kMainColor;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#pragma mark - 背景
|
||||
UILabel *backViewTitle = [[UILabel alloc] init];
|
||||
backViewTitle.text = TFLocalizedString(@"背景");
|
||||
backViewTitle.textAlignment = NSTextAlignmentCenter;
|
||||
backViewTitle.textColor = kGrayTextColor;
|
||||
backViewTitle.font = kFont13;
|
||||
[self addSubview:backViewTitle];
|
||||
|
||||
[backViewTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(pageTitle.mas_bottom);
|
||||
make.width.mas_equalTo(titleWidth);
|
||||
make.height.mas_equalTo(titleHeight);
|
||||
}];
|
||||
|
||||
#pragma mark - 背景滚动
|
||||
backgroundScorll = [[UIScrollView alloc] init];
|
||||
backgroundScorll.backgroundColor = kWhiteColor;
|
||||
backgroundScorll.showsVerticalScrollIndicator = NO;
|
||||
backgroundScorll.showsHorizontalScrollIndicator = NO;
|
||||
[self addSubview:backgroundScorll];
|
||||
|
||||
[backgroundScorll mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(decreaseFontBtn.mas_left);
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
|
||||
make.centerY.mas_equalTo(backViewTitle.mas_centerY);
|
||||
make.height.mas_equalTo(backViewTitle.mas_height);
|
||||
}];
|
||||
[backgroundScorll setNeedsLayout];
|
||||
[backgroundScorll layoutIfNeeded];
|
||||
|
||||
NSMutableArray *backgroundImageArr = [[functionalManager getReaderBackgroundColorModeArray] mutableCopy];
|
||||
[backgroundImageArr removeLastObject];
|
||||
NSUInteger buttonNum = backgroundImageArr.count;//每行多少按钮
|
||||
CGFloat button_W = factoryButtonHeight + 5; //按钮宽
|
||||
CGFloat button_H = factoryButtonHeight + 5; //按钮高
|
||||
CGFloat space_X = (CGRectGetWidth(backgroundScorll.bounds) - (button_W * buttonNum)) / (buttonNum - 1);// 按钮间距
|
||||
for (int i = 0; i < backgroundImageArr.count; i++) {
|
||||
int loc = i % buttonNum;//列号
|
||||
CGFloat button_X = (space_X + button_W) * loc;
|
||||
|
||||
UIButton *button = [self factorySettingButtonWithBackViewImageName:@"" buttonTitle:nil tag:i fitImageView:NO];
|
||||
button.tintColor = kMainColor;
|
||||
button.layer.contents = (id)[UIImage imageNamed:[[functionalManager getReaderBackgroundColorModeArray] objectAtIndex:i]].CGImage;
|
||||
button.layer.cornerRadius = 4;
|
||||
button.clipsToBounds = YES;
|
||||
button.tag = i;
|
||||
button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
button.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
[button setImageEdgeInsets:UIEdgeInsetsMake(factoryButtonHeight * 0.5, factoryButtonHeight * 0.5, 0, 0)];
|
||||
[button addTarget:self action:@selector(changeBackgroundImageClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[backgroundScorll addSubview:button];
|
||||
|
||||
[button mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(button_X);
|
||||
make.centerY.mas_equalTo(backgroundScorll.mas_centerY);
|
||||
make.width.mas_equalTo(button_W);
|
||||
make.height.mas_equalTo(button_H);
|
||||
}];
|
||||
|
||||
if (i == TFReaderBackColorWhite) {
|
||||
button.layer.borderColor = kColorRGBA(235, 235, 241, 1).CGColor;
|
||||
button.layer.borderWidth = 0.8;
|
||||
}
|
||||
|
||||
if ([functionalManager getReaderBackgroundColorMode] == i) {
|
||||
[button setImage:[[UIImage imageNamed:@"book_setting_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
}
|
||||
backgroundScorll.contentSize = CGSizeMake((button_W + kHalfMargin) * backgroundImageArr.count, 0);
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:Notification_Switch_Language object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
|
||||
fontTitle.text = TFLocalizedString(@"字号");
|
||||
spaceLineTitle.text = TFLocalizedString(@"间距");
|
||||
pageTitle.text = TFLocalizedString(@"翻页");
|
||||
pageCurlButton.titleLabel.text = TFLocalizedString(@"仿真");
|
||||
[pageCurlButton setTitle:TFLocalizedString(@"仿真") forState:UIControlStateNormal];
|
||||
scrollButton.titleLabel.text = TFLocalizedString(@"滑动");
|
||||
[scrollButton setTitle:TFLocalizedString(@"滑动") forState:UIControlStateNormal];
|
||||
coverButton.titleLabel.text = TFLocalizedString(@"覆盖");
|
||||
[coverButton setTitle:TFLocalizedString(@"覆盖") forState:UIControlStateNormal];
|
||||
noneButton.titleLabel.text = TFLocalizedString(@"无");
|
||||
[noneButton setTitle:TFLocalizedString(@"无") forState:UIControlStateNormal];
|
||||
backViewTitle.text = TFLocalizedString(@"背景");
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 点击事件
|
||||
// 改变字号
|
||||
- (void)fontSizeChangeClick:(UIButton *)sender
|
||||
{
|
||||
sender.backgroundColor = kColorRGBA(235, 235, 241, 1);
|
||||
sender.imageView.tintColor = kBlackColor;
|
||||
|
||||
CGFloat temp_font = [functionalManager getReaderFontSize];
|
||||
if (sender.tag == 0) {
|
||||
if (temp_font == [functionalManager getReaderMinFontSize]) {
|
||||
sender.imageView.tintColor = kGrayTextColor;
|
||||
return;
|
||||
}
|
||||
[functionalManager setReaderFontSize:temp_font - 1];
|
||||
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
|
||||
} else {
|
||||
if (temp_font == [functionalManager getReaderMaxFontSize]) {
|
||||
sender.imageView.tintColor = kGrayTextColor;
|
||||
return;
|
||||
}
|
||||
[functionalManager setReaderFontSize:temp_font + 1];
|
||||
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
|
||||
}
|
||||
|
||||
if ([functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
|
||||
decreaseFontBtn.imageView.tintColor = kGrayTextColor;
|
||||
} else if ([functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
|
||||
increaseFontBtn.imageView.tintColor = kGrayTextColor;
|
||||
} else {
|
||||
decreaseFontBtn.imageView.tintColor = kBlackColor;
|
||||
increaseFontBtn.imageView.tintColor = kBlackColor;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)fontSizeChangeHighlighted:(UIButton *)sender
|
||||
{
|
||||
if (sender.tag == 0 && [functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender.tag == 1 && [functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.backgroundColor = kMainColor;
|
||||
sender.imageView.tintColor = kWhiteColor;
|
||||
}
|
||||
|
||||
// 改变背景色
|
||||
- (void)changeBackgroundImageClick:(UIButton *)sender
|
||||
{
|
||||
[backgroundScorll.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj isKindOfClass:[UIButton class]]) {
|
||||
UIButton *t_btn = (UIButton *)obj;
|
||||
[t_btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
|
||||
}
|
||||
}];
|
||||
|
||||
[sender setImage:[[UIImage imageNamed:@"book_setting_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
|
||||
[functionalManager setNightModeState:TFReaderPatternModeDaytime];
|
||||
[functionalManager setReaderBackgroundColor:sender.tag];
|
||||
}
|
||||
|
||||
// 设置翻页类型
|
||||
- (void)transitionStyleChangeClick:(UIButton *)sender
|
||||
{
|
||||
for (UIView *t_view in self.subviews) {
|
||||
if ([t_view isKindOfClass:[UIButton class]] && (t_view.tag == 100 || t_view.tag == 101 || t_view.tag == 102 || t_view.tag == 103)) {
|
||||
UIButton *t_button = (UIButton *)t_view;
|
||||
t_button.backgroundColor = kColorRGBA(235, 235, 241, 1);
|
||||
t_button.selected = NO;
|
||||
}
|
||||
}
|
||||
|
||||
switch (sender.tag) {
|
||||
case 100:
|
||||
[functionalManager setTransitionStyle:TFReaderTransitionStylePageCurl];
|
||||
break;
|
||||
case 101:
|
||||
[functionalManager setTransitionStyle:TFReaderTransitionStyleScroll];
|
||||
break;
|
||||
case 102:
|
||||
[functionalManager setTransitionStyle:TFReaderTransitionStyleCover];
|
||||
break;
|
||||
case 103:
|
||||
[functionalManager setTransitionStyle:TFReaderTransitionStyleNone];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
sender.selected = YES;
|
||||
sender.backgroundColor = kMainColor;
|
||||
}
|
||||
|
||||
// 设置字间距
|
||||
- (void)lineSpacingChangeClick:(UIButton *)sender
|
||||
{
|
||||
for (UIView *t_view in self.subviews) {
|
||||
if ([t_view isKindOfClass:[UIButton class]] && (t_view.tag == 10 || t_view.tag == 11 || t_view.tag == 12)) {
|
||||
UIButton *t_button = (UIButton *)t_view;
|
||||
t_button.backgroundColor = kColorRGBA(235, 235, 241, 1);
|
||||
t_button.imageView.tintColor = kBlackColor;
|
||||
}
|
||||
}
|
||||
|
||||
switch (sender.tag) {
|
||||
case 10:
|
||||
[functionalManager setReaderLinesSpacing:line_spacing_small];
|
||||
break;
|
||||
case 11:
|
||||
[functionalManager setReaderLinesSpacing:line_spacing_medium];
|
||||
break;
|
||||
case 12:
|
||||
[functionalManager setReaderLinesSpacing:line_spacing_big];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
sender.imageView.tintColor = kWhiteColor;
|
||||
sender.backgroundColor = kMainColor;
|
||||
}
|
||||
|
||||
- (UIButton *)factorySettingButtonWithBackViewImageName:(NSString *)imageName buttonTitle:(NSString *)title tag:(NSInteger)tag fitImageView:(BOOL)fitImage
|
||||
{
|
||||
UIButton *t_factory = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
t_factory.backgroundColor = kColorRGBA(235, 235, 241, 1);
|
||||
t_factory.layer.cornerRadius = 2;
|
||||
t_factory.tag = tag;
|
||||
[t_factory.titleLabel setTextAlignment:NSTextAlignmentCenter];
|
||||
if (title.length > 0) {
|
||||
t_factory.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
|
||||
[t_factory setTitle:title forState:0];
|
||||
[t_factory.titleLabel setFont:kMainFont];
|
||||
[t_factory setTitleColor:kBlackColor forState:UIControlStateNormal];
|
||||
[t_factory setTitleColor:kWhiteColor forState:UIControlStateSelected];
|
||||
} else {
|
||||
if (imageName.length > 0) {
|
||||
t_factory.imageView.tintColor = kBlackColor;
|
||||
t_factory.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
t_factory.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
|
||||
[t_factory setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[t_factory setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateHighlighted];
|
||||
}
|
||||
if (fitImage) {
|
||||
t_factory.imageView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
} else {
|
||||
t_factory.imageView.tintColor = kMainColor;
|
||||
}
|
||||
}
|
||||
|
||||
return t_factory;
|
||||
}
|
||||
|
||||
- (void)setHidden:(BOOL)hidden {
|
||||
[super setHidden:hidden];
|
||||
if (!hidden) {
|
||||
[backgroundScorll.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj isKindOfClass:[UIButton class]]) {
|
||||
UIButton *t_btn = (UIButton *)obj;
|
||||
if ([functionalManager getReaderBackgroundColorMode] == t_btn.tag) {
|
||||
[t_btn setImage:[UIImage imageNamed:@"book_setting_select"] forState:UIControlStateNormal];
|
||||
} else {
|
||||
[t_btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// WXBookReaderToolBar.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/5/30.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface WXYZ_BookReaderMenuBar : UIView
|
||||
|
||||
interface_singleton
|
||||
|
||||
- (void)hiddend;
|
||||
|
||||
- (void)show;
|
||||
|
||||
- (void)stopAutoRead;
|
||||
|
||||
@end
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// WXBookReaderToolBar.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by Andrew on 2018/5/30.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_BookReaderMenuBar.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
|
||||
#import "WXYZ_BookReaderTopBar.h"
|
||||
#import "WXYZ_BookReaderBottomBar.h"
|
||||
|
||||
#if TF_Enable_Ai
|
||||
#import "WXYZ_TouchAssistantView.h"
|
||||
#endif
|
||||
|
||||
#define ToolBar_Normal_Height (60 + PUB_TABBAR_OFFSET)
|
||||
|
||||
@interface WXYZ_BookReaderMenuBar ()
|
||||
{
|
||||
// 导航条
|
||||
WXYZ_BookReaderTopBar *navBar;
|
||||
// 工具条
|
||||
WXYZ_BookReaderBottomBar *toolBar;
|
||||
|
||||
TFReaderSettingHelper *functionalManager;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_BookReaderMenuBar
|
||||
|
||||
implementation_singleton(WXYZ_BookReaderMenuBar)
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
|
||||
[self initialize];
|
||||
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
[kMainWindow addSubview:self];
|
||||
|
||||
self.hidden = YES;
|
||||
|
||||
functionalManager = [TFReaderSettingHelper sharedManager];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddend) name:NSNotification_Hidden_Bottom_ToolNav object:nil];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint toolBarPoint = [toolBar.layer convertPoint:[touch locationInView:self] fromLayer:self.layer];
|
||||
CGPoint navBarPoint = [navBar.layer convertPoint:[touch locationInView:self] fromLayer:self.layer];
|
||||
if (![toolBar.layer containsPoint:toolBarPoint] && ![navBar.layer containsPoint:navBarPoint]) {
|
||||
[self hiddend];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hiddend
|
||||
{
|
||||
if (functionalManager.state == TFReaderAutoReadStateStart && self.hidden) {
|
||||
[self show];
|
||||
return;
|
||||
}
|
||||
[navBar hiddenNavBarCompletion:^{
|
||||
self.hidden = YES;
|
||||
}];
|
||||
[toolBar hiddenToolBar];
|
||||
|
||||
#if TF_Enable_Ai
|
||||
[[WXYZ_TouchAssistantView sharedManager] hiddenAssistiveTouchView];
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
- (void)show
|
||||
{
|
||||
[kMainWindow bringSubviewToFront:self];
|
||||
self.hidden = NO;
|
||||
if (!toolBar.autoReading) {
|
||||
[navBar showNavBarCompletion:^{
|
||||
|
||||
}];
|
||||
[toolBar showToolBar];
|
||||
} else {
|
||||
[functionalManager setAutoReaderState:TFReaderAutoReadStatePause];
|
||||
[navBar hiddenNavBarCompletion:^{
|
||||
|
||||
}];
|
||||
[toolBar showAutoReadToolBar];
|
||||
}
|
||||
|
||||
#if TF_Enable_Ai
|
||||
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchView];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
navBar = [[WXYZ_BookReaderTopBar alloc] initWithFrame:CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT)];
|
||||
[self addSubview:navBar];
|
||||
|
||||
toolBar = [[WXYZ_BookReaderBottomBar alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ToolBar_Normal_Height)];
|
||||
[self addSubview:toolBar];
|
||||
|
||||
}
|
||||
|
||||
- (void)stopAutoRead
|
||||
{
|
||||
[toolBar stopAutoRead];
|
||||
}
|
||||
|
||||
- (void)popViewContriller
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Back object:nil];
|
||||
[self stopAutoRead];
|
||||
}
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// WXYZ_BookReaderMenuPayView.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/7/15.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface WXYZ_BookReaderMenuPayView : UIView
|
||||
|
||||
@end
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
//
|
||||
// WXYZ_BookReaderMenuPayView.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/7/15.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_BookReaderMenuPayView.h"
|
||||
#import "TFRechargeViewController.h"
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBar.h"
|
||||
|
||||
#import "TFReaderSettingHelper.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
|
||||
@interface WXYZ_BookReaderMenuPayView ()
|
||||
{
|
||||
TFReaderSettingHelper *functionalManager;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_BookReaderMenuPayView
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self initialize];
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
self.frame = CGRectMake(0, SCREEN_HEIGHT / 2 - PUB_TABBAR_OFFSET - 2 * kMargin, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
|
||||
functionalManager = [TFReaderSettingHelper sharedManager];
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
UIButton *buyBulkButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
buyBulkButton.layer.cornerRadius = 4;
|
||||
buyBulkButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
|
||||
buyBulkButton.layer.borderWidth = 0.7;
|
||||
buyBulkButton.clipsToBounds = YES;
|
||||
[buyBulkButton setTitle:TFLocalizedString(@"批量购买更优惠") forState:UIControlStateNormal];
|
||||
[buyBulkButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
|
||||
[buyBulkButton.titleLabel setFont:kMainFont];
|
||||
[buyBulkButton addTarget:self action:@selector(buyBulkButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:buyBulkButton];
|
||||
|
||||
[buyBulkButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- 2 * kMargin);
|
||||
make.left.mas_equalTo(self.mas_left).with.offset(2 * kMargin);
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- 2 * kMargin);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
|
||||
UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
buyButton.layer.cornerRadius = 4;
|
||||
buyButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
|
||||
buyButton.layer.borderWidth = 0.7;
|
||||
buyButton.clipsToBounds = YES;
|
||||
[buyButton setTitle:TFLocalizedString(@"确定购买") forState:UIControlStateNormal];
|
||||
[buyButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
|
||||
[buyButton.titleLabel setFont:kMainFont];
|
||||
[buyButton addTarget:self action:@selector(buyCurrentChapter) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:buyButton];
|
||||
|
||||
[buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(buyBulkButton.mas_top).with.offset(- 15);
|
||||
make.left.mas_equalTo(buyBulkButton.mas_left);
|
||||
make.right.mas_equalTo(buyBulkButton.mas_right);
|
||||
make.height.mas_equalTo(buyBulkButton.mas_height);
|
||||
}];
|
||||
|
||||
UILabel *titleLabel = [[UILabel alloc] init];
|
||||
titleLabel.text = TFLocalizedString(@"支持正版");
|
||||
titleLabel.textColor = [functionalManager getReaderTextColor];
|
||||
titleLabel.backgroundColor = [UIColor clearColor];
|
||||
titleLabel.font = kFont10;
|
||||
titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:titleLabel];
|
||||
|
||||
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.mas_centerX);
|
||||
make.bottom.mas_equalTo(buyButton.mas_top).with.offset( - 2 * kMargin);
|
||||
make.width.mas_equalTo(100);
|
||||
make.height.mas_equalTo(20);
|
||||
}];
|
||||
|
||||
UIView *leftLine = [[UIView alloc] init];
|
||||
leftLine.backgroundColor = [functionalManager getReaderTextColor];
|
||||
[self addSubview:leftLine];
|
||||
|
||||
[leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(titleLabel.mas_centerY);
|
||||
make.left.mas_equalTo(buyBulkButton.mas_left);
|
||||
make.right.mas_equalTo(titleLabel.mas_left).with.offset(- kHalfMargin);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
}];
|
||||
|
||||
UIView *rightLine = [[UIView alloc] init];
|
||||
rightLine.backgroundColor = [functionalManager getReaderTextColor];
|
||||
[self addSubview:rightLine];
|
||||
|
||||
[rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(titleLabel.mas_centerY);
|
||||
make.left.mas_equalTo(titleLabel.mas_right).with.offset(kHalfMargin);
|
||||
make.right.mas_equalTo(buyBulkButton.mas_right);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)buyBulkButtonClick
|
||||
{
|
||||
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
|
||||
|
||||
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
|
||||
t_model.production_id = bookManager.book_id;
|
||||
t_model.chapter_id = bookManager.chapter_id;
|
||||
|
||||
|
||||
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:t_model barType:WXYZ_BottomPayBarTypeBuyChapter productionType:TFProductionTypeNovel];
|
||||
[payBar showBottomPayBar];
|
||||
}
|
||||
|
||||
- (void)buyCurrentChapter
|
||||
{
|
||||
if (!TFUserInfoManager.isLogin) {
|
||||
[TFLoginOptionsViewController presentLoginView:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
|
||||
|
||||
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
|
||||
t_model.production_id = bookManager.book_id;
|
||||
t_model.chapter_id = bookManager.chapter_id;
|
||||
|
||||
[TFNetworkTools POST:Book_Buy_Chapter parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:bookManager.book_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:bookManager.chapter_id], @"num":@"1"} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
NSArray<NSString *> *t_arr = [requestModel.data objectForKey:@"chapter_ids"];
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"购买成功")];
|
||||
NSInteger index = [TFReaderBookManager sharedManager].currentChapterIndex;
|
||||
[TFReaderBookManager sharedManager].bookModel.chapter_list[index].is_preview = NO;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:t_arr];
|
||||
|
||||
} else if (requestModel.code == 802) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFRechargeViewController"];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// WXYZ_BookReaderTopBar.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface WXYZ_BookReaderTopBar : UIView
|
||||
|
||||
// 显示导航条
|
||||
- (void)showNavBarCompletion:(void(^)(void))completion;
|
||||
|
||||
// 隐藏导航条
|
||||
- (void)hiddenNavBarCompletion:(void(^)(void))completion;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,302 @@
|
||||
//
|
||||
// WXYZ_BookReaderTopBar.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by Andrew on 2018/6/12.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_BookReaderTopBar.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "TFShareManager.h"
|
||||
|
||||
#if TF_Download_Mode
|
||||
#import "TFNovelDownloadMenuView.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#endif
|
||||
|
||||
#if TF_Enable_Ai
|
||||
#import "WXYZ_BookAiPlayPageViewController.h"
|
||||
#import "TFAudioPlayViewController.h"
|
||||
#import "WXYZ_AudioSettingHelper.h"
|
||||
#endif
|
||||
|
||||
#import "TFReadRecordManager.h"
|
||||
|
||||
#import "WXYZ_MoreView.h"
|
||||
#import "WXYZ_GiftView.h"
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface WXYZ_BookReaderTopBar ()
|
||||
|
||||
@property (nonatomic, assign) BOOL navBarShowing;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<UIButton *> *buttonMenuArr;
|
||||
|
||||
@property (nonatomic, strong) UIButton *radioButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_BookReaderTopBar
|
||||
{
|
||||
TFReaderSettingHelper *functionalManager;
|
||||
UIButton *moreButton;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
|
||||
[self initialize];
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
functionalManager = [TFReaderSettingHelper sharedManager];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenNavBar) name:NSNotification_Hidden_ToolNav object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageSwitch) name:Notification_Switch_Language object:nil];
|
||||
}
|
||||
|
||||
- (void)languageSwitch {
|
||||
for (UIView *obj in self.subviews) {
|
||||
[obj removeFromSuperview];
|
||||
}
|
||||
[self createSubViews];
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
UIImageView *bottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, self.width, 10)];
|
||||
bottomLine.userInteractionEnabled = YES;
|
||||
bottomLine.image = [UIImage imageNamed:@"navbar_bottom_line"];
|
||||
[self addSubview:bottomLine];
|
||||
|
||||
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
button.frame = CGRectMake(0.0f, PUB_NAVBAR_HEIGHT - 64.0f, 64.0f, 64.0f);
|
||||
button.backgroundColor = [UIColor clearColor];
|
||||
button.adjustsImageWhenHighlighted = NO;
|
||||
[button.titleLabel setFont:kMainFont];
|
||||
[button setTitleColor:kBlackColor forState:UIControlStateNormal];
|
||||
[button setImage:[[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[button setImageEdgeInsets:UIEdgeInsetsMake(30, 14, 10, 26)];
|
||||
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
||||
[button setTintColor:kBlackColor];
|
||||
[button addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:button];
|
||||
|
||||
UIView *menuView = [[UIView alloc] init];
|
||||
menuView.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:menuView];
|
||||
|
||||
moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
moreButton.backgroundColor = [UIColor clearColor];
|
||||
moreButton.tintColor = kBlackColor;
|
||||
[moreButton.titleLabel setFont:kMainFont];
|
||||
[moreButton setImage:[[UIImage imageNamed:@"book_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[moreButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
|
||||
[moreButton addTarget:self action:@selector(moreEvent) forControlEvents:UIControlEventTouchUpInside];
|
||||
moreButton.imageEdgeInsets = UIEdgeInsetsMake(-10, -10, -10, -10);
|
||||
[menuView addSubview:moreButton];
|
||||
moreButton.hidden = NO;
|
||||
|
||||
#if TF_Download_Mode
|
||||
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
downloadButton.hidden = NO;
|
||||
downloadButton.adjustsImageWhenHighlighted = NO;
|
||||
downloadButton.tintColor = kBlackColor;
|
||||
[downloadButton setImage:[[UIImage imageNamed:@"public_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[downloadButton setImageEdgeInsets:UIEdgeInsetsMake(11, 11, 11, 11)];
|
||||
[downloadButton addTarget:self action:@selector(downloadButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:downloadButton];
|
||||
downloadButton.hidden = NO;
|
||||
#endif
|
||||
|
||||
//#if TF_Enable_Ai
|
||||
UIButton *radioButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.radioButton = radioButton;
|
||||
radioButton.hidden = NO;
|
||||
radioButton.adjustsImageWhenHighlighted = NO;
|
||||
radioButton.tintColor = kBlackColor;
|
||||
[radioButton setImage:[[UIImage imageNamed:@"audio_book"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[radioButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
|
||||
[radioButton addTarget:self action:@selector(radioButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:radioButton];
|
||||
radioButton.hidden = NO;
|
||||
//#endif
|
||||
|
||||
#if TF_Enable_Gift
|
||||
UIButton *giftButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
giftButton.hidden = NO;
|
||||
giftButton.adjustsImageWhenHighlighted = NO;
|
||||
giftButton.tintColor = kBlackColor;
|
||||
[giftButton setImage:[[UIImage imageNamed:@"book_gift"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[giftButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
|
||||
[giftButton addTarget:self action:@selector(giftButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[menuView addSubview:giftButton];
|
||||
#endif
|
||||
|
||||
NSMutableArray *buttonMenuArr = [NSMutableArray arrayWithObjects:
|
||||
#if TF_Download_Mode
|
||||
downloadButton,
|
||||
#endif
|
||||
moreButton,
|
||||
nil];
|
||||
self.buttonMenuArr = buttonMenuArr;
|
||||
|
||||
#if TF_Enable_Ai
|
||||
if ([TFUtilsHelper getAiReadSwitchState]) {
|
||||
[buttonMenuArr insertObject:radioButton atIndex:0];
|
||||
} else {
|
||||
radioButton.hidden = YES;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TF_Enable_Gift
|
||||
AppDelegate *app = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
|
||||
TFCheckSettingModel *model = app.checkSettingModel;
|
||||
if (TF_Enable_Gift && (model.system_setting.novel_reward_switch == 1 || model.system_setting.monthly_ticket_switch == 1)) {
|
||||
[buttonMenuArr insertObject:giftButton atIndex:0];
|
||||
giftButton.hidden = NO;
|
||||
} else {
|
||||
giftButton.hidden = YES;
|
||||
}
|
||||
#endif
|
||||
|
||||
[menuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
|
||||
make.bottom.mas_equalTo(self.mas_bottom);
|
||||
make.width.mas_equalTo(40 * buttonMenuArr.count + (buttonMenuArr.count - 1) * kHalfMargin);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
|
||||
[buttonMenuArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:0 tailSpacing:0];
|
||||
[buttonMenuArr mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(0);
|
||||
make.height.mas_equalTo(40);
|
||||
make.width.mas_equalTo(40);
|
||||
}];
|
||||
}
|
||||
|
||||
// 隐藏导航条
|
||||
- (void)hiddenNavBarCompletion:(void(^)(void))completion
|
||||
{
|
||||
if (!_navBarShowing && functionalManager.state != TFReaderAutoReadStatePause && functionalManager.state != TFReaderAutoReadStateStop) {
|
||||
return;
|
||||
}
|
||||
[functionalManager hiddenStatusBar];
|
||||
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
|
||||
self.frame = CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
|
||||
} completion:^(BOOL finished) {
|
||||
if (completion) {
|
||||
self.navBarShowing = NO;
|
||||
!completion ?: completion();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)hiddenNavBar
|
||||
{
|
||||
[self hiddenNavBarCompletion:nil];
|
||||
}
|
||||
|
||||
// 显示导航条
|
||||
- (void)showNavBarCompletion:(void(^)(void))completion
|
||||
{
|
||||
if (_navBarShowing) {
|
||||
return;
|
||||
}
|
||||
[functionalManager showStatusBar];
|
||||
[TFViewHelper setStateBarDefaultStyle];
|
||||
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
|
||||
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
|
||||
} completion:^(BOOL finished) {
|
||||
if (completion) {
|
||||
self.navBarShowing = YES;
|
||||
!completion ?: completion();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
#if TF_Download_Mode
|
||||
- (void)downloadButtonClick
|
||||
{
|
||||
TFNovelDownloadMenuView *downloadBar = [[TFNovelDownloadMenuView alloc] init];
|
||||
downloadBar.book_id = [TFUtilsHelper formatStringWithInteger:[TFReaderBookManager sharedManager].book_id];
|
||||
downloadBar.chapter_id = [TFUtilsHelper formatStringWithInteger:[TFReaderBookManager sharedManager].chapter_id];
|
||||
[kMainWindow addSubview:downloadBar];
|
||||
|
||||
[downloadBar showDownloadPayView];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TF_Enable_Ai
|
||||
- (void)radioButtonClick
|
||||
{
|
||||
if ([TFNetworkManager networkingStatus] == NO) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"听书功能仅支持在线使用")];
|
||||
return;
|
||||
}
|
||||
|
||||
TFProductionModel *bookModel = [TFReaderBookManager sharedManager].bookModel;
|
||||
TFProductionChapterModel *bookChapterModel = [[TFProductionChapterModel alloc] init];
|
||||
for (TFProductionChapterModel *t_model in bookModel.chapter_list) {
|
||||
if (t_model.chapter_id == [TFReaderBookManager sharedManager].chapter_id) {
|
||||
bookChapterModel = t_model;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WXYZ_BookAiPlayPageViewController *vc = [WXYZ_BookAiPlayPageViewController sharedManager];
|
||||
[vc loadDataWithBookModel:bookModel chapterModel:bookChapterModel];
|
||||
|
||||
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi]) {
|
||||
[vc popViewController];
|
||||
} else if (![[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
|
||||
[[TFAudioPlayViewController sharedManager] popViewController];
|
||||
UINavigationController *nav = [TFViewHelper getCurrentNavigationController];
|
||||
if ([nav.viewControllers.lastObject isKindOfClass:TFAudioDetailViewController.class]) {
|
||||
TFNavigationController *t_nav = [[TFNavigationController alloc] initWithRootViewController:vc];
|
||||
[[TFViewHelper getCurrentViewController] presentViewController:t_nav animated:YES completion:nil];
|
||||
} else {
|
||||
[[TFAudioPlayViewController sharedManager] popViewController];
|
||||
}
|
||||
|
||||
} else if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
|
||||
[[TFAudioPlayViewController sharedManager] popViewController];
|
||||
[[TFAudioPlayViewController sharedManager] popViewController];
|
||||
} else {
|
||||
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
|
||||
nav.view.tag = 2345;
|
||||
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)giftButtonClick {
|
||||
WXYZ_GiftView *mainView = [[WXYZ_GiftView alloc] initWithFrame:CGRectZero bookModel:[TFReaderBookManager sharedManager].bookModel];
|
||||
[mainView show];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
|
||||
}
|
||||
|
||||
// 返回
|
||||
- (void)popViewController
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Back object:nil];
|
||||
}
|
||||
|
||||
- (void)moreEvent {
|
||||
WXYZ_MoreView *mainView = [[WXYZ_MoreView alloc] init];
|
||||
[mainView show];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// WXYZ_MoreView.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/22.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 阅读器更多功能视图
|
||||
@interface WXYZ_MoreView : UIView
|
||||
|
||||
- (void)hide;
|
||||
|
||||
- (void)show;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,392 @@
|
||||
//
|
||||
// WXYZ_MoreView.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by LL on 2020/5/22.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_MoreView.h"
|
||||
|
||||
#import "UIView+LayoutCallback.h"
|
||||
#import "NSObject+Observer.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "TFCollectionManager.h"
|
||||
|
||||
#import "TFNovelDetailViewController.h"
|
||||
|
||||
#import "TFShareManager.h"
|
||||
|
||||
#import "TFReadRecordManager.h"
|
||||
#import "TFBookMarkModel.h"
|
||||
|
||||
#import "WXYZ_BookReaderMenuBar.h"
|
||||
|
||||
@interface WXYZ_MoreCell : UICollectionViewCell
|
||||
|
||||
- (void)setDict:(NSDictionary <NSString *, NSString *> *)dict;
|
||||
|
||||
@end
|
||||
|
||||
typedef NS_ENUM(NSInteger, ReaderBookStyle) {
|
||||
ReaderBookDetail = 0,
|
||||
ReaderBookMark,
|
||||
ReaderBookRack,
|
||||
ReaderBookShare,
|
||||
};
|
||||
|
||||
@interface WXYZ_MoreView ()<UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
@property (nonatomic, strong) NSArray<NSDictionary *> *moreDict;
|
||||
|
||||
@property (nonatomic, weak) UIView *mainView;
|
||||
|
||||
/// 背景视图
|
||||
@property (nonatomic, weak) UIView *emptyView;
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *bookModel;
|
||||
|
||||
@property (nonatomic, strong) TFReaderBookManager *bookManager;
|
||||
|
||||
/// 书签状态
|
||||
@property (nonatomic, assign) BOOL markStatus;
|
||||
|
||||
/// 书签Model
|
||||
@property (nonatomic, strong) TFBookMarkModel *markModel;
|
||||
|
||||
/// 是不是封面
|
||||
@property (nonatomic, assign) BOOL isCover;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_MoreView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize {
|
||||
self.bookModel = [TFReaderBookManager sharedManager].bookModel;
|
||||
self.bookManager = [TFReaderBookManager sharedManager];
|
||||
|
||||
// 章节内容
|
||||
NSString *chapterContent = [self.bookManager getChapterContent];
|
||||
// 页面内容
|
||||
NSString *pageContent = [self.bookManager getChapterDetailContent];
|
||||
|
||||
NSRange range = [chapterContent rangeOfString:pageContent];
|
||||
|
||||
if (self.isCover) {// 封面不能添加书签
|
||||
self.markStatus = NO;
|
||||
} else {
|
||||
// 获取当前章节所有的书签
|
||||
NSArray<TFBookMarkModel *> *markArr = [TFReadRecordManager bookMark:[TFUtilsHelper formatStringWithInteger:self.bookManager.book_id] chapterID:[TFUtilsHelper formatStringWithInteger:self.bookManager.chapter_id]];
|
||||
for (TFBookMarkModel *t_model in markArr) {
|
||||
if (t_model.specificIndex >= range.location && t_model.specificIndex < (range.location + range.length)) {
|
||||
self.markModel = t_model;
|
||||
self.markStatus = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
self.backgroundColor = kBlackTransparentColor;
|
||||
[kMainWindow addSubview:self];
|
||||
[self mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(kMainWindow);
|
||||
}];
|
||||
|
||||
UIView *emptyView = [[UIView alloc] init];
|
||||
self.emptyView = emptyView;
|
||||
emptyView.backgroundColor = [UIColor clearColor];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
||||
[emptyView addGestureRecognizer:tap];
|
||||
[self addSubview:emptyView];
|
||||
[emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self);
|
||||
}];
|
||||
|
||||
UIView *mainView = [[UIView alloc] init];
|
||||
self.mainView = mainView;
|
||||
mainView.backgroundColor = [UIColor whiteColor];
|
||||
mainView.frameBlock = ^(UIView * _Nonnull view) {
|
||||
UIBezierPath *corner = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12.0, 12.0)];
|
||||
CAShapeLayer *layer = [CAShapeLayer layer];
|
||||
layer.path = corner.CGPath;
|
||||
view.layer.mask = layer;
|
||||
};
|
||||
[self addSubview:mainView];
|
||||
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.mas_bottom);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(100 + 25 + 25 + PUB_TABBAR_HEIGHT);
|
||||
}];
|
||||
|
||||
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||
flowLayout.estimatedItemSize = CGSizeMake(62.0, 60.0f);
|
||||
CGFloat spacing = (SCREEN_WIDTH - (2 * kMargin) - (self.moreDict.count * flowLayout.estimatedItemSize.width)) / (self.moreDict.count - 1);
|
||||
spacing = spacing < kMargin ? kMargin : spacing;
|
||||
flowLayout.minimumInteritemSpacing = spacing;
|
||||
flowLayout.minimumLineSpacing = kMargin;
|
||||
|
||||
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
|
||||
collectionView.dataSource = self;
|
||||
collectionView.delegate = self;
|
||||
[collectionView registerClass:[WXYZ_MoreCell class] forCellWithReuseIdentifier:@"Identifier"];
|
||||
collectionView.backgroundColor = [UIColor clearColor];
|
||||
collectionView.showsVerticalScrollIndicator = NO;
|
||||
collectionView.showsHorizontalScrollIndicator = NO;
|
||||
[mainView addSubview:collectionView];
|
||||
[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(mainView).offset(25);
|
||||
make.left.equalTo(mainView).offset(kMargin);
|
||||
make.right.equalTo(mainView).offset(- kMargin);
|
||||
make.height.mas_equalTo(100);
|
||||
}];
|
||||
[collectionView addObserver:KEY_PATH(collectionView, contentSize) complete:^(UICollectionView * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
|
||||
CGSize size = [newVal CGSizeValue];
|
||||
[obj mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(size.height);
|
||||
}];
|
||||
}];
|
||||
|
||||
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[closeButton setTitle:TFLocalizedString(@"关闭") forState:UIControlStateNormal];
|
||||
[closeButton setTitleColor:kBlackColor forState:UIControlStateNormal];
|
||||
[closeButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET / 2, 0)];
|
||||
closeButton.titleLabel.font = kFont16;
|
||||
[mainView addSubview:closeButton];
|
||||
[closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
|
||||
make.left.width.equalTo(mainView);
|
||||
make.top.equalTo(collectionView.mas_bottom).offset(25.0f);
|
||||
}];
|
||||
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
||||
[closeButton addGestureRecognizer:tap];
|
||||
|
||||
UIView *splitLine = [[UIView alloc] init];
|
||||
splitLine.backgroundColor = kGrayLineColor;
|
||||
[mainView addSubview:splitLine];
|
||||
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(0.5);
|
||||
make.left.width.top.equalTo(closeButton);
|
||||
}];
|
||||
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)show {
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.mas_bottom).offset(- CGRectGetHeight(self.mainView.frame));
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)hide {
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.mas_bottom);
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
[self removeFromSuperview];
|
||||
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
CGPoint emptyPoint = [self convertPoint:point toView:self.mainView];
|
||||
if ([self.mainView pointInside:emptyPoint withEvent:event]) {
|
||||
return [super hitTest:point withEvent:event];
|
||||
} else {
|
||||
return self.emptyView;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
||||
return self.moreDict.count;
|
||||
}
|
||||
|
||||
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
WXYZ_MoreCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Identifier" forIndexPath:indexPath];
|
||||
[cell setDict:self.moreDict[indexPath.row].allValues.firstObject];
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
||||
NSDictionary *dict = self.moreDict[indexPath.row];
|
||||
ReaderBookStyle style = [dict.allKeys.firstObject integerValue];
|
||||
|
||||
switch (style) {
|
||||
case ReaderBookDetail:
|
||||
{
|
||||
[self hide];
|
||||
|
||||
UINavigationController *nav = [TFViewHelper getCurrentNavigationController];
|
||||
if (nav.viewControllers.count > 1) {
|
||||
UIViewController *tmp = nav.viewControllers[nav.viewControllers.count - 2];
|
||||
if ([tmp isKindOfClass:TFNovelDetailViewController.class]) {
|
||||
[nav popViewControllerAnimated:YES];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFNovelDetailViewController"];
|
||||
}
|
||||
break;
|
||||
case ReaderBookMark:
|
||||
{
|
||||
if (self.isCover) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前页不支持加书签")];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *pageContent = [self.bookManager getChapterDetailContent];
|
||||
if ([pageContent isEqualToString:@"\uFFFC"]) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前页不支持加书签")];
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *dict = nil;
|
||||
if (self.markStatus) {
|
||||
// 移除书签
|
||||
[TFReadRecordManager removeBookMark:self.markModel];
|
||||
dict = @{@(ReaderBookMark) : @{TFLocalizedString(@"添加书签") : @"book_add_mark"}};
|
||||
self.markStatus = NO;
|
||||
} else {
|
||||
// 添加书签
|
||||
self.markModel = [TFReadRecordManager addBookMark:[TFUtilsHelper formatStringWithInteger:self.bookManager.book_id] chapterID:[TFUtilsHelper formatStringWithInteger:self.bookManager.chapter_id] chapterSort:self.bookManager.currentChapterIndex chapterTitle:[self.bookManager getChapterTitle] chapterContent:[self.bookManager getChapterContent] pageContent:pageContent];
|
||||
dict = @{@(ReaderBookMark) : @{TFLocalizedString(@"取消书签") : @"book_remove_mark"}};
|
||||
self.markStatus = YES;
|
||||
}
|
||||
NSMutableArray<NSDictionary *> *arr = [NSMutableArray arrayWithArray:self.moreDict];
|
||||
[arr replaceObjectAtIndex:indexPath.row withObject:dict];
|
||||
self.moreDict = [arr copy];
|
||||
[collectionView reloadData];
|
||||
}
|
||||
break;
|
||||
case ReaderBookRack:
|
||||
{
|
||||
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) break;
|
||||
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:self.bookModel atIndex:0]) {
|
||||
|
||||
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.bookModel.production_id productionType:TFProductionTypeNovel complete:nil];
|
||||
|
||||
NSDictionary *dict = @{@(ReaderBookRack) : @{TFLocalizedString(@"已加入书架") : @"book_remove_rack"}};
|
||||
NSMutableArray<NSDictionary *> *arr = [NSMutableArray arrayWithArray:self.moreDict];
|
||||
[arr replaceObjectAtIndex:indexPath.row withObject:dict];
|
||||
self.moreDict = [arr copy];
|
||||
[collectionView reloadData];
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"添加失败")];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ReaderBookShare:
|
||||
{
|
||||
[self hide];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_ToolNav object:nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
|
||||
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.bookModel.production_id) chapter_id:NSStringFromInteger(self.bookManager.chapter_id) type:TFShareTypeBook];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
- (NSArray<NSDictionary *> *)moreDict {
|
||||
if (!_moreDict) {
|
||||
NSMutableArray<NSDictionary *> *arr = [NSMutableArray array];
|
||||
|
||||
[arr addObject:@{@(ReaderBookDetail) : @{TFLocalizedString(@"书籍详情") : @"book_detail"}}];
|
||||
if (self.markStatus) {
|
||||
[arr addObject:@{@(ReaderBookMark) : @{TFLocalizedString(@"取消书签") : @"book_remove_mark"}}];
|
||||
} else {
|
||||
[arr addObject:@{@(ReaderBookMark) : @{TFLocalizedString(@"添加书签") : @"book_add_mark"}}];
|
||||
}
|
||||
|
||||
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
|
||||
[arr addObject:@{@(ReaderBookRack) : @{TFLocalizedString(@"已加入书架") : @"book_remove_rack"}}];
|
||||
} else {
|
||||
[arr addObject:@{@(ReaderBookRack) : @{TFLocalizedString(@"加入书架") : @"book_add_rack"}}];
|
||||
}
|
||||
[arr addObject:@{@(ReaderBookShare) : @{TFLocalizedString(@"分享") : @"book_share"}}];
|
||||
|
||||
_moreDict = [arr copy];
|
||||
}
|
||||
|
||||
return _moreDict;
|
||||
}
|
||||
|
||||
- (BOOL)isCover {
|
||||
return self.bookManager.currentChapterIndex == 0 && self.bookManager.currentPagerIndex == 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_MoreCell {
|
||||
UIImageView *_coverImageView;
|
||||
UILabel *_titleLabel;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews {
|
||||
_coverImageView = [[UIImageView alloc] init];
|
||||
_coverImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
_coverImageView.clipsToBounds = YES;
|
||||
_coverImageView.userInteractionEnabled = NO;
|
||||
_coverImageView.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:_coverImageView];
|
||||
[_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.width.equalTo(self.contentView);
|
||||
make.height.equalTo(_coverImageView.mas_width);
|
||||
}];
|
||||
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.textColor = kBlackColor;
|
||||
_titleLabel.font = kFont13;
|
||||
_titleLabel.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:_titleLabel];
|
||||
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(_coverImageView.mas_bottom).offset(14.0f);
|
||||
make.centerX.equalTo(self.contentView);
|
||||
make.bottom.equalTo(self.contentView).priorityLow();
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setDict:(NSDictionary <NSString *, NSString *> *)dict {
|
||||
_coverImageView.image = [UIImage imageNamed:dict.allValues.firstObject];
|
||||
_titleLabel.text = dict.allKeys.firstObject ?: @"";
|
||||
}
|
||||
|
||||
- (UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
|
||||
[self setNeedsLayout];
|
||||
[self layoutIfNeeded];
|
||||
CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
|
||||
CGRect cellFrame = layoutAttributes.frame;
|
||||
cellFrame.size.height = size.height;
|
||||
layoutAttributes.frame = cellFrame;
|
||||
return layoutAttributes;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user