123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //
- // YMSettingViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMSettingViewModel.h"
- #import "YMChatNotificationViewModel.h"
- #import "YMGreetingSettingViewModel.h"
- #import "YMFeesSettingViewModel.h"
- #import "YMAdolescentModelViewModel.h"
- #import "YMBlackListViewModel.h"
- #import "YMAboutUsViewModel.h"
- #import "LPBeautySetVC.h"
- @interface YMSettingViewModel ()
- /// 列表数据
- @property (nonatomic, strong, readwrite) NSArray <YMSettingCellViewModel*>*listDataArray;
- /// 设置功能操作
- @property (nonatomic, strong, readwrite) RACSubject *settingFunctionsOperationSubject;
- @end
- @implementation YMSettingViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- self.customNavTitle = @"设置";
- @weakify(self)
- [[self.settingFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
- @strongify(self)
- switch ([value intValue]) {
- case YMSettingFunctionsTypeAccountBinding:
- {
- if (OCStringIsEmpty([LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile)) {
-
- } else {
- [ZCHUDHelper showTitle:@"您已经绑定了手机号"];
- }
- }
- break;
- case YMSettingFunctionsTypeBeautySetting:
- {
- LPBeautySetVC *beautySet = [[LPBeautySetVC alloc]init];
- [[YMGlobalUtils getCurrentVC].navigationController pushViewController:beautySet animated:YES];
- }
- break;
- case YMSettingFunctionsTypeChatNotification:
- {
- YMChatNotificationViewModel *chatNotificationVM = [[YMChatNotificationViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CHAT_NOTIFICATION) withUserInfo:@{
- RouterViewModel:chatNotificationVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeGreetingSetting:
- {
- if ([self isNeedGoddessCertified]) {
- return;
- }
- YMGreetingSettingViewModel *greetingSettingVM = [[YMGreetingSettingViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_GREETING_SETTING) withUserInfo:@{
- RouterViewModel:greetingSettingVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeFeesSetting:
- {
- if ([self isNeedGoddessCertified]) {
- return;
- }
- YMFeesSettingViewModel *feesSettingVM = [[YMFeesSettingViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_FEES_SETTING) withUserInfo:@{
- RouterViewModel:feesSettingVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeAdolescentModel:
- {
-
- YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
- ParamsCategoryType:@(YMAdolescentModelTypeTips)
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
- RouterViewModel:adolescentModelVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeBlackList:
- {
- YMBlackListViewModel *blackListVM = [[YMBlackListViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_BLACKLIST) withUserInfo:@{
- RouterViewModel:blackListVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeClearCache:
- {
- YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
- [customView configutationWithTips:stringFormat(@"是否删除%@数据?",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]) TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:YES];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.3;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm) {
- @strongify(popupView)
- if (isConfirm) {
- [ZCHUDHelper showWithStatus:@"正在清理..."];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [[SDImageCache sharedImageCache] clearMemory];
- [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
-
- }];
- NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
- NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:resultPath];
- for (NSString *fileName in enumerator) {
- NSString *filePath = [resultPath stringByAppendingPathComponent:fileName];
- [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [ZCHUDHelper showTitle:@"清理完成"];
- [self getSettingListData];
- });
- });
- }
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- [popupView pop];
- }
- break;
- case YMSettingFunctionsTypeGotoRating:
- {
- [ZCHUDHelper showTitle:@"暂无评分_(:з」∠)_"];
- }
- break;
- case YMSettingFunctionsTypeCancellationAccount:
- {
- YMCancellationAccountViewModel *cancellationAccountVM = [[YMCancellationAccountViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CANCELLATION_ACCOUNT) withUserInfo:@{
- RouterViewModel:cancellationAccountVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeAboutUs:
- {
- YMAboutUsViewModel *aboutUsVM = [[YMAboutUsViewModel alloc]initWithParams:@{}];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ABOUT_US) withUserInfo:@{
- RouterViewModel:aboutUsVM
- } completion:nil];
- }
- break;
- case YMSettingFunctionsTypeLogOut:
- {
- YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
- [customView configutationWithTips:@"您确定要退出登录吗?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:YES];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.3;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm) {
- @strongify(popupView)
- if (isConfirm) {
- [LCTools changeRootToLogin];
- }
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- [popupView pop];
- }
- break;
- default:
- break;
- }
- }];
- }
- - (void)getSettingListData{
-
- NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
- NSUInteger tmpSize = resultPath.fileSize + [[SDImageCache sharedImageCache] getSize];
-
- CGFloat unit = 1000.0;
- NSString *sizeText = nil;
- if (tmpSize >= unit * unit * unit) { // >= 1GB
- sizeText = [NSString stringWithFormat:@"%.1fGB", tmpSize / unit / unit / unit];
- } else if (tmpSize >= unit * unit) { // >= 1MB
- sizeText = [NSString stringWithFormat:@"%.1fMB", tmpSize / unit / unit];
- } else if (tmpSize >= unit) { // >= 1KB
- sizeText = [NSString stringWithFormat:@"%.1fKB", tmpSize / unit];
- } else { // >= 0B
- sizeText = [NSString stringWithFormat:@"%zdB", tmpSize];
- }
-
- self.listDataArray = [[@[
- @{
- @"title":@"账号绑定",
- @"detail":@"",
- @"content":[LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile,
- ParamsCategoryType:@(YMSettingFunctionsTypeAccountBinding),
- },
- @{
- @"title":@"美颜设置",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeBeautySetting),
- },
- @{
- @"title":@"消息通知",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeChatNotification),
- },
- @{
- @"title":@"打招呼设置",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeGreetingSetting),
- },
- @{
- @"title":@"收费设置",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeFeesSetting),
- },
- @{
- @"title":@"青少年模式",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeAdolescentModel),
- },
- @{
- @"title":@"黑名单",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeBlackList),
- },
- @{
- @"title":@"清除缓存",
- @"detail":@"",
- @"content":sizeText,
- ParamsCategoryType:@(YMSettingFunctionsTypeClearCache),
- },
- @{
- @"title":@"去评分",
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeGotoRating),
- },
- @{
- @"title":@"注销账号",
- @"detail":@"(清除所有资料)",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeCancellationAccount),
- },
- @{
- @"title":stringFormat(@"关于%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]),
- @"detail":@"",
- @"content":@"",
- ParamsCategoryType:@(YMSettingFunctionsTypeAboutUs),
- },
- ].rac_sequence filter:^BOOL(NSDictionary * _Nullable settingFunctionsDic) {
- YMSettingFunctionsType type = [settingFunctionsDic integerValueForKey:ParamsCategoryType defaultValue:YMSettingFunctionsTypeAboutUs];
- if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && type == YMSettingFunctionsTypeGreetingSetting) {
- return YES;
- } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1 && type == YMSettingFunctionsTypeGreetingSetting) {
- return NO;
- } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && type == YMSettingFunctionsTypeFeesSetting) {
- return YES;
- } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1 && type == YMSettingFunctionsTypeFeesSetting) {
- return NO;
- }else if(type == YMSettingFunctionsTypeGotoRating){
- return NO;
- } else {
- return YES;
- }
- }] map:^(NSDictionary * _Nullable dic) {
- YMSettingCellViewModel *viewModel = [[YMSettingCellViewModel alloc]initWithParams:@{
- ParamsModel:dic
- }];
- return viewModel;
- }].array;
-
- [self.refreshUISubject sendNext:@(YMRefreshUI)];
-
- }
- - (RACSubject *)settingFunctionsOperationSubject{
- if (!_settingFunctionsOperationSubject) {
- _settingFunctionsOperationSubject = [RACSubject subject];
- }
- return _settingFunctionsOperationSubject;
- }
- @end
|