374 lines
13 KiB
Objective-C
374 lines
13 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"
|
|
///不同模块的VC
|
|
#import "XPWebViewController.h"
|
|
#import "XPLoginVerifBindPhoneViewController.h"
|
|
#import "XPLoginBindPhoneResultViewController.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
|
|
- (XPMineSettingPresent *)createPresenter {
|
|
return [[XPMineSettingPresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self.presenter getMineSettingDataSourceWith:self.userInfo];
|
|
}
|
|
|
|
- (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.left.right.bottom.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(0);
|
|
}];
|
|
}
|
|
|
|
- (void)pushViewControllerWithType:(XPMineSettingItemType)type {
|
|
switch (type) {
|
|
case XPMineSettingItemType_Phone:
|
|
{
|
|
// 绑定手机
|
|
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 (!self.userInfo.isBindPhone) {
|
|
XPLoginVerifBindPhoneViewController *vc = [[XPLoginVerifBindPhoneViewController alloc] init];
|
|
vc.bindingPhoneNumType = XPBindingPhoneNumTypeNormal;
|
|
vc.userInfo = _userInfo;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
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: {
|
|
|
|
if ([ClientConfig shareConfig].canOpen) {
|
|
[self pushWebViewWIthUrl:URLWithType(kAccountlogoutURL)];
|
|
} else {
|
|
[self pushWebViewWIthUrl:@"youmi/modules/logOff/index.html"];
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
- (void)pushWebViewWIthUrl:(NSString *)url {
|
|
XPWebViewController * webVC = [[XPWebViewController alloc] init];
|
|
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;
|
|
}
|
|
|
|
- (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 safeObjectAtIndex1:indexPath.section];
|
|
XPMineSettingItemModel * model = [array safeObjectAtIndex1: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 safeObjectAtIndex1:indexPath.section] safeObjectAtIndex1: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 {
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
}
|
|
|
|
- (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 {
|
|
[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, 168)];
|
|
}
|
|
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];
|
|
if ([ClientConfig shareConfig].canOpen) {
|
|
[_logoutButton setTitle:YMLocalizedString(@"XPMineSettingViewController7") forState:UIControlStateNormal];
|
|
_logoutButton.backgroundColor = [DJDKMIMOMColor appCellBackgroundColor];
|
|
[_logoutButton setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal];
|
|
}else{
|
|
[_logoutButton setTitle:YMLocalizedString(@"XPMineSettingViewController8") forState:UIControlStateNormal];
|
|
_logoutButton.backgroundColor = UIColorFromRGB(0xCED3D8);
|
|
[_logoutButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
|
|
}
|
|
}
|
|
return _logoutButton;
|
|
}
|
|
|
|
@end
|