小说绘上架版本
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
|
||||
Reference in New Issue
Block a user