小说绘上架版本

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,17 @@
//
// TFSetViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFSetViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,234 @@
//
// TFSetViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSetViewController.h"
#import "TFPushSetViewController.h"
#import "TFLanguageSetController.h"
#import "TFSetSwitchTableViewCell.h"
#import "TFSetLogoutTableViewCell.h"
#import "TFSetNormalTableViewCell.h"
@interface TFSetViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) NSArray *sourcesArray;
@end
@implementation TFSetViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"设置")];
self.view.backgroundColor = kGrayViewColor;
}
- (void)createSubviews
{
if (TFUserInfoManager.isLogin) {
self.sourcesArray = @[
#if TF_Recharge_Mode
@[TFLocalizedString(@"自动购买下一章")],
#endif
@[TFLocalizedString(@"通知管理")],
@[TFLocalizedString(@"清除缓存"),
TFLocalizedString(@"好评支持"),
TFLocalizedString(@"多语言")],
@[TFLocalizedString(@"退出登录")]
];
} else {
self.sourcesArray = @[@[TFLocalizedString(@"清除缓存"), TFLocalizedString(@"好评支持"), TFLocalizedString(@"多语言")]];
}
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(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.sourcesArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.sourcesArray objectOrNilAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (TFUserInfoManager.isLogin) {
#if TF_Recharge_Mode
if (indexPath.section == 0) {
return [self createSettingSwitchCellWithTableView:tableView indexPath:indexPath];
} else if (indexPath.section == 3) {
return [self createSettingLogoutCellWithTableView:tableView indexPath:indexPath];
}
#else
if (indexPath.section == 2) {
return [self createSettingLogoutCellWithTableView:tableView indexPath:indexPath];
}
#endif
}
return [self createSettingNormalCellWithTableView:tableView indexPath:indexPath];
}
- (UITableViewCell *)createSettingSwitchCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
TFSetSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFSetSwitchTableViewCell0"];
if (!cell) {
cell = [[TFSetSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFSetSwitchTableViewCell0"];
}
cell.leftTitleText = [[self.sourcesArray objectOrNilAtIndex:indexPath.section] objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = YES;
if ([TFUserInfoManager shareInstance].auto_sub) {
[cell.switchButton setDefaultOnState:YES];
} else {
[cell.switchButton setDefaultOnState:NO];
}
WS(weakSelf)
cell.switchButton.didChangeHandler = ^(BOOL isOn) {
[weakSelf autoSubNetRequest];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createSettingLogoutCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
TFSetLogoutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFSetLogoutTableViewCell"];
if (!cell) {
cell = [[TFSetLogoutTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFSetLogoutTableViewCell"];
}
cell.leftTitleText = [[self.sourcesArray objectOrNilAtIndex:indexPath.section] objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = [[self.sourcesArray objectOrNilAtIndex:indexPath.section] count] - 1 == indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createSettingNormalCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
TFSetNormalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFSetNormalTableViewCell"];
if (!cell) {
cell = [[TFSetNormalTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFSetNormalTableViewCell"];
}
cell.leftTitleText = [[self.sourcesArray objectOrNilAtIndex:indexPath.section] objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
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] init];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFSetBasicTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.leftTitleText isEqualToString:TFLocalizedString(@"通知管理")]) {
[self.navigationController pushViewController:[[TFPushSetViewController alloc] init] animated:YES];
return;
}
if ([cell.leftTitleText isEqualToString:TFLocalizedString(@"清除缓存")]) {
TFAlertView *alert = [[TFAlertView alloc] init];
alert.alertDetailContent = TFLocalizedString(@"是否清除缓存信息");
alert.confirmButtonClickBlock = ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"清除缓存成功")];
});
};
[alert showAlertView];
return;
}
if ([cell.leftTitleText isEqualToString:TFLocalizedString(@"好评支持")]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:TF_EvaluationAddress] options:@{} completionHandler:nil];
return;
}
if ([cell.leftTitleText isEqualToString:TFLocalizedString(@"退出登录")]) {
[self tableView:tableView settingLogoutdidSelectRowAtIndexPath:indexPath];
return;
}
if ([cell.leftTitleText isEqualToString:TFLocalizedString(@"多语言")]) {
[self.navigationController pushViewController:[[TFLanguageSetController alloc] init] animated:YES];
return;
}
}
- (void)tableView:(UITableView *)tableView settingLogoutdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[TFUserInfoManager logout];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Login_Success object:nil];
[self.mainTableViewGroup reloadData];
[self popViewController];
}
- (void)autoSubNetRequest
{
[TFNetworkTools POST:Auto_Sub_Chapter parameters:nil model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
BOOL autoSub = [t_model[@"data"][@"auto_sub"] boolValue];
[TFUserInfoManager updateWithDict:@{KEY_PATH(TFUserInfoManager.shareInstance, auto_sub):@(autoSub)}];
}
} failure:nil];
}
@end
@@ -0,0 +1,24 @@
//
// TFLanguageSetCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFLanguageSetModel;
@interface TFLanguageSetCell : UITableViewCell
@property (nonatomic, strong) TFLanguageSetModel *languageModel;
@property (nonatomic, weak) UIView *lineView;
- (void)set_selected:(BOOL)selected;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,90 @@
//
// TFLanguageSetCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFLanguageSetCell.h"
#import "NSObject+Observer.h"
#import "TFLanguageSetModel.h"
@interface TFLanguageSetCell ()
{
__weak UIImageView *_selecteImageView;
}
@end
@implementation TFLanguageSetCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self createSubviews];
}
return self;
}
- (void)createSubviews {
self.contentView.backgroundColor = [UIColor whiteColor];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.textColor = kBlackColor;
titleLabel.font = kFont16;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(kHalfMargin);
make.left.equalTo(self.contentView).offset(kMoreHalfMargin);
}];
UILabel *subtitleLabel = [[UILabel alloc] init];
subtitleLabel.textColor = kGrayTextColor;
subtitleLabel.font = kFont12;
[self.contentView addSubview:subtitleLabel];
[subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLabel.mas_bottom).offset(kQuarterMargin);
make.left.right.equalTo(titleLabel);
make.height.mas_equalTo(kMoreHalfMargin);
}];
UIImageView *selectedImageView = [[UIImageView alloc] init];
_selecteImageView = selectedImageView;
selectedImageView.hidden = YES;
selectedImageView.image = [[UIImage imageNamed:@"public_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
selectedImageView.tintColor = kMainColor;
[self.contentView addSubview:selectedImageView];
[selectedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.contentView).offset(-kMoreHalfMargin);
make.width.height.mas_equalTo(22.0);
}];
[titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(selectedImageView.mas_left).offset(-kHalfMargin);
}];
UIView *lineView = [[UIView alloc] init];
self.lineView = lineView;
lineView.backgroundColor = kGrayLineColor;
[self.contentView addSubview:lineView];
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kCellLineHeight);
make.left.equalTo(titleLabel);
make.right.equalTo(selectedImageView);
make.bottom.equalTo(self.contentView);
make.top.equalTo(subtitleLabel.mas_bottom).offset(kHalfMargin).priorityLow();
}];
[self addObserver:KEY_PATH(self, languageModel) complete:^(id _Nonnull obj, id _Nullable oldVal, TFLanguageSetModel * _Nullable newVal) {
titleLabel.text = newVal.title ?: @"";
subtitleLabel.text = newVal.subtitle ?: @"";
}];
}
- (void)set_selected:(BOOL)selected {
_selecteImageView.hidden = !selected;
}
@end
@@ -0,0 +1,18 @@
//
// TFLanguageSetController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFLanguageSetController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,162 @@
//
// TFLanguageSetController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFLanguageSetController.h"
#import "TFLanguageSetCell.h"
#import "TFLanguageSetModel.h"
@interface TFLanguageSetController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray<TFLanguageSetModel *> *dataArray;
/// 当前选择的下标
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, weak) UIButton *saveBtn;
@end
@implementation TFLanguageSetController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
#pragma mark - 初始化
- (void)initialize
{
self.view.backgroundColor = kGrayViewColor;
[self setNavigationBarTitle:TFLocalizedString(@"多语言环境")];
self.dataArray = [NSMutableArray array];
TFLanguageSetModel *t_model = [[TFLanguageSetModel alloc] init];
t_model.language = TFLanguageTypeDefault;
t_model.title = TFLocalizedString(@"自动");
switch (TFLanguageManager.localizedLanguage) {
case TFLanguageTypeSimplifiedChinese:
t_model.subtitle = @"简体中文";
break;
case TFLanguageTypeTraditionalChinese:
t_model.subtitle = @"繁体中文";
break;
case TFLanguageTypeEnglish:
t_model.subtitle = @"English";
break;
case TFLanguageTypeTail:
t_model.subtitle = @"ไทย";
break;
default:
break;
}
[self.dataArray addObject:t_model];
t_model = [[TFLanguageSetModel alloc] init];
t_model.language = TFLanguageTypeSimplifiedChinese;
t_model.title = @"简体中文";
t_model.subtitle = TFLocalizedString(@"简体中文");
[self.dataArray addObject:t_model];
t_model = [[TFLanguageSetModel alloc] init];
t_model.language = TFLanguageTypeTraditionalChinese;
t_model.title = @"繁體中文";
t_model.subtitle = TFLocalizedString(@"繁體中文");
[self.dataArray addObject:t_model];
t_model = [[TFLanguageSetModel alloc] init];
t_model.language = TFLanguageTypeEnglish;
t_model.title = @"English";
t_model.subtitle = TFLocalizedString(@"English");
[self.dataArray addObject:t_model];
t_model = [[TFLanguageSetModel alloc] init];
t_model.language = TFLanguageTypeTail;
t_model.title = @"ไทย";
t_model.subtitle = TFLocalizedString(@"ไทย");
[self.dataArray addObject:t_model];
self.selectedIndex = TFLanguageManager.userLanguage;
}
#pragma mark - UI
- (void)createSubviews {
UIButton *saveBtn = nil;
[self setNavigationBarRightButton:({
saveBtn = [UIButton buttonWithType:UIButtonTypeSystem];
self.saveBtn = saveBtn;
[saveBtn setTitle:TFLocalizedString(@"保存") forState:UIControlStateNormal];
[saveBtn setTitleColor:kGrayTextColor forState:UIControlStateDisabled];
[saveBtn setTitleColor:kColorRGB(44, 144, 255) forState:UIControlStateNormal];
saveBtn.backgroundColor = [UIColor clearColor];
saveBtn.titleLabel.font = kFont15;
saveBtn.enabled = NO;
[saveBtn addTarget:self action:@selector(changeLanguage) forControlEvents:UIControlEventTouchUpInside];
saveBtn;
})];
[saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.navigationBar).offset(-kQuarterMargin);
make.centerY.equalTo(self.navigationBar.navTitleLabel);
make.size.mas_equalTo(CGSizeMake(50.0, 20.0));
}];
saveBtn.hidden = YES;
self.mainTableView.dataSource = self;
self.mainTableView.delegate = self;
[self.view addSubview:self.mainTableView];
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.mainTableView registerClass:TFLanguageSetCell.class forCellReuseIdentifier:TFLanguageSetCell.className];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.bottom.equalTo(self.view);
make.top.equalTo(self.view).offset(PUB_NAVBAR_HEIGHT);
}];
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TFLanguageSetCell *cell = [tableView dequeueReusableCellWithIdentifier:TFLanguageSetCell.className forIndexPath:indexPath];
cell.languageModel = self.dataArray[indexPath.row];
cell.lineView.hidden = (indexPath.row == self.dataArray.count - 1);
[cell set_selected:(self.selectedIndex == indexPath.row)];
return cell;
}
#pragma mark UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] init];
view.backgroundColor = kGrayViewColor;
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TFLanguageSetCell *oldCell = (TFLanguageSetCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:indexPath.section]];
[oldCell set_selected:NO];
self.selectedIndex = indexPath.row;
[self changeLanguage];
}
/// 切换语言
- (void)changeLanguage {
TFLanguageSetModel *t_model = self.dataArray[self.selectedIndex];
[TFLanguageManager setLanguageType:t_model.language];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"切换成功")];
[TFNetworkTools POST:Switch_Language parameters:nil model:nil success:nil failure:nil];
}
@end
@@ -0,0 +1,24 @@
//
// TFLanguageSetModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFLanguageSetModel : NSObject
@property (nonatomic, assign) TFLanguageType language;
/// 标题使用的是该语言国家的本地语言展示,不会进行国际化
@property (nonatomic, copy) NSString *title;
/// 子标题是标题国际化之后的状态
@property (nonatomic, copy) NSString *subtitle;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,13 @@
//
// TFLanguageSetModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/14.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFLanguageSetModel.h"
@implementation TFLanguageSetModel
@end
@@ -0,0 +1,20 @@
//
// TFPushSetModel.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFPushSetModel : NSObject
@property (nonatomic ,copy) NSString *label; // 名称
@property (nonatomic ,copy) NSString *push_key; // 开关对应key
@property (nonatomic ,assign) NSInteger status; // 状态 1-开启 0-关闭(后端默认开启)
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,13 @@
//
// TFPushSetModel.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPushSetModel.h"
@implementation TFPushSetModel
@end
@@ -0,0 +1,20 @@
//
// TFPushSetTableViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFSetBasicTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFPushSetTableViewCell : TFSetBasicTableViewCell
@property (nonatomic ,assign) BOOL allowedPush;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,85 @@
//
// TFPushSetTableViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPushSetTableViewCell.h"
@interface TFPushSetTableViewCell ()
{
UIButton *openButton;
UIImageView *connerImageView;
}
@end
@implementation TFPushSetTableViewCell
- (void)createSubviews
{
[super createSubviews];
connerImageView = [[UIImageView alloc] init];
connerImageView.image = [UIImage imageNamed:@"public_more"];
[self.contentView addSubview:connerImageView];
[connerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.height.mas_equalTo(10);
}];
openButton = [UIButton buttonWithType:UIButtonTypeCustom];
[openButton setTitle:TFLocalizedString(@"点击开启") forState:UIControlStateNormal];
[openButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[openButton.titleLabel setFont:kFont12];
[openButton addTarget:self action:@selector(permissionsClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:openButton];
[openButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(connerImageView.mas_left).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.mas_equalTo(60);
make.height.mas_equalTo(self.leftTitleLabel.mas_height);
}];
}
- (void)setAllowedPush:(BOOL)allowedPush
{
_allowedPush = allowedPush;
if (allowedPush) {
[openButton setTitle:TFLocalizedString(@"已开启") forState:UIControlStateNormal];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:30.0 labelText:TFLocalizedString(@"已开启") maxWidth:SCREEN_WIDTH / 2.0];
[openButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(width);
}];
[openButton setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[connerImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(CGFLOAT_MIN);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
} else {
[openButton setTitle:TFLocalizedString(@"点击开启") forState:UIControlStateNormal];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:30.0 labelText:TFLocalizedString(@"点击开启") maxWidth:SCREEN_WIDTH / 2.0];
[openButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(width);
}];
[openButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[connerImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.width.mas_equalTo(10);
}];
}
}
- (void)permissionsClick
{
if (!_allowedPush) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
}
}
@end
@@ -0,0 +1,17 @@
//
// TFPushSetViewController.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFPushSetViewController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,177 @@
//
// TFPushSetViewController.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPushSetViewController.h"
#import <UserNotifications/UserNotifications.h>
#import "TFSetSwitchTableViewCell.h"
#import "TFPushSetTableViewCell.h"
#import "TFPushSetModel.h"
@interface TFPushSetViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL allowedPush;
@end
@implementation TFPushSetViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self currentNotificationStatus];
[self netRequest];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"通知管理")];
self.view.backgroundColor = kGrayViewColor;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentNotificationStatus) name:UIApplicationDidBecomeActiveNotification 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(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT);
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (self.allowedPush) {
return 2;
}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1) {
return self.dataSourceArray.count;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFPushSetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFPushSetTableViewCell"];
if (!cell) {
cell = [[TFPushSetTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFPushSetTableViewCell"];
}
cell.leftTitleText = TFLocalizedString(@"设置新消息通知");
cell.allowedPush = self.allowedPush;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
WS(weakSelf)
TFPushSetModel *settingModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
TFSetSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFSetSwitchTableViewCell0"];
if (!cell) {
cell = [[TFSetSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFSetSwitchTableViewCell0"];
}
cell.leftTitleText = settingModel.label?:@"";
cell.hiddenEndLine = NO;
if (settingModel.status == 1) {
[cell.switchButton setDefaultOnState:YES];
} else {
[cell.switchButton setDefaultOnState:NO];
}
cell.switchButton.didChangeHandler = ^(BOOL isOn) {
[weakSelf switchPushStateRequest:settingModel.push_key];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor clearColor];
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 0) {
return 30;
}
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
view.backgroundColor = [UIColor clearColor];
if (section == 0) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH - 2 * kMargin, 30)];
label.backgroundColor = [UIColor clearColor];
label.text = [NSString stringWithFormat:TFLocalizedString(@"请在 iPhone 的“设置”-“%@”设置开启/关闭"), App_Name];
label.textColor = kGrayTextColor;
label.font = kFont10;
[view addSubview:label];
}
return view;
}
- (void)currentNotificationStatus
{
WS(weakSelf)
if (@available(iOS 10 , *)) {
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusDenied) {
weakSelf.allowedPush = NO;
} else {
weakSelf.allowedPush = YES;
}
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.mainTableViewGroup reloadData];
});
}];
}
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:User_Push_State parameters:nil model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
for (NSDictionary *t_dic in [[t_model objectForKey:@"data"] objectForKey:@"list"]) {
[weakSelf.dataSourceArray addObject:[TFPushSetModel modelWithDictionary:t_dic]];
}
[weakSelf.mainTableViewGroup reloadData];
}
} failure:nil];
}
- (void)switchPushStateRequest:(NSString *)push_key
{
[TFNetworkTools POST:User_Update_Push_State parameters:@{@"push_key":push_key?:@""} model:nil success:nil failure:nil];
}
@end
@@ -0,0 +1,20 @@
//
// TFSetBasicTableViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBasicTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFSetBasicTableViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) UILabel *leftTitleLabel;
@property (nonatomic ,copy) NSString *leftTitleText;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,39 @@
//
// TFSetBasicTableViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSetBasicTableViewCell.h"
@implementation TFSetBasicTableViewCell
- (void)createSubviews
{
[super createSubviews];
self.leftTitleLabel = [[UILabel alloc] init];
self.leftTitleLabel.font = kMainFont;
self.leftTitleLabel.textColor = kBlackColor;
self.leftTitleLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:self.leftTitleLabel];
[self.leftTitleLabel 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(- kMargin);
make.height.mas_equalTo(50);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setLeftTitleText:(NSString *)leftTitleText
{
_leftTitleText = leftTitleText;
self.leftTitleLabel.text = leftTitleText;
}
@end
@@ -0,0 +1,18 @@
//
// TFSetLogoutTableViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFSetBasicTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFSetLogoutTableViewCell : TFSetBasicTableViewCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,35 @@
//
// TFSetLogoutTableViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSetLogoutTableViewCell.h"
@interface TFSetLogoutTableViewCell ()
@end
@implementation TFSetLogoutTableViewCell
- (void)createSubviews
{
[super createSubviews];
self.backgroundColor = [UIColor clearColor];
self.leftTitleLabel.text = TFLocalizedString(@"退出登录");
self.leftTitleLabel.textAlignment = NSTextAlignmentCenter;
self.leftTitleLabel.textColor = kWhiteColor;
self.leftTitleLabel.backgroundColor = kRedColor;
self.leftTitleLabel.layer.cornerRadius = 4;
self.leftTitleLabel.clipsToBounds = YES;
[self.leftTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(40);
}];
}
@end
@@ -0,0 +1,20 @@
//
// TFSetNormalTableViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFSetBasicTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFSetNormalTableViewCell : TFSetBasicTableViewCell
@property (nonatomic ,copy) NSString *rightTitleText;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,53 @@
//
// TFSetNormalTableViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSetNormalTableViewCell.h"
@interface TFSetNormalTableViewCell ()
{
UILabel *rightTitleLabel;
}
@end
@implementation TFSetNormalTableViewCell
- (void)createSubviews
{
[super createSubviews];
UIImageView *connerImage = [[UIImageView alloc] init];
connerImage.image = [UIImage imageNamed:@"public_more"];
[self.contentView addSubview:connerImage];
[connerImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.height.mas_equalTo(10);
}];
rightTitleLabel = [[UILabel alloc] init];
rightTitleLabel.font = kFont12;
rightTitleLabel.textColor = kGrayTextColor;
rightTitleLabel.textAlignment = NSTextAlignmentRight;
[self.contentView addSubview:rightTitleLabel];
[rightTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_centerX);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.right.mas_equalTo(connerImage.mas_left).with.offset(- 5);
make.height.mas_equalTo(self.leftTitleLabel.mas_height);
}];
}
- (void)setRightTitleText:(NSString *)rightTitleText
{
rightTitleLabel.text = rightTitleText;
}
@end
@@ -0,0 +1,21 @@
//
// TFSetSwitchTableViewCell.h
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFSetBasicTableViewCell.h"
#import "KLSwitch.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFSetSwitchTableViewCell : TFSetBasicTableViewCell
@property (nonatomic ,strong) KLSwitch *switchButton;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,28 @@
//
// TFSetSwitchTableViewCell.m
// WXReader
//
// Created by 谢腾飞 on 2020/12/2.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFSetSwitchTableViewCell.h"
@interface TFSetSwitchTableViewCell ()
@end
@implementation TFSetSwitchTableViewCell
- (void)createSubviews
{
[super createSubviews];
self.switchButton = [[KLSwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 51 - kHalfMargin - kQuarterMargin, 10, 51, 31)];
self.switchButton.transform = CGAffineTransformMakeScale(0.7, 0.7);//缩放
self.switchButton.onTintColor = kMainColor;
[self.contentView addSubview:self.switchButton];
}
@end