You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.8 KiB

//
// TFTaskHeaderView.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/3.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFTaskHeaderView.h"
#import "WXYZ_TaskModel.h"
#import "TFSignModel.h"
#import "TFSignAlertView.h"
@interface TFTaskHeaderView ()
@property (nonatomic ,strong) UILabel *signLabel;
@property (nonatomic ,strong) UIButton *signBtn;
@property (nonatomic ,strong) UILabel *promptLabel;
@end
@implementation TFTaskHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
NSMutableAttributedString *t_atr = [[NSMutableAttributedString alloc] initWithString:TFLocalizedString(@"您已连续签到") attributes:@{NSFontAttributeName : kBoldFont19, NSForegroundColorAttributeName : kBlackColor}];
t_atr.lineSpacing = kQuarterMargin;
UIImageView *signImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kGeometricWidth(50, 196, 276), 50.0)];
signImageView.backgroundColor = kMainColor;
signImageView.layer.cornerRadius = 8.5;
signImageView.layer.masksToBounds = YES;
self.signLabel = [[UILabel alloc] init];
self.signLabel.text = @"0";
self.signLabel.backgroundColor = [UIColor clearColor];
self.signLabel.font = kBoldFont27;
self.signLabel.textColor = kWhiteColor;
[signImageView addSubview:self.signLabel];
[self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(signImageView);
}];
NSMutableAttributedString *attributeView = [NSMutableAttributedString attachmentStringWithContent:signImageView contentMode:UIViewContentModeBottom attachmentSize:CGSizeMake(kGeometricWidth(50, 196, 276) + 10, 50.0) alignToFont : kBoldFont19 alignment:YYTextVerticalAlignmentCenter];
[t_atr appendAttributedString:attributeView];
[t_atr appendAttributedString:[[NSAttributedString alloc] initWithString:TFLocalizedString(@"天") attributes:@{NSFontAttributeName : kBoldFont19, NSForegroundColorAttributeName : kBlackColor}]];
YYLabel *signLabel = [[YYLabel alloc] init];
signLabel.backgroundColor = [UIColor clearColor];
signLabel.numberOfLines = 0;
signLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 120.0 - kMargin;
signLabel.attributedText = t_atr;
[self addSubview:signLabel];
[signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(kMargin);
make.centerY.equalTo(self);
make.width.mas_equalTo(signLabel.preferredMaxLayoutWidth);
}];
self.signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.signBtn.userInteractionEnabled = NO;
[self.signBtn setImage:[UIImage imageNamed:TFLocalizedString(@"task_unsign")] forState:UIControlStateNormal];
[self.signBtn addTarget:self action:@selector(signClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.signBtn];
[self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right);
make.centerY.mas_equalTo(self.mas_centerY);
make.width.height.mas_equalTo(120);
}];
self.promptLabel = [[UILabel alloc] init];
self.promptLabel.font = kFont10;
self.promptLabel.textColor = kGrayTextLightColor;
self.promptLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.promptLabel];
[self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(signLabel.mas_left);
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- kHalfMargin);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(20);
}];
}
- (void)setSignInfoModel:(WXYZ_SignInfoModel *)signInfoModel
{
_signInfoModel = signInfoModel;
if (signInfoModel.sign_status == 0) {
[self.signBtn setImage:[UIImage imageNamed:TFLocalizedString(@"task_unsign")] forState:UIControlStateNormal];
self.signBtn.userInteractionEnabled = YES;
} else {
[self.signBtn setImage:[UIImage imageNamed:TFLocalizedString(@"task_signed")] forState:UIControlStateNormal];
self.signBtn.userInteractionEnabled = NO;
}
self.signLabel.text = [TFUtilsHelper formatStringWithInteger:signInfoModel.sign_days];
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@%@", TFLocalizedString(@"提示:"), TFLocalizedString(@"连续签到最高可获得"), [TFUtilsHelper formatStringWithInteger:signInfoModel.max_award], signInfoModel.unit?:TFSystemInfoManager.masterUnit]];
NSString *suffix = [NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:signInfoModel.max_award], signInfoModel.unit?:TFSystemInfoManager.masterUnit];
[attributedStr addAttribute:NSForegroundColorAttributeName value:kColorRGBA(251, 100, 26, 1) range:NSMakeRange(attributedStr.length - suffix.length, suffix.length)];
self.promptLabel.attributedText = attributedStr;
}
- (void)signClick
{
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Sign_Click parameters:nil model:TFSignModel.class success:^(BOOL isSuccess, TFSignModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
if ((t_model.book.count > 0 || t_model.comic.count > 0) && t_model.award.length > 0 && t_model.tomorrow_award.length > 0) {
NSMutableArray *t_arr = [NSMutableArray array];
for (TFProductionModel *t in t_model.book) {
t.productionType = TFProductionTypeNovel;
[t_arr addObject:t];
}
for (TFProductionModel *t in t_model.comic) {
t.productionType = TFProductionTypeComic;
[t_arr addObject:t];
}
for (TFProductionModel *t in t_model.audio) {
t.productionType = TFProductionTypeAudio;
[t_arr addObject:t];
}
TFSignAlertView *alert = [[TFSignAlertView alloc] init];
alert.alertTitle = t_model.award;
alert.alertDetailContent = t_model.tomorrow_award;
alert.bookList = [t_arr copy];
[alert showAlertView];
}
!weakSelf.signClickBlock ?: weakSelf.signClickBlock();
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
}
} failure:nil];
}
@end