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.
230 lines
9.4 KiB
230 lines
9.4 KiB
4 years ago
|
//
|
||
|
// TFAudioDirectoryViewCell.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/25.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFAudioDirectoryViewCell.h"
|
||
|
#import "TFReadRecordManager.h"
|
||
|
#import "WXYZ_AudioDownloadManager.h"
|
||
|
|
||
|
@interface TFAudioDirectoryViewCell ()
|
||
|
|
||
|
@property (nonatomic ,strong) UILabel *titleLabel;
|
||
|
@property (nonatomic ,strong) UIImageView *playAmountIconView;
|
||
|
@property (nonatomic ,strong) UILabel *playAmountLabel;
|
||
|
@property (nonatomic ,strong) UIImageView *updateTimeIconView;
|
||
|
@property (nonatomic ,strong) UILabel *updateTimeLabel;
|
||
|
@property (nonatomic ,strong) UIButton *downloadBtn;
|
||
|
@end
|
||
|
|
||
|
@implementation TFAudioDirectoryViewCell
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
[super createSubviews];
|
||
|
|
||
|
self.titleLabel = [[UILabel alloc] init];
|
||
|
self.titleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
self.titleLabel.textColor = kBlackColor;
|
||
|
self.titleLabel.font = kMainFont;
|
||
|
[self.contentView addSubview:self.titleLabel];
|
||
|
|
||
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||
|
make.top.mas_equalTo(self.contentView.mas_top);
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(-2 * kHalfMargin - 40);
|
||
|
make.height.mas_equalTo(kLabelHeight);
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[self.downloadBtn setAdjustsImageWhenHighlighted:NO];
|
||
|
[self.downloadBtn setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download"] forState:UIControlStateNormal];
|
||
|
[self.downloadBtn addTarget:self action:@selector(downloadBtnClick:) forControlEvents:UIControlEventTouchUpInside];
|
||
|
[self.contentView addSubview:self.downloadBtn];
|
||
|
|
||
|
[self.downloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
|
||
|
make.centerY.mas_equalTo(self.contentView.mas_centerY);
|
||
|
make.height.width.mas_equalTo(40);
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.playAmountIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_directory_readtime"]];
|
||
|
[self.contentView addSubview:self.playAmountIconView];
|
||
|
|
||
|
[self.playAmountIconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.titleLabel.mas_left);
|
||
|
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kHalfMargin);
|
||
|
make.height.mas_equalTo(12);
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kMargin).priorityLow();
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.playAmountLabel = [[UILabel alloc] init];
|
||
|
self.playAmountLabel.font = kFont11;
|
||
|
self.playAmountLabel.textColor = kGrayTextColor;
|
||
|
[self.contentView addSubview:self.playAmountLabel];
|
||
|
|
||
|
[self.playAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.playAmountIconView.mas_right).with.offset(kQuarterMargin);
|
||
|
make.centerY.mas_equalTo(self.playAmountIconView.mas_centerY);
|
||
|
make.height.mas_equalTo(self.playAmountIconView.mas_height);
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.updateTimeIconView = [[UIImageView alloc] init];
|
||
|
self.updateTimeIconView.image = [UIImage imageNamed:@"audio_directory_updatetime"];
|
||
|
[self.contentView addSubview:self.updateTimeIconView];
|
||
|
|
||
|
[self.updateTimeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.playAmountLabel.mas_right).with.offset(kHalfMargin);
|
||
|
make.centerY.mas_equalTo(self.playAmountLabel.mas_centerY);
|
||
|
make.height.mas_equalTo(self.playAmountIconView.mas_height);
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
|
||
|
|
||
|
self.updateTimeLabel = [[UILabel alloc] init];
|
||
|
self.updateTimeLabel.font = kFont11;
|
||
|
self.updateTimeLabel.textColor = kGrayTextColor;
|
||
|
[self.contentView addSubview:self.updateTimeLabel];
|
||
|
|
||
|
[self.updateTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.updateTimeIconView.mas_right).with.offset(kQuarterMargin);
|
||
|
make.right.mas_equalTo(self.downloadBtn.mas_left);
|
||
|
make.centerY.mas_equalTo(self.updateTimeIconView.mas_centerY);
|
||
|
make.height.mas_equalTo(self.updateTimeIconView.mas_height);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)setAudioDirectoryModel:(TFProductionChapterModel *)audioDirectoryModel
|
||
|
{
|
||
|
if (_audioDirectoryModel != audioDirectoryModel) {
|
||
|
|
||
|
_audioDirectoryModel = audioDirectoryModel;
|
||
|
|
||
|
self.titleLabel.text = audioDirectoryModel.chapter_title ? : @"";
|
||
|
|
||
|
if (audioDirectoryModel.play_num > 0) {
|
||
|
|
||
|
self.playAmountIconView.hidden = NO;
|
||
|
[self.playAmountIconView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(12);
|
||
|
}];
|
||
|
|
||
|
self.playAmountLabel.text = audioDirectoryModel.play_num ? : @"";
|
||
|
self.playAmountLabel.hidden = NO;
|
||
|
[self.playAmountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.playAmountLabel]);
|
||
|
}];
|
||
|
} else {
|
||
|
|
||
|
self.playAmountIconView.hidden = YES;
|
||
|
[self.playAmountIconView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.titleLabel.mas_left);
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
|
||
|
self.playAmountLabel.hidden = YES;
|
||
|
[self.playAmountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.playAmountIconView.mas_right);
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
if (audioDirectoryModel.update_time.length > 0) {
|
||
|
self.updateTimeIconView.hidden = NO;
|
||
|
[self.updateTimeIconView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(12);
|
||
|
}];
|
||
|
self.updateTimeLabel.text = audioDirectoryModel.update_time ? : @"";
|
||
|
self.updateTimeLabel.hidden = NO;
|
||
|
} else {
|
||
|
|
||
|
self.updateTimeIconView.hidden = YES;
|
||
|
[self.updateTimeIconView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
|
||
|
self.updateTimeLabel.hidden = YES;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] isCurrentPlayingChapterWithProduction_id:audioDirectoryModel.production_id chapter_id:audioDirectoryModel.chapter_id] &&
|
||
|
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] isCurrentPlayingProductionWithProduction_id:audioDirectoryModel.production_id]) {
|
||
|
|
||
|
self.titleLabel.textColor = kMainColor;
|
||
|
|
||
|
} else if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] chapterHasReadedWithProduction_id:audioDirectoryModel.production_id chapter_id:audioDirectoryModel.chapter_id]) {
|
||
|
|
||
|
self.titleLabel.textColor = kGrayTextColor;
|
||
|
} else {
|
||
|
self.titleLabel.textColor = kBlackColor;
|
||
|
}
|
||
|
|
||
|
[self changeDownloadButtonState];
|
||
|
}
|
||
|
|
||
|
- (void)setCellDownloadState:(WXYZ_ProductionDownloadState)cellDownloadState
|
||
|
{
|
||
|
if (_cellDownloadState != cellDownloadState) {
|
||
|
_cellDownloadState = cellDownloadState;
|
||
|
|
||
|
[self changeDownloadButtonState];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)changeDownloadButtonState
|
||
|
{
|
||
|
switch (_cellDownloadState) {
|
||
|
case WXYZ_ProductionDownloadStateNormal: {
|
||
|
if (self.audioDirectoryModel.is_preview == 1) {
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:TFLocalizedString(@"audio_download_vip")] forState:UIControlStateNormal];
|
||
|
} else {
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download"] forState:UIControlStateNormal];
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case WXYZ_ProductionDownloadStateDownloading: {
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_downloading"] forState:UIControlStateNormal];
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case WXYZ_ProductionDownloadStateDownloaded: {
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_downloaded"] forState:UIControlStateNormal];
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case WXYZ_ProductionDownloadStateFail: {
|
||
|
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download_fail"] forState:UIControlStateNormal];
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)downloadBtnClick:(UIButton *)sender
|
||
|
{
|
||
|
if (([[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:self.audioDirectoryModel.production_id chapter_id:self.audioDirectoryModel.chapter_id] == WXYZ_ProductionDownloadStateDownloading) || ([[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:self.audioDirectoryModel.production_id chapter_id:self.audioDirectoryModel.chapter_id] == WXYZ_ProductionDownloadStateDownloaded)) {
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (self.downloadChapterBlock) {
|
||
|
self.downloadChapterBlock(self.audioDirectoryModel.production_id, self.audioDirectoryModel.chapter_id, self.index);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|