YOUPAIBBSettingVC.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. //
  2. // YOUPAIBBSettingVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2021/11/1.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIBBSettingVC.h"
  9. #import "YOUPAIZYSettingCell.h"
  10. #import "YOUPAILCBindPhoneAccountVC.h"
  11. #import "YOUPAILCMediaChatRecordVC.h"
  12. #import "YOUPAILCBlackListVC.h"
  13. #import "YOUPAILCNewChatNoticationVC.h"
  14. #import "YOUPAILCAboutVC.h"
  15. #import "YOUPAILCUpdateVersionVC.h"
  16. #import "UIViewController+TFPresent.h"
  17. #import "YOUPAILPYoungSettingVC.h"
  18. @interface YOUPAIBBSettingVC ()<UITableViewDataSource,UITableViewDelegate>
  19. @property(nonatomic,strong)UITableView* youpaiptableView;
  20. @property(nonatomic,strong)UIView* youpaipfooterView;
  21. /* <#Annotation#> */
  22. @property (strong, nonatomic) NSArray *youpaiptitleArr;
  23. @end
  24. @implementation YOUPAIBBSettingVC
  25. - (void)viewWillAppear:(BOOL)animated{
  26. [super viewWillAppear:animated];
  27. [self.youpaiptableView reloadData];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. self.navigationItem.title = @"设置";
  32. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender != 1) { //男
  33. self.youpaiptitleArr = @[@"账号绑定",@"消息通知",@"青少年模式",@"黑名单",@"清除缓存",@"清除所有聊天记录",@"去评分",@"关于花蝶"];
  34. }else{
  35. self.youpaiptitleArr = @[@"账号绑定",@"消息通知",@"黑名单",@"清除缓存",@"清除所有聊天记录",@"去评分",@"关于花蝶"];
  36. }
  37. [self.view addSubview:self.youpaiptableView];
  38. self.youpaiptableView.tableFooterView = self.youpaipfooterView;
  39. }
  40. -(UIView *)youpaipfooterView{
  41. if (!_youpaipfooterView) {
  42. _youpaipfooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 120 + SafeHeight)];
  43. _youpaipfooterView.backgroundColor = LCWhiteColor;
  44. UIButton* startBtn = [[UIButton alloc]initWithFrame:CGRectMake(40.0f,40.0f, KScreenWidth - 80.0f, 49.0f)];
  45. startBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
  46. startBtn.titleLabel.font = LCFont16;
  47. startBtn.layer.cornerRadius = 24.5f;
  48. startBtn.layer.masksToBounds = YES;
  49. [startBtn setTitle:@"退出登录" forState:(UIControlStateNormal)];
  50. [startBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  51. [startBtn addTarget:self action:@selector(youpaifbackClick) forControlEvents:(UIControlEventTouchUpInside)];
  52. [_youpaipfooterView addSubview:startBtn];
  53. }
  54. return _youpaipfooterView;
  55. }
  56. - (UITableView *)youpaiptableView{
  57. if (!_youpaiptableView) {
  58. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
  59. _youpaiptableView.showsVerticalScrollIndicator = NO;
  60. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  61. _youpaiptableView.backgroundColor = LCWhiteColor;
  62. // _tableView.separatorInset = UIEdgeInsetsMake(0,34, 0,34);
  63. _youpaiptableView.delegate = self;
  64. _youpaiptableView.dataSource = self;
  65. if (@available(iOS 15.0, *)) {
  66. _youpaiptableView.sectionHeaderTopPadding = 0;
  67. }
  68. }
  69. return _youpaiptableView;
  70. }
  71. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  72. return self.youpaiptitleArr.count;
  73. }
  74. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  75. return CGFLOAT_MIN;
  76. }
  77. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  78. return [[UIView alloc]init];
  79. }
  80. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  81. return 54.0f;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  84. YOUPAIZYSettingCell * cell = [[YOUPAIZYSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commonCell"];
  85. NSString *titleStr = self.youpaiptitleArr[indexPath.row];
  86. if ([titleStr isEqualToString:@"账号绑定"]) {
  87. cell.youpaipheadLabel.text = @"账号绑定";
  88. cell.youpaiparrowLabel.text = [LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile;
  89. if (cell.youpaiparrowLabel.text.length != 0) {
  90. cell.youpaiparrowImgView.hidden = YES;
  91. [cell.youpaiparrowLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  92. make.right.offset(-20.0f);
  93. make.centerY.equalTo(cell.youpaipbaseView);
  94. make.height.equalTo(15);
  95. }];
  96. }else{
  97. cell.youpaiparrowImgView.hidden = NO;
  98. [cell.youpaiparrowLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  99. make.right.equalTo(cell.youpaiparrowImgView.left).offset(-5);
  100. make.centerY.equalTo(cell.youpaipbaseView);
  101. make.height.equalTo(15);
  102. }];
  103. }
  104. }else if ([titleStr isEqualToString:@"黑名单"]){
  105. // if (indexPath.row==0) {
  106. // cell.headLabel.text = @"通话记录";
  107. // }else{
  108. cell.youpaipheadLabel.text = @"黑名单";
  109. // }
  110. }
  111. /*else if ([titleStr isEqualToString:@"勿扰模式"]){
  112. cell.hintLabel.hidden = NO;
  113. cell.headLabel.text = @"勿扰模式";
  114. cell.rightSwitch.hidden = NO;
  115. cell.arrowImgView.hidden = YES;
  116. if ([LCSaveModel getUserModel].userinfo.is_anchor == 1) {
  117. cell.rightSwitch.selected = ![LCSaveData getVideoOpenStatu];
  118. [cell.rightSwitch addTarget:self action:@selector(youpaifvideoSwitchValueChange:) forControlEvents:UIControlEventTouchUpInside];
  119. }else{
  120. cell.rightSwitch.selected = [LCSaveData getProfileWuraoStatus];
  121. [cell.rightSwitch addTarget:self action:@selector(youpaifopenDontDisturb) forControlEvents:UIControlEventTouchUpInside];
  122. }
  123. }*/else if ([titleStr isEqualToString:@"青少年模式"]){
  124. // if (indexPath.row==0) {
  125. // cell.headLabel.text = @"通话记录";
  126. // }else{
  127. cell.youpaipheadLabel.text = @"青少年模式";
  128. // }
  129. }
  130. else if ([titleStr isEqualToString:@"消息通知"]){
  131. cell.youpaipheadLabel.text = @"消息通知";
  132. }else if ([titleStr isEqualToString:@"清除缓存"]){
  133. cell.youpaipheadLabel.text = @"清除缓存";
  134. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  135. NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
  136. NSUInteger tmpSize = resultPath.fileSize+[[SDImageCache sharedImageCache] getSize];
  137. CGFloat unit = 1000.0;
  138. NSString *sizeText = nil;
  139. if (tmpSize >= unit * unit * unit) { // >= 1GB
  140. sizeText = [NSString stringWithFormat:@"%.1fGB", tmpSize / unit / unit / unit];
  141. } else if (tmpSize >= unit * unit) { // >= 1MB
  142. sizeText = [NSString stringWithFormat:@"%.1fMB", tmpSize / unit / unit];
  143. } else if (tmpSize >= unit) { // >= 1KB
  144. sizeText = [NSString stringWithFormat:@"%.1fKB", tmpSize / unit];
  145. } else { // >= 0B
  146. sizeText = [NSString stringWithFormat:@"%zdB", tmpSize];
  147. }
  148. dispatch_async(dispatch_get_main_queue(), ^{
  149. cell.youpaiparrowLabel.text = sizeText;
  150. });
  151. });
  152. }else if ([titleStr isEqualToString:@"清除所有聊天记录"]){
  153. cell.youpaipheadLabel.text = @"清除所有聊天记录";
  154. }
  155. else if ([titleStr isEqualToString:@"去评分"]){
  156. cell.youpaipheadLabel.text = @"去评分";
  157. }else if ([titleStr isEqualToString:@"关于花蝶"]){
  158. cell.youpaipheadLabel.text = @"关于花蝶";
  159. }
  160. return cell;
  161. }
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  163. NSString *titleStr = self.youpaiptitleArr[indexPath.row];
  164. if ([titleStr isEqualToString:@"账号绑定"]) {
  165. if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipmobile.length == 0) {
  166. YOUPAILCBindPhoneAccountVC* bindAccount = [[YOUPAILCBindPhoneAccountVC alloc]init];
  167. [self.navigationController pushViewController:bindAccount animated:YES];
  168. }
  169. }else if ([titleStr isEqualToString:@"黑名单"]){
  170. YOUPAILCBlackListVC* black = [[YOUPAILCBlackListVC alloc]init];
  171. [self.navigationController pushViewController:black animated:YES];
  172. }else if ([titleStr isEqualToString:@"勿扰模式"]){
  173. }else if ([titleStr isEqualToString:@"青少年模式"]){
  174. YOUPAILPYoungSettingVC* setting = [[YOUPAILPYoungSettingVC alloc]init];
  175. [self.navigationController pushViewController:setting animated:YES];
  176. }else if ([titleStr isEqualToString:@"消息通知"]){
  177. YOUPAILCNewChatNoticationVC * noti = [[YOUPAILCNewChatNoticationVC alloc]init];
  178. [self.navigationController pushViewController:noti animated:YES];
  179. }else if ([titleStr isEqualToString:@"清除缓存"]){
  180. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"是否确定清除缓存?" preferredStyle:UIAlertControllerStyleAlert];
  181. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  182. }];
  183. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  184. [ZCHUDHelper showWithStatus:@"正在清理..."];
  185. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  186. [[SDImageCache sharedImageCache] clearMemory];
  187. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  188. }];
  189. NSString * resultPath = [DocPath stringByAppendingPathComponent:@"/save"];
  190. NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:resultPath];
  191. for (NSString *fileName in enumerator) {
  192. NSString *filePath = [resultPath stringByAppendingPathComponent:fileName];
  193. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  194. }
  195. dispatch_async(dispatch_get_main_queue(), ^{
  196. [ZCHUDHelper showTitle:@"清理完成"];
  197. [self.youpaiptableView reloadData];
  198. });
  199. });
  200. }];
  201. [alertController addAction:cancelAction];
  202. [alertController addAction:okAction];
  203. [self presentViewController:alertController animated:YES completion:nil];
  204. }else if ([titleStr isEqualToString:@"清除所有聊天记录"]){
  205. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"是否确定清除聊天记录?" preferredStyle:UIAlertControllerStyleAlert];
  206. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  207. }];
  208. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  209. id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
  210. NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
  211. deleteOption.removeSession = YES;
  212. deleteOption.removeTable = YES;
  213. [manager deleteAllMessages:deleteOption];
  214. [ZCHUDHelper showTitle:@"聊天记录已清空"];
  215. }];
  216. [alertController addAction:cancelAction];
  217. [alertController addAction:okAction];
  218. [self presentViewController:alertController animated:YES completion:nil];
  219. }
  220. else if ([titleStr isEqualToString:@"去评分"]){
  221. NSString *urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", APPID];
  222. if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:urlStr]]) {
  223. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
  224. }
  225. }else if ([titleStr isEqualToString:@"关于花蝶"]){
  226. YOUPAILCAboutVC* about = [[YOUPAILCAboutVC alloc]init];
  227. [self.navigationController pushViewController:about animated:YES];
  228. }
  229. }
  230. - (void)youpaifbackClick{
  231. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"退出账号" message:@"是否退出当前账号登录状态?" preferredStyle:UIAlertControllerStyleAlert];
  232. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  233. }];
  234. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  235. [self.navigationController popToRootViewControllerAnimated:NO];
  236. [LCTools changeRootToLogin];
  237. }];
  238. [alertController addAction:cancelAction];
  239. [alertController addAction:okAction];
  240. [self presentViewController:alertController animated:YES completion:nil];
  241. }
  242. -(void)youpaifcheckAppUpdate:(BOOL)need
  243. {
  244. [ZCHUDHelper showWithStatus:@"请求中..."];
  245. [LCHttpHelper requestWithURLString:CheckUpdateVersion parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  246. NSDictionary *dict = (NSDictionary *)responseObject;
  247. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  248. if (code == 0)
  249. {
  250. NSString *newVersion = [[dict objectForKey:@"data"] objectForKey:@"newversion"];
  251. //NSString *myVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  252. NSString *app_build = [[UIApplication sharedApplication] appVersion];
  253. if ([newVersion compare:app_build options:NSCaseInsensitiveSearch] > 0) {
  254. [ZCHUDHelper dismiss];
  255. YOUPAILCUpdateVersionVC *VC= [[YOUPAILCUpdateVersionVC alloc]init];
  256. VC.youpaipenforce = [[[dict objectForKey:@"data"] objectForKey:@"enforce"]integerValue];
  257. VC.youpaipdownLoadUrl = [[dict objectForKey:@"data"] objectForKey:@"downloadurl"];
  258. VC.youpaipversionStr = [NSString stringWithFormat:@"版本号:%@",newVersion];
  259. VC.youpaipupdateText = [[dict objectForKey:@"data"] objectForKey:@"upgradetext"];
  260. VC.vWidth = KScreenWidth - 70;
  261. NSDictionary *attrs = @{NSFontAttributeName : [UIFont systemFontOfSize:14]};
  262. CGSize maxSize= [VC.youpaipupdateText boundingRectWithSize:CGSizeMake(VC.vWidth-116,66) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
  263. if(maxSize.height<28)
  264. {
  265. maxSize.height = 28;
  266. }
  267. else{
  268. maxSize.height = maxSize.height+20;
  269. }
  270. VC.vHeight = VC.vWidth*203/305.0 +86 + maxSize.height + 120;
  271. VC.isTouchDismiss = YES;
  272. [self TFPresentVC:VC completion:^{
  273. }];
  274. }else{
  275. if (need) {
  276. // [ZCHUDHelper dismiss];
  277. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)0.5*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  278. [ZCHUDHelper showTitle:@"已经是最新版本" showtime:1];
  279. });
  280. }
  281. }
  282. }
  283. } failure:^(NSError *error) {
  284. [ZCHUDHelper dismiss];
  285. }];
  286. }
  287. - (void)youpaifvideoSwitchValueChange:(UIButton*)switchView{
  288. NSInteger status = 0;
  289. if (switchView.selected == NO) {//将状态置为1空闲
  290. status = 0;
  291. }else{
  292. status = 1;
  293. }
  294. [LCHttpHelper requestWithURLString:BigCastSetVideoStatus parameters:@{@"status":@(status)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  295. NSDictionary* dict = (NSDictionary*)responseObject;
  296. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  297. if (code==0) {
  298. if (status==1) {
  299. [LCSaveData saveVideoOpenStatu:YES];
  300. }else{
  301. [LCSaveData saveVideoOpenStatu:NO];
  302. }
  303. }
  304. [self.youpaiptableView reloadData];
  305. } failure:^(NSError *error) {
  306. }];
  307. }
  308. - (void)youpaifopenDontDisturb{
  309. NSString *status = [LCSaveData getProfileWuraoStatus] ? @"0" : @"1";
  310. [LCHttpHelper requestWithURLString:SetWuRaoStatus parameters:@{@"is_msg_refuse":status} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  311. NSDictionary* dict = (NSDictionary*)responseObject;
  312. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  313. if (code==0) {
  314. if ([status isEqualToString:@"1"]) {
  315. [ZCHUDHelper showTitle:@"打开勿打扰"];
  316. [LCSaveData saveProfileWuraoStatus:YES];
  317. [self.youpaiptableView reloadData];
  318. }else{
  319. [ZCHUDHelper showTitle:@"关闭勿打扰"];
  320. [LCSaveData saveProfileWuraoStatus:NO];
  321. [self.youpaiptableView reloadData];
  322. }
  323. }
  324. } failure:^(NSError *error) {
  325. }];
  326. }
  327. @end