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.

318 lines
11 KiB

//
// TFMineViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/11.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFMineViewController.h"
#import "WXYZ_UserDataViewController.h"
#import "TFAppraiseViewController.h"
#import "TFFeedBackViewController.h"
#import "TFSetViewController.h"
#import "TFRecordsViewController.h"
#if TF_Task_Mode && TF_Super_Member_Mode && TF_Recharge_Mode
#import "TFTaskViewController.h"
#endif
#import "TFDownloadCacheViewController.h"
#import "TFRechargeViewController.h"
#import "TFAboutViewController.h"
#import "TFUpgradeMemberController.h"
#import "TFHistoricalRecordController.h"
#import "TFMineTableViewCell.h"
#import "TFMineHeaderView.h"
#import "TFUserCenterModel.h"
#import "TFCollectionManager.h"
#import "TFShareManager.h"
#import "TFMonthlyTicketViewController.h"
#import "TFRewardRecordViewController.h"
#import "TFWebViewController.h"
#import "TFLoginOptionsViewController.h"
@interface TFMineViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFMineHeaderView *headerView;
@property (nonatomic ,strong) TFUserCenterModel *userModel;
@end
@implementation TFMineViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[self netRequest];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Show_Tabbar object:nil];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
self.view.backgroundColor = kGrayViewColor;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(avatarChanged:) name:Notification_Avatar_Changed object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nicknameChnaged:) name:Notification_NickName_Changed object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToUserInfo) name:Notification_Push_UserInfo object:nil];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
UIView *topCoverView = [[UIView alloc] init];
topCoverView.backgroundColor = kWhiteColor;
[self.view addSubview:topCoverView];
[topCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.mas_equalTo(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(is_iPhoneX?30:20);
}];
WS(weakSelf)
self.headerView = [[TFMineHeaderView alloc] init];
self.headerView.portraitHandleBlock = ^{
if (TFUserInfoManager.isLogin) {
[weakSelf.navigationController pushViewController:[[WXYZ_UserDataViewController alloc] init] animated:YES];
} else {
[TFLoginOptionsViewController presentLoginView:nil];
}
};
// 金币
#if TF_Records_Mode
self.headerView.goldSelectedBlock = ^{
TFRecordsViewController *vc = [[TFRecordsViewController alloc] init];
vc.pageIndex = 0;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
#endif
#if TF_Task_Mode && TF_Super_Member_Mode && TF_Recharge_Mode
// 书券余额
self.headerView.taskSelectedBlock = ^{
TFRecordsViewController *vc = [[TFRecordsViewController alloc] init];
vc.pageIndex = 1;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
#endif
#if TF_Records_Mode
// 月票余额
self.headerView.voucherSelectedBlock = ^{
[weakSelf.navigationController pushViewController:[[TFMonthlyTicketViewController alloc] init] animated:YES];
};
#endif
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.userModel.panel_list.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.userModel.panel_list[section].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFMineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFMineTableViewCell"];
if (!cell) {
cell = [[TFMineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFMineTableViewCell"];
}
cell.cellModel = self.userModel.panel_list[indexPath.section][indexPath.row];
cell.hiddenEndLine = (indexPath.row == self.userModel.panel_list[indexPath.section].count - 1);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFMineTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// 充值
if ([cell.cellModel.action isEqualToString:@"recharge"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFRechargeViewController alloc] init] animated:YES];
}
// 包月
if ([cell.cellModel.action isEqualToString:@"vip"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFUpgradeMemberController alloc] init] animated:YES];
}
// 任务
if ([cell.cellModel.action isEqualToString:@"task"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFTaskViewController alloc] init] animated:YES];
}
if ([cell.cellModel.action isEqualToString:@"invite"] && cell.cellModel.enable) {
[self shareToFriend];
}
if ([cell.cellModel.action isEqualToString:@"history"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFHistoricalRecordController alloc] init] animated:YES];
}
if ([cell.cellModel.action isEqualToString:@"download"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFDownloadCacheViewController alloc] init] animated:YES];
}
// 我的书评
if ([cell.cellModel.action isEqualToString:@"comment"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFAppraiseViewController alloc] init] animated:YES];
}
// 联系客服
if ([cell.cellModel.action isEqualToString:@"service"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFAboutViewController alloc] init] animated:YES];
}
// 意见反馈
if ([cell.cellModel.action isEqualToString:@"feedback"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFFeedBackViewController alloc] init] animated:YES];
}
// 设置
if ([cell.cellModel.action isEqualToString:@"setting"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFSetViewController alloc] init] animated:YES];
}
// 打赏记录
if ([cell.cellModel.action isEqualToString:@"reward"] && cell.cellModel.enable) {
[self.navigationController pushViewController:[[TFRewardRecordViewController alloc] init] animated:YES];
}
// 成为作家
if ([cell.cellModel.action isEqualToString:@"url"] && cell.cellModel.enable) {
TFWebViewController *vc = [[TFWebViewController alloc] init];
vc.URLString = cell.cellModel.content;
vc.navTitle = TFLocalizedString(@"成为作家");
[self.navigationController pushViewController:vc animated:YES];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if ([[self.userModel.panel_list objectOrNilAtIndex:section] count] == 0) {
return CGFLOAT_MIN;
}
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = kGrayViewColor;
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == self.userModel.panel_list.count - 1) {
return kMargin;
}
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kMargin)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)avatarChanged:(NSNotification *)noti
{
if ([noti.object isKindOfClass:[UIImage class]]) {
self.headerView.avatarImage = noti.object;
}
}
- (void)nicknameChnaged:(NSNotification *)noti
{
self.headerView.nickName = noti.object;
}
- (void)pushToUserInfo
{
[self.navigationController pushViewController:[[WXYZ_UserDataViewController alloc] init] animated:YES];
}
- (void)shareToFriend
{
[TFShareManager shareApp];
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POSTQuick:User_Center parameters:nil model:TFUserCenterModel.class success:^(BOOL isSuccess, TFUserCenterModel *_Nullable t_model, BOOL isCache, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableViewGroup endRefreshing];
if (isSuccess) {
TFSystemInfoManager.masterUnit = t_model.masterUnit;
TFSystemInfoManager.subUnit = t_model.subUnit;
weakSelf.userModel = t_model;
weakSelf.headerView.userModel = t_model;
[weakSelf.mainTableViewGroup reloadData];
if (!isCache) {
[TFUserInfoManager updateWithDict:requestModel.data];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: @""];
if (requestModel.code == 302) {
[TFUserInfoManager logout];
[weakSelf netRequest];
}
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableViewGroup endRefreshing];
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end