YOUPAILCSettingVC.m 18 KB

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