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.
157 lines
5.3 KiB
157 lines
5.3 KiB
4 years ago
|
//
|
||
|
// TFNovelDownloadMenuCell.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/16.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFNovelDownloadMenuCell.h"
|
||
|
|
||
|
@interface TFNovelDownloadMenuCell ()
|
||
|
{
|
||
|
UILabel *chapterLabel;
|
||
|
UILabel *tagView;
|
||
|
UILabel *downloadStateLabel;
|
||
|
|
||
|
UIActivityIndicatorView *activityIndicator;
|
||
|
}
|
||
|
@end
|
||
|
|
||
|
@implementation TFNovelDownloadMenuCell
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
[super createSubviews];
|
||
|
|
||
|
chapterLabel = [[UILabel alloc] init];
|
||
|
chapterLabel.textColor = kBlackColor;
|
||
|
chapterLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
chapterLabel.font = kFont12;
|
||
|
[self.contentView addSubview:chapterLabel];
|
||
|
|
||
|
[chapterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||
|
make.top.mas_equalTo(self.contentView.mas_top);
|
||
|
make.height.mas_equalTo(40);
|
||
|
make.width.mas_equalTo(100);
|
||
|
}];
|
||
|
|
||
|
tagView = [[UILabel alloc] init];
|
||
|
tagView.hidden = YES;
|
||
|
tagView.textColor = kWhiteColor;
|
||
|
tagView.textAlignment = NSTextAlignmentCenter;
|
||
|
tagView.font = kFont8;
|
||
|
tagView.backgroundColor = kRedColor;
|
||
|
tagView.layer.cornerRadius = 4;
|
||
|
tagView.clipsToBounds = YES;
|
||
|
[self.contentView addSubview:tagView];
|
||
|
|
||
|
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(chapterLabel.mas_right);
|
||
|
make.centerY.mas_equalTo(chapterLabel.mas_centerY);
|
||
|
make.width.mas_equalTo(50);
|
||
|
make.height.mas_equalTo(15);
|
||
|
}];
|
||
|
|
||
|
downloadStateLabel = [[UILabel alloc] init];
|
||
|
downloadStateLabel.hidden = YES;
|
||
|
downloadStateLabel.textColor = kGrayTextLightColor;
|
||
|
downloadStateLabel.textAlignment = NSTextAlignmentRight;
|
||
|
downloadStateLabel.font = kFont12;
|
||
|
downloadStateLabel.backgroundColor = [UIColor clearColor];
|
||
|
[self.contentView addSubview:downloadStateLabel];
|
||
|
|
||
|
[downloadStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||
|
make.top.mas_equalTo(0);
|
||
|
make.width.mas_equalTo(100);
|
||
|
make.height.mas_equalTo(40);
|
||
|
}];
|
||
|
|
||
|
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
|
||
|
activityIndicator.hidesWhenStopped = YES;
|
||
|
[self.contentView addSubview:activityIndicator];
|
||
|
//设置小菊花的frame
|
||
|
[activityIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||
|
make.centerY.mas_equalTo(self.contentView.mas_centerY);
|
||
|
make.height.width.mas_equalTo(20);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)startDownloadLoading
|
||
|
{
|
||
|
[activityIndicator startAnimating];
|
||
|
}
|
||
|
|
||
|
- (void)setOptionModel:(TFDownloadTaskModel *)optionModel
|
||
|
{
|
||
|
_optionModel = optionModel;
|
||
|
chapterLabel.text = optionModel.label?:@"";
|
||
|
[chapterLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:40 labelText:optionModel.label?:@""]);
|
||
|
}];
|
||
|
|
||
|
if (optionModel.tag && optionModel.tag.length > 0) {
|
||
|
tagView.hidden = NO;
|
||
|
tagView.text = optionModel.tag;
|
||
|
[tagView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont8 labelHeight:15 labelText:optionModel.tag]);
|
||
|
}];
|
||
|
} else {
|
||
|
tagView.hidden = YES;
|
||
|
}
|
||
|
|
||
|
chapterLabel.textColor = kBlackColor;
|
||
|
downloadStateLabel.hidden = YES;
|
||
|
self.userInteractionEnabled = YES;
|
||
|
|
||
|
switch ([[WXYZ_BookDownloadManager sharedManager] getDownloadMissionStateWithProduction_id:self.book_id downloadTaskModel:optionModel]) {
|
||
|
case WXYZ_ProductionDownloadStateDownloading:
|
||
|
chapterLabel.textColor = kGrayTextLightColor;
|
||
|
downloadStateLabel.hidden = NO;
|
||
|
downloadStateLabel.text = TFLocalizedString(@"正在下载");
|
||
|
self.userInteractionEnabled = NO;
|
||
|
break;
|
||
|
case WXYZ_ProductionDownloadStateDownloaded:
|
||
|
chapterLabel.textColor = kGrayTextLightColor;
|
||
|
downloadStateLabel.hidden = NO;
|
||
|
downloadStateLabel.text = TFLocalizedString(@"已下载");
|
||
|
self.userInteractionEnabled = NO;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setMissionState:(WXYZ_DownloadMissionState)missionState
|
||
|
{
|
||
|
_missionState = missionState;
|
||
|
|
||
|
[activityIndicator stopAnimating];
|
||
|
|
||
|
switch (missionState) {
|
||
|
case WXYZ_DownloadStateMissionStart:
|
||
|
chapterLabel.textColor = kGrayTextLightColor;
|
||
|
downloadStateLabel.hidden = NO;
|
||
|
downloadStateLabel.text = TFLocalizedString(@"正在下载");
|
||
|
self.userInteractionEnabled = NO;
|
||
|
break;
|
||
|
case WXYZ_DownloadStateMissionFinished:
|
||
|
chapterLabel.textColor = kGrayTextLightColor;
|
||
|
downloadStateLabel.hidden = NO;
|
||
|
downloadStateLabel.text = TFLocalizedString(@"已下载");
|
||
|
self.userInteractionEnabled = NO;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
chapterLabel.textColor = kBlackColor;
|
||
|
downloadStateLabel.hidden = YES;
|
||
|
self.userInteractionEnabled = YES;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|