YMSettingViewModel.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. //
  2. // YMSettingViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSettingViewModel.h"
  9. #import "YMChatNotificationViewModel.h"
  10. #import "YMGreetingSettingViewModel.h"
  11. #import "YMFeesSettingViewModel.h"
  12. #import "YMAdolescentModelViewModel.h"
  13. #import "YMBlackListViewModel.h"
  14. #import "YMAboutUsViewModel.h"
  15. #import "LPBeautySetVC.h"
  16. @interface YMSettingViewModel ()
  17. /// 列表数据
  18. @property (nonatomic, strong, readwrite) NSArray <YMSettingCellViewModel*>*listDataArray;
  19. /// 设置功能操作
  20. @property (nonatomic, strong, readwrite) RACSubject *settingFunctionsOperationSubject;
  21. @end
  22. @implementation YMSettingViewModel
  23. - (void)ym_initialize{
  24. [super ym_initialize];
  25. self.customNavTitle = @"设置";
  26. @weakify(self)
  27. [[self.settingFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  28. @strongify(self)
  29. switch ([value intValue]) {
  30. case YMSettingFunctionsTypeAccountBinding:
  31. {
  32. if (OCStringIsEmpty([LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile)) {
  33. } else {
  34. [ZCHUDHelper showTitle:@"您已经绑定了手机号"];
  35. }
  36. }
  37. break;
  38. case YMSettingFunctionsTypeBeautySetting:
  39. {
  40. LPBeautySetVC *beautySet = [[LPBeautySetVC alloc]init];
  41. [[YMGlobalUtils getCurrentVC].navigationController pushViewController:beautySet animated:YES];
  42. }
  43. break;
  44. case YMSettingFunctionsTypeChatNotification:
  45. {
  46. YMChatNotificationViewModel *chatNotificationVM = [[YMChatNotificationViewModel alloc]initWithParams:@{}];
  47. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CHAT_NOTIFICATION) withUserInfo:@{
  48. RouterViewModel:chatNotificationVM
  49. } completion:nil];
  50. }
  51. break;
  52. case YMSettingFunctionsTypeGreetingSetting:
  53. {
  54. if ([self isNeedGoddessCertified]) {
  55. return;
  56. }
  57. YMGreetingSettingViewModel *greetingSettingVM = [[YMGreetingSettingViewModel alloc]initWithParams:@{}];
  58. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_GREETING_SETTING) withUserInfo:@{
  59. RouterViewModel:greetingSettingVM
  60. } completion:nil];
  61. }
  62. break;
  63. case YMSettingFunctionsTypeFeesSetting:
  64. {
  65. if ([self isNeedGoddessCertified]) {
  66. return;
  67. }
  68. YMFeesSettingViewModel *feesSettingVM = [[YMFeesSettingViewModel alloc]initWithParams:@{}];
  69. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_FEES_SETTING) withUserInfo:@{
  70. RouterViewModel:feesSettingVM
  71. } completion:nil];
  72. }
  73. break;
  74. case YMSettingFunctionsTypeAdolescentModel:
  75. {
  76. YMAdolescentModelViewModel *adolescentModelVM = [[YMAdolescentModelViewModel alloc]initWithParams:@{
  77. ParamsCategoryType:@(YMAdolescentModelTypeTips)
  78. }];
  79. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ADOLESCENT_MODEL) withUserInfo:@{
  80. RouterViewModel:adolescentModelVM
  81. } completion:nil];
  82. }
  83. break;
  84. case YMSettingFunctionsTypeBlackList:
  85. {
  86. YMBlackListViewModel *blackListVM = [[YMBlackListViewModel alloc]initWithParams:@{}];
  87. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_BLACKLIST) withUserInfo:@{
  88. RouterViewModel:blackListVM
  89. } completion:nil];
  90. }
  91. break;
  92. case YMSettingFunctionsTypeClearCache:
  93. {
  94. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  95. [customView configutationWithTips:stringFormat(@"是否删除%@数据?",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]) TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:YES];
  96. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  97. popupView.priority = 999;
  98. popupView.cornerRadius = adapt(10);
  99. popupView.rectCorners = UIRectCornerAllCorners;
  100. popupView.positionStyle = YMPositionStyleCenter;
  101. popupView.isHideBg = NO;
  102. popupView.bgAlpha = 0.3;
  103. @weakify(popupView)
  104. customView.buttonBlock = ^(BOOL isConfirm) {
  105. @strongify(popupView)
  106. if (isConfirm) {
  107. [ZCHUDHelper showWithStatus:@"正在清理..."];
  108. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  109. [[SDImageCache sharedImageCache] clearMemory];
  110. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  111. }];
  112. NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
  113. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:resultPath];
  114. for (NSString *fileName in enumerator) {
  115. NSString *filePath = [resultPath stringByAppendingPathComponent:fileName];
  116. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  117. }
  118. dispatch_async(dispatch_get_main_queue(), ^{
  119. [ZCHUDHelper showTitle:@"清理完成"];
  120. [self getSettingListData];
  121. });
  122. });
  123. }
  124. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  125. };
  126. [popupView pop];
  127. }
  128. break;
  129. case YMSettingFunctionsTypeGotoRating:
  130. {
  131. [ZCHUDHelper showTitle:@"暂无评分_(:з」∠)_"];
  132. }
  133. break;
  134. case YMSettingFunctionsTypeCancellationAccount:
  135. {
  136. YMCancellationAccountViewModel *cancellationAccountVM = [[YMCancellationAccountViewModel alloc]initWithParams:@{}];
  137. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_CANCELLATION_ACCOUNT) withUserInfo:@{
  138. RouterViewModel:cancellationAccountVM
  139. } completion:nil];
  140. }
  141. break;
  142. case YMSettingFunctionsTypeAboutUs:
  143. {
  144. YMAboutUsViewModel *aboutUsVM = [[YMAboutUsViewModel alloc]initWithParams:@{}];
  145. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_ABOUT_US) withUserInfo:@{
  146. RouterViewModel:aboutUsVM
  147. } completion:nil];
  148. }
  149. break;
  150. case YMSettingFunctionsTypeLogOut:
  151. {
  152. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  153. [customView configutationWithTips:@"您确定要退出登录吗?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:YES];
  154. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  155. popupView.priority = 999;
  156. popupView.cornerRadius = adapt(10);
  157. popupView.rectCorners = UIRectCornerAllCorners;
  158. popupView.positionStyle = YMPositionStyleCenter;
  159. popupView.isHideBg = NO;
  160. popupView.bgAlpha = 0.3;
  161. @weakify(popupView)
  162. customView.buttonBlock = ^(BOOL isConfirm) {
  163. @strongify(popupView)
  164. if (isConfirm) {
  165. [LCTools changeRootToLogin];
  166. }
  167. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  168. };
  169. [popupView pop];
  170. }
  171. break;
  172. default:
  173. break;
  174. }
  175. }];
  176. }
  177. - (void)getSettingListData{
  178. NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
  179. NSUInteger tmpSize = resultPath.fileSize + [[SDImageCache sharedImageCache] getSize];
  180. CGFloat unit = 1000.0;
  181. NSString *sizeText = nil;
  182. if (tmpSize >= unit * unit * unit) { // >= 1GB
  183. sizeText = [NSString stringWithFormat:@"%.1fGB", tmpSize / unit / unit / unit];
  184. } else if (tmpSize >= unit * unit) { // >= 1MB
  185. sizeText = [NSString stringWithFormat:@"%.1fMB", tmpSize / unit / unit];
  186. } else if (tmpSize >= unit) { // >= 1KB
  187. sizeText = [NSString stringWithFormat:@"%.1fKB", tmpSize / unit];
  188. } else { // >= 0B
  189. sizeText = [NSString stringWithFormat:@"%zdB", tmpSize];
  190. }
  191. self.listDataArray = [[@[
  192. @{
  193. @"title":@"账号绑定",
  194. @"detail":@"",
  195. @"content":[LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile,
  196. ParamsCategoryType:@(YMSettingFunctionsTypeAccountBinding),
  197. },
  198. @{
  199. @"title":@"美颜设置",
  200. @"detail":@"",
  201. @"content":@"",
  202. ParamsCategoryType:@(YMSettingFunctionsTypeBeautySetting),
  203. },
  204. @{
  205. @"title":@"消息通知",
  206. @"detail":@"",
  207. @"content":@"",
  208. ParamsCategoryType:@(YMSettingFunctionsTypeChatNotification),
  209. },
  210. @{
  211. @"title":@"打招呼设置",
  212. @"detail":@"",
  213. @"content":@"",
  214. ParamsCategoryType:@(YMSettingFunctionsTypeGreetingSetting),
  215. },
  216. @{
  217. @"title":@"收费设置",
  218. @"detail":@"",
  219. @"content":@"",
  220. ParamsCategoryType:@(YMSettingFunctionsTypeFeesSetting),
  221. },
  222. @{
  223. @"title":@"青少年模式",
  224. @"detail":@"",
  225. @"content":@"",
  226. ParamsCategoryType:@(YMSettingFunctionsTypeAdolescentModel),
  227. },
  228. @{
  229. @"title":@"黑名单",
  230. @"detail":@"",
  231. @"content":@"",
  232. ParamsCategoryType:@(YMSettingFunctionsTypeBlackList),
  233. },
  234. @{
  235. @"title":@"清除缓存",
  236. @"detail":@"",
  237. @"content":sizeText,
  238. ParamsCategoryType:@(YMSettingFunctionsTypeClearCache),
  239. },
  240. @{
  241. @"title":@"去评分",
  242. @"detail":@"",
  243. @"content":@"",
  244. ParamsCategoryType:@(YMSettingFunctionsTypeGotoRating),
  245. },
  246. @{
  247. @"title":@"注销账号",
  248. @"detail":@"(清除所有资料)",
  249. @"content":@"",
  250. ParamsCategoryType:@(YMSettingFunctionsTypeCancellationAccount),
  251. },
  252. @{
  253. @"title":stringFormat(@"关于%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]),
  254. @"detail":@"",
  255. @"content":@"",
  256. ParamsCategoryType:@(YMSettingFunctionsTypeAboutUs),
  257. },
  258. ].rac_sequence filter:^BOOL(NSDictionary * _Nullable settingFunctionsDic) {
  259. YMSettingFunctionsType type = [settingFunctionsDic integerValueForKey:ParamsCategoryType defaultValue:YMSettingFunctionsTypeAboutUs];
  260. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && type == YMSettingFunctionsTypeGreetingSetting) {
  261. return YES;
  262. } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1 && type == YMSettingFunctionsTypeGreetingSetting) {
  263. return NO;
  264. } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && type == YMSettingFunctionsTypeFeesSetting) {
  265. return YES;
  266. } else if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1 && type == YMSettingFunctionsTypeFeesSetting) {
  267. return NO;
  268. }else if(type == YMSettingFunctionsTypeGotoRating){
  269. return NO;
  270. } else {
  271. return YES;
  272. }
  273. }] map:^(NSDictionary * _Nullable dic) {
  274. YMSettingCellViewModel *viewModel = [[YMSettingCellViewModel alloc]initWithParams:@{
  275. ParamsModel:dic
  276. }];
  277. return viewModel;
  278. }].array;
  279. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  280. }
  281. - (RACSubject *)settingFunctionsOperationSubject{
  282. if (!_settingFunctionsOperationSubject) {
  283. _settingFunctionsOperationSubject = [RACSubject subject];
  284. }
  285. return _settingFunctionsOperationSubject;
  286. }
  287. @end