小说绘上架版本
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheDetailViewController.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/4/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFDownloadViewController.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheDetailViewController : TFDownloadViewController
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *audioModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+266
@@ -0,0 +1,266 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheDetailViewController.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/4/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_AudioDownloadCacheDetailViewController.h"
|
||||
|
||||
#import "WXYZ_AudioDownloadTableViewCell.h"
|
||||
|
||||
#import "WXYZ_AudioDownloadManager.h"
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheDetailViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_AudioDownloadCacheDetailViewController
|
||||
{
|
||||
UIButton *deleteButton;
|
||||
TFButton *selectAllButton;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
[self netRequest];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
[self setStatusBarDefaultStyle];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
[self setNavigationBarTitle:self.navTitle?:TFLocalizedString(@"选择章节")];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.mainTableView.delegate = self;
|
||||
self.mainTableView.dataSource = self;
|
||||
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
|
||||
[self.view addSubview:self.mainTableView];
|
||||
|
||||
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
|
||||
make.width.mas_equalTo(self.view.mas_width);
|
||||
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_NAVBAR_HEIGHT - PUB_TABBAR_HEIGHT);
|
||||
}];
|
||||
|
||||
selectAllButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"全选") buttonImageName:@"audio_download_unselect" buttonIndicator:TFButtonIndicatorImageLeftBothLeft];
|
||||
selectAllButton.buttonTitleColor = kBlackColor;
|
||||
selectAllButton.buttonTitleFont = kMainFont;
|
||||
selectAllButton.graphicDistance = 10;
|
||||
selectAllButton.buttonImageScale = 0.4;
|
||||
selectAllButton.tag = 0;
|
||||
selectAllButton.backgroundColor = [UIColor whiteColor];
|
||||
[selectAllButton addTarget:self action:@selector(checkallClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:selectAllButton];
|
||||
|
||||
[selectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(kMargin);
|
||||
make.top.mas_equalTo(self.mainTableView.mas_bottom);
|
||||
make.width.mas_equalTo(100);
|
||||
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
|
||||
deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
deleteButton.backgroundColor = kGrayTextLightColor;
|
||||
deleteButton.enabled = NO;
|
||||
[deleteButton setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
|
||||
[deleteButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
[deleteButton.titleLabel setFont:kMainFont];
|
||||
[deleteButton addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:deleteButton];
|
||||
|
||||
[deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.view.mas_right);
|
||||
make.top.mas_equalTo(selectAllButton.mas_top);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH / 3);
|
||||
make.height.mas_equalTo(selectAllButton.mas_height);
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return self.dataSourceArray.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
static NSString *cellName = @"WXYZ_AudioDownloadTableViewCell";
|
||||
WXYZ_AudioDownloadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_AudioDownloadTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.isCacheState = YES;
|
||||
cell.chapterModel = chapterModel;
|
||||
cell.cellDownloadState = [[self.selectSourceDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapterModel.chapter_id]] integerValue];
|
||||
cell.hiddenEndLine = self.dataSourceArray.count - 1 == indexPath.row;
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
|
||||
view.backgroundColor = kGrayViewColor;
|
||||
|
||||
UILabel *headerTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH / 2, 30)];
|
||||
headerTitleLabel.backgroundColor = [UIColor clearColor];
|
||||
headerTitleLabel.font = kFont12;
|
||||
headerTitleLabel.text = [NSString stringWithFormat:TFLocalizedString(@"共%@章"), [TFUtilsHelper formatStringWithInteger:self.dataSourceArray.count]];
|
||||
headerTitleLabel.textColor = kGrayTextColor;
|
||||
[view addSubview:headerTitleLabel];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
WXYZ_AudioDownloadTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
|
||||
|
||||
switch (cell.cellDownloadState) {
|
||||
case WXYZ_ProductionDownloadStateDownloaded:
|
||||
case WXYZ_ProductionDownloadStateNormal:
|
||||
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateSelected];
|
||||
[self reloadToolBar];
|
||||
break;
|
||||
case WXYZ_ProductionDownloadStateSelected:
|
||||
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateNormal];
|
||||
[self reloadToolBar];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)checkallClick:(TFButton *)sender
|
||||
{
|
||||
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
|
||||
|
||||
if (!sender.selected) { // 全选状态
|
||||
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateDownloaded || [[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateNormal) {
|
||||
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateSelected];
|
||||
}
|
||||
} else {
|
||||
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
|
||||
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.selected = !sender.selected;
|
||||
|
||||
[self reloadToolBar];
|
||||
}
|
||||
|
||||
- (void)deleteClick
|
||||
{
|
||||
NSMutableArray *t_deleteArr = [NSMutableArray array];
|
||||
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
|
||||
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
|
||||
[t_deleteArr addObject:t_chapter_id];
|
||||
}
|
||||
}
|
||||
|
||||
WS(weakSelf)
|
||||
[[WXYZ_AudioDownloadManager sharedManager] removeDownloadChaptersWithProduction_id:self.audioModel.production_id chapter_ids:t_deleteArr];
|
||||
[WXYZ_AudioDownloadManager sharedManager].downloadDeleteFinishBlock = ^(NSArray * _Nonnull success_chapter_ids, NSArray * _Nonnull fail_chapter) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"删除成功")];
|
||||
[weakSelf netRequest];
|
||||
};
|
||||
}
|
||||
|
||||
- (void)reloadToolBar
|
||||
{
|
||||
NSInteger selectIndex = 0;
|
||||
NSInteger downloadedIndex = 0;
|
||||
|
||||
for (NSString *t_key in self.selectSourceDictionary) {
|
||||
switch ([[self.selectSourceDictionary objectForKey:t_key] integerValue]) {
|
||||
case WXYZ_ProductionDownloadStateDownloaded:
|
||||
case WXYZ_ProductionDownloadStateNormal:
|
||||
downloadedIndex ++;
|
||||
break;
|
||||
case WXYZ_ProductionDownloadStateSelected:
|
||||
selectIndex ++;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
deleteButton.enabled = NO;
|
||||
deleteButton.backgroundColor = kGrayTextLightColor;
|
||||
|
||||
selectAllButton.selected = NO;
|
||||
selectAllButton.enabled = YES;
|
||||
selectAllButton.buttonTitle = TFLocalizedString(@"全选");
|
||||
selectAllButton.buttonImageName = @"audio_download_unselect";
|
||||
|
||||
if (selectIndex > 0 && downloadedIndex == 0) { // 有选中的文件并且没有未选中的文件
|
||||
|
||||
deleteButton.enabled = YES;
|
||||
deleteButton.backgroundColor = kMainColor;
|
||||
|
||||
selectAllButton.selected = YES;
|
||||
selectAllButton.buttonTitle = TFLocalizedString(@"取消全选");
|
||||
selectAllButton.buttonImageName = @"audio_download_select";
|
||||
|
||||
} else if (downloadedIndex > 0 && selectIndex > 0) { // 有未选中的文件
|
||||
deleteButton.enabled = YES;
|
||||
deleteButton.backgroundColor = kMainColor;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCollectionCellDownloadStateWithChapter_id:(NSInteger)chapter_id downloadState:(WXYZ_ProductionDownloadState)downloadState
|
||||
{
|
||||
WXYZ_AudioDownloadTableViewCell *cell = (WXYZ_AudioDownloadTableViewCell *)[self.mainTableView cellForRowAtIndexPath:(NSIndexPath *)[self.cellIndexDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapter_id]]];
|
||||
cell.cellDownloadState = downloadState;
|
||||
[self.selectSourceDictionary setObject:[TFUtilsHelper formatStringWithInteger:downloadState] forKey:[TFUtilsHelper formatStringWithInteger:chapter_id]];
|
||||
}
|
||||
|
||||
- (void)netRequest
|
||||
{
|
||||
self.dataSourceArray = [[[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterModelArrayWithProduction_id:self.audioModel.production_id] mutableCopy];
|
||||
|
||||
if (self.dataSourceArray.count == 0) {
|
||||
[self.navigationController popViewControllerAnimated:NO];
|
||||
return;
|
||||
}
|
||||
[self resetSelectSourceDicWithDataSourceArray:[self.dataSourceArray copy] productionType:TFProductionTypeAudio];
|
||||
|
||||
[self reloadToolBar];
|
||||
[self.mainTableView reloadData];
|
||||
}
|
||||
|
||||
@end
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/4/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^CellSelectBlock)(TFProductionModel *productionModel, NSInteger production_id, NSString *name);
|
||||
|
||||
typedef void(^ImageViewSelectBlock)(NSInteger production_id);
|
||||
|
||||
typedef void(^ButtonSelectBlock)(TFProductionModel *productionModel);
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, strong) TFProductionModel *productionModel;
|
||||
|
||||
@property (nonatomic, copy) CellSelectBlock cellSelectBlock;
|
||||
|
||||
@property (nonatomic, copy) ImageViewSelectBlock imageViewSelectBlock;
|
||||
|
||||
@property (nonatomic, copy) ButtonSelectBlock buttonSelectBlock;
|
||||
|
||||
@property (nonatomic, assign, readonly) BOOL isEditting;
|
||||
|
||||
@property (nonatomic, assign, readonly) BOOL isSelected;
|
||||
|
||||
/// 选择编辑单元
|
||||
@property (nonatomic, copy) void(^selecteEdittingCellBlock)(TFProductionModel *productionModel, BOOL isSelected);
|
||||
|
||||
- (void)setEditing:(BOOL)editing;
|
||||
|
||||
// 强行设置编辑状态
|
||||
- (void)set_Editting:(BOOL)editting;
|
||||
|
||||
// 切换选中状态
|
||||
- (void)switchSelectedState:(BOOL)state;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/4/1.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_AudioDownloadCacheTableViewCell.h"
|
||||
#import "TFReadRecordManager.h"
|
||||
#import "WXYZ_AudioDownloadManager.h"
|
||||
#import "TFProductionCoverView.h"
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheTableViewCell ()
|
||||
|
||||
@property (nonatomic, weak) UIView *mainView;
|
||||
|
||||
@property (nonatomic, weak) TFProductionCoverView *coverImageView;
|
||||
|
||||
@property (nonatomic, weak) UILabel *titleNameLabel;
|
||||
|
||||
@property (nonatomic, weak) UILabel *subTitleLabel;
|
||||
|
||||
@property (nonatomic, weak) UIButton *readButton;
|
||||
|
||||
@property (nonatomic, weak) UIImageView *selectedView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_AudioDownloadCacheTableViewCell
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapClick:)]];
|
||||
|
||||
UIView *mainView = [[UIView alloc] init];
|
||||
self.mainView = mainView;
|
||||
mainView.backgroundColor = [UIColor clearColor];
|
||||
[self.contentView addSubview:mainView];
|
||||
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.contentView);
|
||||
make.left.equalTo(self.contentView).offset(-16.0f);
|
||||
make.width.equalTo(self.contentView).offset(16.0f);
|
||||
make.height.equalTo(self.contentView);
|
||||
}];
|
||||
|
||||
UIImageView *selectedView = [[UIImageView alloc] init];
|
||||
self.selectedView = selectedView;
|
||||
selectedView.image = [UIImage imageNamed:@"audio_download_unselect"];
|
||||
[mainView addSubview:selectedView];
|
||||
[selectedView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(16.0f);
|
||||
make.left.equalTo(mainView);
|
||||
make.centerY.equalTo(mainView);
|
||||
}];
|
||||
|
||||
TFProductionCoverView *coverImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeAudio coverDirection:TFProductionCoverDirectionVertical];
|
||||
self.coverImageView = coverImageView;
|
||||
coverImageView.tag = 200;
|
||||
[coverImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapClick:)]];
|
||||
[mainView addSubview:coverImageView];
|
||||
|
||||
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(selectedView.mas_right).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(mainView.mas_top).with.offset(kQuarterMargin);
|
||||
make.width.mas_equalTo(BOOK_WIDTH_SMALL - kMargin);
|
||||
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH_SMALL - kMargin, 3, 4));
|
||||
make.bottom.mas_equalTo(mainView.mas_bottom).with.offset(- kQuarterMargin).priorityLow();
|
||||
}];
|
||||
|
||||
UILabel *titleNameLabel = [[UILabel alloc] init];
|
||||
self.titleNameLabel = titleNameLabel;
|
||||
titleNameLabel.textColor = kBlackColor;
|
||||
titleNameLabel.textAlignment = NSTextAlignmentLeft;
|
||||
titleNameLabel.font = kBoldFont14;
|
||||
titleNameLabel.numberOfLines = 0;
|
||||
[mainView addSubview:titleNameLabel];
|
||||
|
||||
[titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(coverImageView.mas_right).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(coverImageView.mas_top);
|
||||
make.right.mas_equalTo(mainView.mas_right).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
UILabel *subTitleLabel = [[UILabel alloc] init];
|
||||
self.subTitleLabel = subTitleLabel;
|
||||
subTitleLabel.textColor = kGrayTextColor;
|
||||
subTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
subTitleLabel.font = kFont12;
|
||||
subTitleLabel.numberOfLines = 0;
|
||||
[mainView addSubview:subTitleLabel];
|
||||
|
||||
[subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.mas_equalTo(titleNameLabel);
|
||||
make.bottom.mas_equalTo(coverImageView.mas_bottom);
|
||||
}];
|
||||
|
||||
UIButton *readButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.readButton = readButton;
|
||||
readButton.backgroundColor = kMainColor;
|
||||
readButton.layer.cornerRadius = 12;
|
||||
[readButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
|
||||
[readButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
[readButton.titleLabel setFont:kFont12];
|
||||
[readButton addTarget:self action:@selector(readButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[mainView addSubview:readButton];
|
||||
|
||||
[readButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(mainView.mas_right).with.offset(- kHalfMargin);
|
||||
make.centerY.mas_equalTo(mainView.mas_centerY);
|
||||
make.width.mas_equalTo(70);
|
||||
make.height.mas_equalTo(24);
|
||||
}];
|
||||
|
||||
[titleNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.readButton.mas_top).offset(-kQuarterMargin);
|
||||
}];
|
||||
|
||||
[subTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.readButton.mas_bottom).offset(kQuarterMargin);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setProductionModel:(TFProductionModel *)productionModel
|
||||
{
|
||||
_productionModel = productionModel;
|
||||
|
||||
self.coverImageView.coverImageUrl = productionModel.cover;
|
||||
|
||||
self.titleNameLabel.text = productionModel.name ? : @"";
|
||||
|
||||
self.subTitleLabel.text = [NSString stringWithFormat:TFLocalizedString(@"%@章/%@章"), [TFUtilsHelper formatStringWithInteger:[[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterCountWithProduction_id:productionModel.production_id]], [TFUtilsHelper formatStringWithInteger:productionModel.total_chapters]];
|
||||
|
||||
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapterTitleWithProduction_id:productionModel.production_id].length > 0) {
|
||||
[self.readButton setTitle:TFLocalizedString(@"继续收听") forState:UIControlStateNormal];
|
||||
} else {
|
||||
[self.readButton setTitle:TFLocalizedString(@"开始收听") forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cellTapClick:(UITapGestureRecognizer *)tap
|
||||
{
|
||||
if (_isEditting) {
|
||||
[self switchSelectedState:!_isSelected];
|
||||
return;
|
||||
}
|
||||
if (tap.view.tag == 200) {
|
||||
if (self.imageViewSelectBlock) {
|
||||
self.imageViewSelectBlock(_productionModel.production_id);
|
||||
}
|
||||
} else {
|
||||
if (self.cellSelectBlock) {
|
||||
self.cellSelectBlock(_productionModel, _productionModel.production_id, _productionModel.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)readButtonClick
|
||||
{
|
||||
if (self.buttonSelectBlock) {
|
||||
self.buttonSelectBlock(_productionModel);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)switchSelectedState:(BOOL)state {
|
||||
UIImage *image = nil;
|
||||
if (state) {
|
||||
image = [UIImage imageNamed:@"audio_download_select"];
|
||||
} else {
|
||||
image = [UIImage imageNamed:@"audio_download_unselect"];
|
||||
}
|
||||
_isSelected = state;
|
||||
self.selectedView.image = image;
|
||||
!self.selecteEdittingCellBlock ?: self.selecteEdittingCellBlock(self.productionModel, state);
|
||||
}
|
||||
|
||||
- (void)setEditing:(BOOL)editing {
|
||||
if (editing && _isEditting == NO) {
|
||||
self.readButton.hidden = editing;
|
||||
[UIView animateWithDuration:0.2 animations:^{
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(17.0f);
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
_isEditting = YES;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!editing && _isEditting == YES) {
|
||||
self.readButton.hidden = editing;
|
||||
[UIView animateWithDuration:0.2 animations:^{
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(-16.0f);
|
||||
}];
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
} completion:^(BOOL finished) {
|
||||
if (finished) {
|
||||
_isEditting = NO;
|
||||
}
|
||||
}];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)set_Editting:(BOOL)editting {
|
||||
if (editting) {
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(17.0f);
|
||||
}];
|
||||
} else {
|
||||
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.contentView).offset(-16.0f);
|
||||
}];
|
||||
}
|
||||
[self.mainView.superview layoutIfNeeded];
|
||||
_isEditting = editting;
|
||||
}
|
||||
|
||||
@end
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheViewController.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/3/21.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheViewController : TFBasicViewController
|
||||
|
||||
/// 切换编辑状态
|
||||
@property (nonatomic, copy, readonly) BOOL (^editStateBlock)(void);
|
||||
|
||||
@property (nonatomic, copy) void(^changeEditStateBlock)(BOOL status);
|
||||
|
||||
@property (nonatomic, assign) BOOL isEditting;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+421
@@ -0,0 +1,421 @@
|
||||
//
|
||||
// WXYZ_AudioDownloadCacheViewController.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/3/21.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_AudioDownloadCacheViewController.h"
|
||||
#import "WXYZ_AudioDownloadCacheDetailViewController.h"
|
||||
#import "TFAudioPlayViewController.h"
|
||||
|
||||
#import "WXYZ_AudioDownloadCacheTableViewCell.h"
|
||||
|
||||
#import "WXYZ_AudioDownloadManager.h"
|
||||
#import "TFReadRecordManager.h"
|
||||
|
||||
#import "UIView+LayoutCallback.h"
|
||||
#import "TFCollectionManager.h"
|
||||
|
||||
@interface WXYZ_AudioDownloadCacheViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
/// 编辑页面
|
||||
@property (nonatomic, weak) UIView *edittingView;
|
||||
|
||||
@property (nonatomic, weak) UIButton *edittingAll;
|
||||
|
||||
@property (nonatomic, weak) UIButton *edittingDelete;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<NSNumber *> *selectedArray;
|
||||
|
||||
@property (nonatomic, weak) CALayer *topLayer;
|
||||
|
||||
@property (nonatomic, weak) CALayer *middleLayer;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_AudioDownloadCacheViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self setStatusBarDefaultStyle];
|
||||
|
||||
self.dataSourceArray = [[[[[WXYZ_DownloadHelper sharedManager] getDownloadProductionArrayWithProductionType:TFProductionTypeAudio] reverseObjectEnumerator] allObjects] mutableCopy];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (self.dataSourceArray.count == 0) {
|
||||
[self.mainTableView xtfei_showEmptyView];
|
||||
} else {
|
||||
[self.mainTableView xtfei_hideEmptyView];
|
||||
}
|
||||
});
|
||||
|
||||
[self.mainTableView reloadData];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
self.selectedArray = [NSMutableArray array];
|
||||
// 设置编辑状态
|
||||
WS(weakSelf)
|
||||
_editStateBlock = ^() {
|
||||
BOOL isEditting = NO;
|
||||
if (weakSelf.mainTableView.visibleCells.count == 0) return NO;
|
||||
for (UITableViewCell *cell in weakSelf.mainTableView.visibleCells) {
|
||||
if ([cell isMemberOfClass:WXYZ_AudioDownloadCacheTableViewCell.class]) {
|
||||
WXYZ_AudioDownloadCacheTableViewCell *celll = (WXYZ_AudioDownloadCacheTableViewCell *)cell;
|
||||
isEditting = !celll.isEditting;
|
||||
weakSelf.isEditting = isEditting;
|
||||
// 隐藏/显示底部编辑区域
|
||||
if (isEditting) {
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[weakSelf.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(weakSelf.view);
|
||||
}];
|
||||
[weakSelf.edittingView.superview layoutIfNeeded];
|
||||
}];
|
||||
} else {
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[weakSelf.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(weakSelf.view).offset(CGRectGetHeight(weakSelf.edittingView .bounds));
|
||||
}];
|
||||
[weakSelf.edittingView.superview layoutIfNeeded];
|
||||
}];
|
||||
}
|
||||
[celll setEditing:!celll.isEditting];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return isEditting;
|
||||
};
|
||||
|
||||
[self hiddenNavigationBar:YES];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
UIView *edittingView = [[UIView alloc] init];
|
||||
self.edittingView = edittingView;
|
||||
edittingView .backgroundColor = self.view.backgroundColor;
|
||||
WS(weakSelf)
|
||||
edittingView.frameBlock = ^(UIView * _Nonnull view) {
|
||||
if (weakSelf.topLayer) return;
|
||||
CALayer *layer = [CALayer layer];
|
||||
layer.backgroundColor = kColorRGB(238, 238, 238).CGColor;
|
||||
layer.frame = CGRectMake(0, 0, CGRectGetWidth(view.bounds), 0.5);
|
||||
[view.layer addSublayer:layer];
|
||||
weakSelf.topLayer = layer;
|
||||
};
|
||||
[self.view addSubview:edittingView ];
|
||||
[edittingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.width.bottom.equalTo(self.view);
|
||||
}];
|
||||
|
||||
// 编辑状态下全选按钮
|
||||
UIButton *edittingAll = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.edittingAll = edittingAll;
|
||||
[edittingAll setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
|
||||
[edittingAll addTarget:self action:@selector(selectedAllEvent) forControlEvents:UIControlEventTouchUpInside];
|
||||
edittingAll.frameBlock = ^(UIButton * _Nonnull button) {
|
||||
if (weakSelf.middleLayer) return;
|
||||
CALayer *layer = [CALayer layer];
|
||||
layer.backgroundColor = kColorRGB(238, 238, 238).CGColor;
|
||||
layer.frame = CGRectMake(CGRectGetMaxX(button.frame), 16.0f, 0.5, CGRectGetHeight(button.bounds) - 2 * 16.0f);
|
||||
[button.layer addSublayer:layer];
|
||||
weakSelf.middleLayer = layer;
|
||||
};
|
||||
[edittingAll setTitleColor:kBlackColor forState:UIControlStateNormal];
|
||||
edittingAll.titleLabel.font = kFont14;
|
||||
[edittingView addSubview:edittingAll];
|
||||
[edittingAll mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(edittingView ).offset(1.0f);
|
||||
make.left.equalTo(edittingView );
|
||||
make.width.equalTo(edittingView ).multipliedBy(0.5f);
|
||||
make.height.equalTo(edittingAll.mas_width).multipliedBy(60.0f / 187.5f);
|
||||
make.bottom.equalTo(edittingView ).offset(-PUB_TABBAR_OFFSET).priorityLow();
|
||||
}];
|
||||
|
||||
// 编辑状态下删除按钮
|
||||
UIButton *edittingDelete = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
self.edittingDelete = edittingDelete;
|
||||
[edittingDelete setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
|
||||
[edittingDelete addTarget:self action:@selector(deleteEvent) forControlEvents:UIControlEventTouchUpInside];
|
||||
[edittingDelete setTitleColor:kGrayTextColor forState:UIControlStateNormal];
|
||||
edittingDelete.titleLabel.font = kFont14;
|
||||
[edittingView addSubview:edittingDelete];
|
||||
[edittingDelete mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.size.top.equalTo(edittingAll);
|
||||
make.left.equalTo(edittingAll.mas_right);
|
||||
}];
|
||||
|
||||
[edittingView setNeedsLayout];
|
||||
[edittingView layoutIfNeeded];
|
||||
// 设置编辑区域默认高度
|
||||
[edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.view).offset(CGRectGetHeight(edittingView .bounds));
|
||||
}];
|
||||
|
||||
self.mainTableView.delegate = self;
|
||||
self.mainTableView.dataSource = self;
|
||||
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
|
||||
[self.view addSubview:self.mainTableView];
|
||||
|
||||
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.right.equalTo(self.view);
|
||||
make.bottom.equalTo(edittingView .mas_top);
|
||||
}];
|
||||
|
||||
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"还没有下载记录") tapBlock:^{
|
||||
}];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (self.dataSourceArray.count == 0) {
|
||||
[self.mainTableView xtfei_showEmptyView];
|
||||
} else {
|
||||
[self.mainTableView xtfei_hideEmptyView];
|
||||
}
|
||||
});
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.mainTableView setEditing:NO animated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return self.dataSourceArray.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
WS(weakSelf)
|
||||
WXYZ_AudioDownloadCacheTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WXYZ_AudioDownloadCacheTableViewCell"];
|
||||
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_AudioDownloadCacheTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WXYZ_AudioDownloadCacheTableViewCell"];
|
||||
}
|
||||
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
cell.productionModel = t_model;
|
||||
[cell set_Editting:self.isEditting];
|
||||
cell.cellSelectBlock = ^(TFProductionModel * _Nonnull productionModel, NSInteger production_id, NSString * _Nonnull name) {
|
||||
productionModel.chapter_list = [[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterModelArrayWithProduction_id:production_id];
|
||||
|
||||
WXYZ_AudioDownloadCacheDetailViewController *vc = [[WXYZ_AudioDownloadCacheDetailViewController alloc] init];
|
||||
vc.audioModel = productionModel;
|
||||
vc.navTitle = name;
|
||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||
};
|
||||
cell.imageViewSelectBlock = ^(NSInteger production_id) {
|
||||
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
|
||||
vc.audio_id = production_id;
|
||||
[weakSelf.navigationController pushViewController:vc animated:YES];
|
||||
};
|
||||
cell.buttonSelectBlock = ^(TFProductionModel * _Nonnull productionModel) {
|
||||
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] moveCollectionToTopWithProductionModel:t_model];
|
||||
TFAudioPlayViewController *vc = [TFAudioPlayViewController sharedManager];
|
||||
[vc loadDataWithAudio_id:productionModel.production_id chapter_id:0];
|
||||
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
|
||||
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
|
||||
};
|
||||
|
||||
if ([self.selectedArray containsObject:@(t_model.production_id)]) {
|
||||
[cell switchSelectedState:YES];
|
||||
} else {
|
||||
[cell switchSelectedState:NO];
|
||||
}
|
||||
|
||||
cell.selecteEdittingCellBlock = ^(TFProductionModel * _Nonnull productionModel, BOOL isSelected) {
|
||||
if (isSelected) {
|
||||
[weakSelf.selectedArray addObject:@(productionModel.production_id)];
|
||||
} else {
|
||||
[weakSelf.selectedArray removeObject:@(productionModel.production_id)];
|
||||
}
|
||||
[weakSelf updateEdittingView];
|
||||
};
|
||||
|
||||
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return UITableViewCellEditingStyleDelete;
|
||||
}
|
||||
|
||||
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
return TFLocalizedString(@"删除");
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return kHalfMargin;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
[[WXYZ_AudioDownloadManager sharedManager] removeDownloadProductionWithProduction_id:t_model.production_id];
|
||||
|
||||
[self.dataSourceArray removeObject:t_model];
|
||||
[self.mainTableView reloadData];
|
||||
|
||||
if (self.dataSourceArray.count > 0) {
|
||||
[self.mainTableView xtfei_hideEmptyView];
|
||||
} else {
|
||||
[self.mainTableView xtfei_showEmptyView];
|
||||
}
|
||||
}
|
||||
|
||||
// 全选按钮点击事件
|
||||
- (void)selectedAllEvent {
|
||||
if ([self.edittingAll.titleLabel.text isEqualToString:TFLocalizedString(@"全选")]) {
|
||||
for (UITableViewCell *cell in self.mainTableView.visibleCells) {
|
||||
if ([cell isMemberOfClass:WXYZ_AudioDownloadCacheTableViewCell.class]) {
|
||||
WXYZ_AudioDownloadCacheTableViewCell *tempCell = (WXYZ_AudioDownloadCacheTableViewCell *)cell;
|
||||
[tempCell switchSelectedState:YES];
|
||||
}
|
||||
}
|
||||
|
||||
for (TFProductionModel *t_model in self.dataSourceArray) {
|
||||
if (![self.selectedArray containsObject:@(t_model.production_id)]) {
|
||||
[self.selectedArray addObject:@(t_model.production_id)];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (UITableViewCell *cell in self.mainTableView.visibleCells) {
|
||||
if ([cell isMemberOfClass:WXYZ_AudioDownloadCacheTableViewCell.class]) {
|
||||
WXYZ_AudioDownloadCacheTableViewCell *tempCell = (WXYZ_AudioDownloadCacheTableViewCell *)cell;
|
||||
[tempCell switchSelectedState:NO];
|
||||
}
|
||||
}
|
||||
|
||||
[self.selectedArray removeAllObjects];
|
||||
}
|
||||
|
||||
[self updateEdittingView];
|
||||
}
|
||||
|
||||
// 删除按钮点击事件
|
||||
- (void)deleteEvent
|
||||
{
|
||||
if (self.selectedArray.count == 0) return;
|
||||
NSMutableArray *arr = [self.dataSourceArray mutableCopy];
|
||||
NSMutableArray<NSIndexPath *> *pathArr = [NSMutableArray array];
|
||||
[arr enumerateObjectsUsingBlock:^(TFProductionModel * _Nonnull productionModel, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([self.selectedArray containsObject:@(productionModel.production_id)]) {
|
||||
[[WXYZ_AudioDownloadManager sharedManager] removeDownloadProductionWithProduction_id:productionModel.production_id];
|
||||
[self.dataSourceArray removeObject:productionModel];
|
||||
[self.selectedArray removeObject:@(productionModel.production_id)];
|
||||
[pathArr addObject:[NSIndexPath indexPathForRow:idx inSection:0]];
|
||||
}
|
||||
}];
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
[self.mainTableView performBatchUpdates:^{
|
||||
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
|
||||
} completion:^(BOOL finished) {
|
||||
if (!finished) return;
|
||||
BOOL a = !_editStateBlock ?: _editStateBlock();
|
||||
NSLog(@"%@", a?@"":@"");
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.view).offset(CGRectGetHeight(self.edittingView .bounds));
|
||||
}];
|
||||
[self.edittingView.superview layoutIfNeeded];
|
||||
}];
|
||||
!self.changeEditStateBlock ?: self.changeEditStateBlock(YES);
|
||||
}];
|
||||
} else {
|
||||
[self.mainTableView beginUpdates];
|
||||
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
|
||||
[self.mainTableView endUpdates];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL a = !_editStateBlock ?: _editStateBlock();
|
||||
NSLog(@"%@", a?@"":@"");
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
[self.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.equalTo(self.view).offset(CGRectGetHeight(self.edittingView .bounds));
|
||||
}];
|
||||
[self.edittingView.superview layoutIfNeeded];
|
||||
}];
|
||||
!self.changeEditStateBlock ?: self.changeEditStateBlock(YES);
|
||||
});
|
||||
}
|
||||
|
||||
if (self.dataSourceArray.count > 0) {
|
||||
[self.mainTableView xtfei_hideEmptyView];
|
||||
} else {
|
||||
[self.mainTableView xtfei_showEmptyView];
|
||||
}
|
||||
|
||||
self.isEditting = NO;
|
||||
[self updateEdittingView];
|
||||
}
|
||||
|
||||
// 更新底部编辑区域
|
||||
- (void)updateEdittingView
|
||||
{
|
||||
if (self.dataSourceArray.count > 0 && self.mainTableView.visibleCells.count == 0) return;
|
||||
|
||||
BOOL allSelected = YES;
|
||||
for (TFProductionModel *t_model in self.dataSourceArray) {
|
||||
if (![self.selectedArray containsObject:@(t_model.production_id)]) {
|
||||
allSelected = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allSelected) {
|
||||
[self.edittingAll setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
|
||||
} else {
|
||||
[self.edittingAll setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
if (self.selectedArray.count == 0) {
|
||||
[self.edittingDelete setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
|
||||
[self.edittingDelete setTitleColor:kGrayTextColor forState:UIControlStateNormal];
|
||||
} else {
|
||||
[self.edittingDelete setTitle:[NSString stringWithFormat:@"%@(%zd)", TFLocalizedString(@"删除"), self.selectedArray.count] forState:UIControlStateNormal];
|
||||
[self.edittingDelete setTitleColor:kRedColor forState:UIControlStateNormal];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user