小说绘上架版本

This commit is contained in:
xtfei2011
2021-02-07 11:24:08 +08:00
commit ee5c1c8b12
1762 changed files with 115892 additions and 0 deletions
@@ -0,0 +1,20 @@
//
// TFSearchViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFSearchViewController : TFBasicViewController
@property (nonatomic ,strong) NSString *placeholder;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,367 @@
//
// TFSearchViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSearchViewController.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFProductionListViewCell.h"
#import "TFHotspotSearchView.h"
#import "TFSearchBar.h"
#import "TFBookStoreLabelModel.h"
#import "TFSearchModel.h"
@interface TFSearchViewController ()<UITableViewDelegate, UITableViewDataSource, TFSearchBarDelegate>
@property (nonatomic ,strong) TFHotspotSearchView *hotspotSearchView;
@property (nonatomic ,strong) TFBookStoreLabelModel *labelModel;
@property (nonatomic ,strong) TFSearchBar *searchBar;
@property (nonatomic ,assign) BOOL inSearchState;
@property (nonatomic ,strong) NSString *searchStr;
@end
@implementation TFSearchViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Show_Tabbar object:nil];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)createSubviews
{
self.searchBar = [[TFSearchBar alloc] initWithFrame:CGRectMake(5, PUB_NAVBAR_OFFSET + 25, SCREEN_WIDTH - 2 * 5, 40)];
self.searchBar.placeholderText = self.placeholder ?: TFLocalizedString(@"搜索您感兴趣的书籍");
self.searchBar.backgroundColor = [UIColor clearColor];
self.searchBar.delegate = self;
[self.view addSubview:self.searchBar];
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 + kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - kHalfMargin);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"未搜索到相关内容") buttonTitle:nil tapBlock:^{
}];
WS(weakSelf)
self.hotspotSearchView = [[TFHotspotSearchView alloc] init];
self.hotspotSearchView.bookClickBlock = ^(NSString *hotspotBook) {
weakSelf.searchBar.searchText = hotspotBook;
[weakSelf searchButtonClickedWithSearchText:hotspotBook];
};
[self.mainTableView setTableHeaderView:self.hotspotSearchView];
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[weakSelf netRequest];
}];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
[self.mainTableView hideRefreshHeader];
[self.mainTableView hideRefreshFooter];
[self.mainTableView titleLabel].hidden = YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.inSearchState ? self.dataSourceArray.count : self.labelModel ? 1 : 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
if (self.inSearchState) {
static NSString *cellName = @"TFProductionListViewCell";
TFProductionListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFProductionListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.productionType = self.productionType;
cell.productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
return cell;
} else {
static NSString *cellName = @"TFBookStoreNovelStyleTwoCell";
TFBookStoreNovelStyleTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleTwoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
switch (weakSelf.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *novelDetail = [[TFNovelDetailViewController alloc] init];
novelDetail.book_id = production_id;
[weakSelf.navigationController pushViewController:novelDetail animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *comicDetail = [[TFComicDetailViewController alloc] init];
comicDetail.comic_id = production_id;
[weakSelf.navigationController pushViewController:comicDetail animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *audioDetail = [[TFAudioDetailViewController alloc] init];
audioDetail.audio_id = production_id;
[weakSelf.navigationController pushViewController:audioDetail animated:YES];
}
break;
#endif
default:
break;
}
};
cell.labelModel = self.labelModel;
return cell;
}
}
- (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 didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.inSearchState) {
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.searchBar searchBarResignFirstResponder];
}
- (void)cancelButtonClicked
{
if (self.searchStr.length > 0) {
self.searchBar.searchText = @"";
[self.searchBar resignFirstResponder];
[self searchBarCleanText];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)searchButtonClickedWithSearchText:(NSString *)searchText
{
self.currentPageNumber = 1;
self.inSearchState = YES;
self.searchStr = searchText;
[self searchNetRequest];
}
- (void)searchBarCleanText
{
self.currentPageNumber = 1;
self.inSearchState = NO;
self.searchStr = @"";
self.hotspotSearchView.hidden = NO;
[self.hotspotSearchView setNormalFrame];
[self.mainTableView reloadData];
[self.mainTableView xtfei_startLoading];
[self.mainTableView hideRefreshFooter];
[self.mainTableView hideRefreshHeader];
[self.mainTableView titleLabel].hidden = YES;
}
- (void)searchNetRequest
{
// if ([self.searchStr isEqualToString:TFLocalizedString(@" 切换至测试版 ")]) {
// [[NSNotificationCenter defaultCenter] postNotificationName:Notification_Review_State object:@"1"];
// return;
// }
//
// if ([self.searchStr isEqualToString:TFLocalizedString(@" 强行切换至测试版 ")]) {
//#ifdef Notification_Force_Review_State
// [[NSNotificationCenter defaultCenter] postNotificationName:Notification_Force_Review_State object:@"1"];
//#else
// [[NSNotificationCenter defaultCenter] postNotificationName:@"mDidForceChangeMagicState" object:@"1"];
//#endif
// return;
// }
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Search_List;
break;
case TFProductionTypeComic:
url = Comic_Search_List;
break;
case TFProductionTypeAudio:
url = Audio_Search_List;
break;
default:
break;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"keyword"] = self.searchStr;
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
weakSelf.hotspotSearchView.hidden = YES;
weakSelf.hotspotSearchView.frame = CGRectMake(0, 0, 0.1, 0.1);
// [weakSelf.mainTableView showRefreshHeader];
// [weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
- (void)netRequest
{
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Search;
break;
case TFProductionTypeComic:
url = Comic_Search;
break;
case TFProductionTypeAudio:
url = Audio_Search;
break;
default:
break;
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:nil model:TFSearchModel.class success:^(BOOL isSuccess, TFSearchModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
for (TFProductionModel *tt_model in t_model.list) {
tt_model.productionType = weakSelf.productionType;
}
weakSelf.hotspotSearchView.hotspotBookArray = t_model.hot_word;
// if (t_model.hot_word.count > 0) {
// weakSelf.searchBar.placeholderText = [t_model.hot_word objectOrNilAtIndex:(arc4random() % (t_model.hot_word.count - 1))];
// } else {
// weakSelf.searchBar.placeholderText = TFLocalizedString(@"搜索您感兴趣的书籍");
// }
weakSelf.labelModel = [[TFBookStoreLabelModel alloc] init];
weakSelf.labelModel.list = t_model.list;
weakSelf.labelModel.label = TFLocalizedString(@"热搜榜");
weakSelf.labelModel.style = 2;
}
[weakSelf.mainTableView reloadData];
} failure:nil];
}
@end
@@ -0,0 +1,21 @@
//
// TFSearchModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel;
@interface TFSearchModel : NSObject
@property (nonatomic ,strong) NSArray<TFProductionModel *> *list;
@property (nonatomic ,strong) NSArray<NSString *> *hot_word;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// TFSearchModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSearchModel.h"
@implementation TFSearchModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"list" : [TFProductionModel class]};
}
@end
@@ -0,0 +1,26 @@
//
// TFHotspotSearchView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^HotspotBookClickBlock)(NSString *hotspotBook);
@interface TFHotspotSearchView : UIView
@property (nonatomic ,strong) NSArray *hotspotBookArray;
@property (nonatomic ,copy) HotspotBookClickBlock bookClickBlock;
- (void)setSmallFrame;
- (void)setNormalFrame;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,129 @@
//
// TFHotspotSearchView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/24.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFHotspotSearchView.h"
@interface TFHotspotSearchView ()
@property (nonatomic ,assign) CGRect hotspotSearchViewFrame;
@end
@implementation TFHotspotSearchView
- (instancetype)init
{
if (self = [super init]) {
}
return self;
}
- (void)setHotspotBookArray:(NSArray *)hotspotBookArray
{
_hotspotBookArray = hotspotBookArray;
UILabel *headTitle = [[UILabel alloc] init];
headTitle.textColor = kGrayTextColor;
headTitle.backgroundColor = [UIColor clearColor];
headTitle.text = TFLocalizedString(@"热门搜索");
headTitle.font = kFont12;
[self addSubview:headTitle];
[headTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(kHalfMargin + 5);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(20);
}];
int buttonNum = 2; // 每行多少按钮
CGFloat button_W = SCREEN_WIDTH / 2; // 按钮宽
CGFloat margin_Y = 2 * kMargin; // 第一个按钮的Y坐标
CGFloat button_H = 35; // 按钮高
CGFloat button_Y = 0;
for (int i = 0; i < hotspotBookArray.count; i++) {
int row = i / buttonNum; // 行号
int loc = i % buttonNum; // 列号
CGFloat button_X = button_W * loc;
button_Y = margin_Y + button_H * row;
UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
bottomButton.frame = CGRectMake(button_X, button_Y, button_W, button_H);
bottomButton.backgroundColor = [UIColor clearColor];
bottomButton.tag = i;
[bottomButton addTarget:self action:@selector(hotspotBookClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:bottomButton];
UILabel *indexLabel = [[UILabel alloc] init];
indexLabel.backgroundColor = kColorRGBA(203, 204, 204, 1);
indexLabel.text = [NSString stringWithFormat:@"%d", i + 1];
indexLabel.font = kFont8;
indexLabel.layer.cornerRadius = 2;
indexLabel.clipsToBounds = YES;
indexLabel.textColor = [UIColor whiteColor];
indexLabel.textAlignment = NSTextAlignmentCenter;
[bottomButton addSubview:indexLabel];
switch (i) {
case 0:
indexLabel.backgroundColor = kColorRGBA(227, 58, 52, 1);
break;
case 1:
indexLabel.backgroundColor = kColorRGBA(238, 132, 55, 1);
break;
case 2:
indexLabel.backgroundColor = kColorRGBA(237, 173, 72, 1);
break;
default:
break;
}
[indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.centerY.mas_equalTo(bottomButton.mas_centerY);
make.height.width.mas_equalTo(13);
}];
UILabel *hotWordLabel = [[UILabel alloc] init];
hotWordLabel.textAlignment = NSTextAlignmentLeft;
hotWordLabel.textColor = kBlackColor;
hotWordLabel.font = kMainFont;
hotWordLabel.text = [hotspotBookArray objectOrNilAtIndex:i];
[bottomButton addSubview:hotWordLabel];
[hotWordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(indexLabel.mas_right).with.offset(8);
make.centerY.mas_equalTo(indexLabel.mas_centerY);
make.right.mas_equalTo(bottomButton.mas_right);
make.height.mas_equalTo(bottomButton.mas_height);
}];
}
self.hotspotSearchViewFrame = CGRectMake(0, 0, SCREEN_WIDTH, button_Y + button_H + kMargin);
self.frame = self.hotspotSearchViewFrame;
}
- (void)hotspotBookClick:(UIButton *)sender
{
NSString *bookName = [self.hotspotBookArray objectOrNilAtIndex:sender.tag];
if (self.bookClickBlock) {
self.bookClickBlock(bookName);
}
}
- (void)setSmallFrame
{
self.frame = CGRectMake(0, 0, 0, 0);
}
- (void)setNormalFrame
{
self.frame = self.hotspotSearchViewFrame;
}
@end