Files
peko-ios/YuMi/Modules/YMMine/View/Setting/XPMineSettingViewController.m

499 lines
19 KiB
Objective-C

//
// YMMineSettingViewController.m
// YUMI
//
// Created by YUMI on 2021/9/17.
//
#import "XPMineSettingViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImageManager.h>
#import "SDWebImageManager.h"
#import <ReactiveObjC/ReactiveObjC.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "YUMIMacroUitls.h"
#import "NSArray+Safe.h"
#import "YUMIHtmlUrl.h"
#import "YYUtility.h"
#import "ClientConfig.h"
///Model
#import "XPMineSettingItemModel.h"
#import "UserInfoModel.h"
#import "XPVersionUpdateModel.h"
///View
#import "XPMineSettingTableViewCell.h"
#import "TTAlertConfig.h"
#import "TTPopup.h"
#import "XPUpgradeView.h"
///P
#import "XPMineSettingPresent.h"
#import "XPMineSettingProtocol.h"
///VC
#import "XPMineAboutUsViewController.h"
#import "XPMineFeedbackViewController.h"
#import "XPMineNotificaViewController.h"
#import "XPMinePayPwdViewController.h"
#import "XPMineModifPayPwdViewController.h"
#import "XPPrivacyViewController.h"
#import "XPMineLoginPasswordViewController.h"
#import "XPMineBlackListViewController.h"
#import "XPMaskManagerVC.h"
#import "XPMineSwitchLanguageVC.h"
///不同模块的VC
#import "XPWebViewController.h"
#import "XPLoginVerifBindPhoneViewController.h"
#import "AccountBindingViewController.h"
#import "VipSettingViewController.h"
#import "BaseNavigationController.h"
#import "LoginViewController.h"
#import "SocialShareManager.h"
#import "FirstRechargeManager.h"
@interface XPMineSettingViewController ()<UITableViewDelegate, UITableViewDataSource, XPMineSettingProtocol>
///
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSArray<NSArray<XPMineSettingItemModel *> *> *datasource;
///退出登录
@property (nonatomic,strong) UIButton *logoutButton;
///底部的试图
@property (strong, nonatomic) UIView *footerView;
@end
@implementation XPMineSettingViewController
- (void)dealloc
{
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (XPMineSettingPresent *)createPresenter {
return [[XPMineSettingPresent alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self initSubViews];
[self initSubViewConstraints];
[self.presenter getMineSettingDataSourceWith:self.userInfo];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(switchLanguage:) name:@"kSwitchLanguage" object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setNavView) name:@"kNavViewUpdateWhenLanguageUpdate" object:nil];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
-(void)setNavView{
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"common_nav_back"] ms_SetImageForRTL]
style:UIBarButtonItemStyleDone
target:self
action:@selector(backClick)];
leftBarButtonItem.tintColor = [DJDKMIMOMColor mainTextColor];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}
-(void)switchLanguage:(NSNotification *)not{
for (UIView *obj in self.view.subviews) {
[obj removeFromSuperview];
}
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.leftBarButtonItem = nil;
[self.presenter clearList];
self.tableView = nil;
self.datasource = nil;
self.logoutButton = nil;
self.footerView = nil;
[self initSubViews];
[self initSubViewConstraints];
[self.presenter getMineSettingDataSourceWith:self.userInfo];
}
-(void)backClick{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
///每次都需要刷新一个userinfo
[self.presenter getUserInfo];
}
#pragma mark - Private Method
- (void)initSubViews {
self.title = YMLocalizedString(@"XPMineSettingViewController0");
[self.view addSubview:self.tableView];
[self.footerView addSubview:self.logoutButton];
self.tableView.tableFooterView = self.footerView;
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.mas_equalTo(self.view).inset(14);
make.top.mas_equalTo(12);
}];
[self.logoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.footerView);
make.size.mas_equalTo(CGSizeMake(KScreenWidth - 32* 2, 50));
}];
}
- (void)toBindEmail {
AccountBindingViewController *bindingVC = [[AccountBindingViewController alloc] initWithType:BindingDisplayType_email
currentBindingAccount:self.userInfo.email
areaCode:@""
userInfo:self.userInfo];
[self.navigationController pushViewController:bindingVC animated:YES];
}
- (void)pushViewControllerWithType:(XPMineSettingItemType)type {
switch (type) {
case XPMineSettingItemType_Email:
[self toBindEmail];
break;
case XPMineSettingItemType_Phone:
{
AccountBindingViewController *bindingVC = [[AccountBindingViewController alloc] initWithType:BindingDisplayType_phoneNum
currentBindingAccount:self.userInfo.phone
areaCode:self.userInfo.phoneAreaCode
userInfo:self.userInfo];
[self.navigationController pushViewController:bindingVC animated:YES];
// 绑定手机
// if (self.userInfo.isBindPhone) { // 如果已经绑定
// XPLoginBindPhoneResultViewController *vc = [[XPLoginBindPhoneResultViewController alloc] init];
// vc.userInfo = _userInfo;
// [self.navigationController pushViewController:vc animated:YES];
// }else {
// XPLoginVerifBindPhoneViewController *vc = [[XPLoginVerifBindPhoneViewController alloc] init];
// vc.bindingPhoneNumType = XPBindingPhoneNumTypeNormal;
// vc.userInfo = _userInfo;
// [self.navigationController pushViewController:vc animated:YES];
// }
}
break;
case XPMineSettingItemType_Pay_Password:
{
if (!self.userInfo.isBindPhone) {
[self showErrorToast:YMLocalizedString(@"XPMineSettingViewController1")];
return;
}
//支付密码
if (self.userInfo.isBindPaymentPwd) {
XPMineModifPayPwdViewController *vc = [[XPMineModifPayPwdViewController alloc] init];
vc.userInfo = self.userInfo;
[self.navigationController pushViewController:vc animated:YES];
} else {
XPMinePayPwdViewController *vc = [[XPMinePayPwdViewController alloc] init];
vc.userInfo = self.userInfo;
[self.navigationController pushViewController:vc animated:YES];
}
}
break;
case XPMineSettingItemType_Login_Password:
{
if ([NSString isEmpty:self.userInfo.email] && [NSString isEmpty:self.userInfo.phone]) {
[self toBindEmail];
return;
}
//支付密码
if (self.userInfo.isBindPasswd) {
XPMineLoginPasswordViewController *vc = [[XPMineLoginPasswordViewController alloc] init];
vc.userInfo = self.userInfo;
vc.isModifiPwd = YES;
[self.navigationController pushViewController:vc animated:YES];
} else {
XPMineLoginPasswordViewController *vc = [[XPMineLoginPasswordViewController alloc] init];
vc.userInfo = self.userInfo;
vc.isModifiPwd = NO;
[self.navigationController pushViewController:vc animated:YES];
}
}
break;
case XPMineSettingItemType_Black_Manager:
{
XPMineBlackListViewController * blackMangerVC = [[XPMineBlackListViewController alloc] init];
[self.navigationController pushViewController:blackMangerVC animated:YES];
}
break;
case XPMineSettingItemType_Notification_Remind:
{
XPMineNotificaViewController * notiVC = [[XPMineNotificaViewController alloc] init];
[self.navigationController pushViewController:notiVC animated:YES];
}
break;
case XPMineSettingItemType_Permission:
{
XPPrivacyViewController * pvc = [[XPPrivacyViewController alloc] init];
[self.navigationController pushViewController:pvc animated:YES];
}
break;
case XPMineSettingItemType_Helper:
{
[self pushWebViewWIthUrl:URLWithType(kFAQURL)];
}
break;
case XPMineSettingItemType_Feedback:
{
XPMineFeedbackViewController * feedbackVC = [[XPMineFeedbackViewController alloc] init];
[self.navigationController pushViewController:feedbackVC animated:YES];
}
break;
case XPMineSettingItemType_Clear_Memory:
{
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"XPMineSettingViewController2");
config.message = YMLocalizedString(@"XPMineSettingViewController3");
[TTPopup alertWithConfig:config confirmHandler:^{
NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
@weakify(self);
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
@strongify(self);
[self showSuccessToast:YMLocalizedString(@"XPMineSettingViewController4")];
}];
[[SDWebImageManager sharedManager].imageCache clearWithCacheType:SDImageCacheTypeAll completion:nil];
} cancelHandler:^{
}];
}
break;
case XPMineSettingItemType_About_Us:
{
XPMineAboutUsViewController * aboutusVC = [[XPMineAboutUsViewController alloc] init];
[self.navigationController pushViewController:aboutusVC animated:YES];
}
break;
case XPMineSettingItemType_CheckUpdate:
{
[self showLoading];
[self.presenter getVersionUpdate];
}
break;
case XPMineSettingItemType_Delete_Account: {
[self pushWebViewWIthUrl:URLWithType(kAccountlogoutConfirmURL)];
}
break;
case XPMineSettingItemType_Shield_management:
{
XPMaskManagerVC *vc = [XPMaskManagerVC new];
[self.navigationController pushViewController:vc animated:YES];
break;
}
case XPMineSettingItemType_Language:
{
XPMineSwitchLanguageVC*languageVC = [XPMineSwitchLanguageVC new];
[self.navigationController pushViewController:languageVC animated:YES];
}
break;
case XPMineSettingItemType_VIP: {
VipSettingViewController *vc = [[VipSettingViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
default:
break;
}
}
- (void)pushWebViewWIthUrl:(NSString *)url {
XPWebViewController * webVC = [[XPWebViewController alloc] initWithRoomUID:nil];
webVC.url = url;
[self.navigationController pushViewController:webVC animated:YES];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 45;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.datasource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource[section].count;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray * array = [self.datasource xpSafeObjectAtIndex:indexPath.section];
XPMineSettingItemModel *model = [array xpSafeObjectAtIndex:indexPath.row];
switch (model.type) {
case XPMineSettingItemType_Email:
case XPMineSettingItemType_VIP:
case XPMineSettingItemType_Shield_management:
case XPMineSettingItemType_Permission:
[(XPMineSettingTableViewCell *)cell setTopCorner:YES bottomCorner:NO];
break;
case XPMineSettingItemType_Pay_Password:
case XPMineSettingItemType_Language:
case XPMineSettingItemType_Black_Manager:
case XPMineSettingItemType_About_Us:
[(XPMineSettingTableViewCell *)cell setTopCorner:NO bottomCorner:YES];
break;
default:
[(XPMineSettingTableViewCell *)cell setTopCorner:NO bottomCorner:NO];
break;
}
// if (indexPath.row == 0) {
// [(XPMineSettingTableViewCell *)cell setTopCorner:YES bottomCorner:NO];
// } else if (indexPath.row == self.datasource[indexPath.section].count-1) {
// [(XPMineSettingTableViewCell *)cell setTopCorner:NO bottomCorner:YES];
// } else {
// [(XPMineSettingTableViewCell *)cell setTopCorner:NO bottomCorner:NO];
// }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
XPMineSettingTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineSettingTableViewCell class])];
if (cell == nil) {
cell = [[XPMineSettingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineSettingTableViewCell class])];
}
NSArray * array = [self.datasource xpSafeObjectAtIndex:indexPath.section];
XPMineSettingItemModel * model = [array xpSafeObjectAtIndex:indexPath.row];
cell.itemModel = model;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section != 0) {
return 15;
}
return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView * view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, KScreenWidth, 15);
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView * view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, KScreenWidth, 0.01f);
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
XPMineSettingItemModel * model = [[self.datasource xpSafeObjectAtIndex:indexPath.section] xpSafeObjectAtIndex:indexPath.row];
[self pushViewControllerWithType:model.type];
}
}
#pragma mark - XPMineSettingProtocol
- (void)getMineSettingDatasourceSuccess:(NSArray *)array {
self.datasource = array;
[self.tableView reloadData];
}
- (void)onGetUserInfoSuccess:(UserInfoModel *)userInfo {
self.userInfo = userInfo;
[self.presenter getMineSettingDataSourceWith:userInfo];
}
- (void)logoutCurrentAccountSuccess {
// 停止首充监控
[[FirstRechargeManager sharedManager] stopMonitoring];
[[SocialShareManager sharedManager] reset];
LoginViewController *lvc = [[LoginViewController alloc] init];
BaseNavigationController * navigationController = [[BaseNavigationController alloc] initWithRootViewController:lvc];
kWindow.rootViewController = navigationController;
}
- (void)getVersionUpdateFail{
[self hideHUD];
}
///版本更新
-(void)getVersionUpdate:(XPVersionUpdateModel *)model{
[self hideHUD];
if(model.updateVersion.length == 0){
[self showErrorToast:YMLocalizedString(@"XPMineSettingViewController5")];
return;
}
NSString *appVersion = [YYUtility appVersion];
NSString *updateVersion = model.updateVersion;
NSComparisonResult result = [appVersion compare:updateVersion options:NSNumericSearch];
if(result == NSOrderedSame || result == NSOrderedDescending){
[self showErrorToast:YMLocalizedString(@"XPMineSettingViewController6")];
return;
}
XPUpgradeView *view = [[XPUpgradeView alloc] init];
view.versionModel = model;
TTPopupService * service = [[TTPopupService alloc] init];
service.contentView = view;
service.shouldDismissOnBackgroundTouch = NO;
[TTPopup popupWithConfig:service];
}
#pragma mark - Event Response
- (void)logoutButtonAction:(UIButton *)sender {
id isSaveBindPwd = [[NSUserDefaults standardUserDefaults]valueForKey:@"kSaveBindPwd"];
if(self.userInfo.isBindPasswd == NO && isSaveBindPwd == nil){
[[NSUserDefaults standardUserDefaults]setValue:@"1" forKey:@"kSaveBindPwd"];
[[NSUserDefaults standardUserDefaults]synchronize];
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"XPMineSettingViewController9");
config.message = YMLocalizedString(@"XPMineSettingViewController10");
[TTPopup alertWithConfig:config confirmHandler:^{
// if (!self.userInfo.isBindPhone) {
// XPLoginVerifBindPhoneViewController *vc = [[XPLoginVerifBindPhoneViewController alloc] init];
// vc.bindingPhoneNumType = XPBindingPhoneNumTypeNormal;
// vc.userInfo = self.userInfo;
// vc.isLogout = YES;
// [self.navigationController pushViewController:vc animated:YES];
// return;
// }
[self logoutCurrentAccountSuccess];
} cancelHandler:^{
[self.presenter logoutCurrentAccount];
}];
return;
}
[self.presenter logoutCurrentAccount];
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
[_tableView registerClass:[XPMineSettingTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineSettingTableViewCell class])];
}
return _tableView;
}
- (UIView *)footerView {
if (!_footerView) {
_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 88)];
}
return _footerView;
}
- (UIButton *)logoutButton {
if (!_logoutButton) {
_logoutButton = [UIButton buttonWithType:UIButtonTypeCustom];
_logoutButton.frame = CGRectMake(32, 40, KScreenWidth - 32* 2, 50);
_logoutButton.layer.masksToBounds = YES;
_logoutButton.layer.cornerRadius = 50/2;
_logoutButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_logoutButton addTarget:self action:@selector(logoutButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_logoutButton setTitle:YMLocalizedString(@"XPMineSettingViewController7") forState:UIControlStateNormal];
_logoutButton.backgroundColor = UIColorFromRGB(0xF2F3F7);
[_logoutButton setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal];
}
return _logoutButton;
}
@end