SetViewControllor.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. #import "SetViewControllor.h"
  2. #import "ZFModalTransitionAnimator.h"
  3. #import "SetLogoutCell.h"
  4. #import <JPUSHService.h>
  5. #import "AppDelegate.h"
  6. #import "YBTabBarController.h"
  7. #import "SetCell.h"
  8. #import "BlackListVC.h"
  9. #import <SDWebImage/SDImageCache.h>
  10. #import "PubH5.h"
  11. #import "YBDestroyAccount.h"
  12. #import "YBPrivateVC.h"
  13. #import "YBUserAuthVC.h"
  14. @interface SetViewControllor ()<UITableViewDataSource,UITableViewDelegate> {
  15. int isNewBuid;//判断是不是最新版本
  16. CGFloat _cacheSize;
  17. NSMutableArray *_titleArray;
  18. }
  19. @property (nonatomic, strong) ZFModalTransitionAnimator *animator;
  20. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *toppp;
  21. @end
  22. @implementation SetViewControllor
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.naviView.hidden = YES;
  26. [BGSetting getBgSettingUpdate:NO maintain:NO eventBack:nil];
  27. double size = (double)[[SDImageCache sharedImageCache] totalDiskSize];
  28. _cacheSize = size /1024.0/1024.0;
  29. [self updateCache];
  30. if (self.toppp.constant<80) {
  31. self.toppp.constant += statusbarHeight;
  32. }
  33. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  34. self.navigationController.navigationBar.backgroundColor = RGB_COLOR(@"#F6F6F6", 1);
  35. self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
  36. self.view.backgroundColor = [UIColor blackColor];
  37. self.tableView.tableFooterView = [[UIView alloc]init];
  38. self.tableView.backgroundColor = Normal_Color;
  39. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  40. }
  41. -(void)updateCache {
  42. NSString *judge_boudle = [NSBundle mainBundle].bundleIdentifier;
  43. NSString *aboutStr = YZMsg(@"关于我们");
  44. /*
  45. if ([judge_boudle isEqual:@"chatsifieds.app"]||[judge_boudle isEqual:@"com.ybdsp.video"]) {
  46. aboutStr = YZMsg(@"关于云视");
  47. }
  48. */
  49. NSString *hisBuild = [common ipa_ver];
  50. NSString *updateTitle = YZMsg(@"当前版本");
  51. NSString *updateDes = [NSString stringWithFormat:@"%@(%@)",[PublicObj getAppBuild],YZMsg(@"最新")];
  52. if (![[PublicObj getAppBuild] isEqual:hisBuild]) {
  53. //updateTitle = YZMsg(@"检查更新");
  54. updateDes = [NSString stringWithFormat:@"%@(%@)",[PublicObj getAppBuild],YZMsg(@"可更新")];
  55. }
  56. if ([PublicObj isUp]) {
  57. updateDes = [NSString stringWithFormat:@"%@",[PublicObj getAppBuild]];
  58. }
  59. NSString *cacheStr = [NSString stringWithFormat:@"%.1fM",_cacheSize];
  60. NSString *showLangStr = @"English";
  61. if ([lagType isEqual:ZH_CN]) {
  62. showLangStr = @"简体中文";
  63. }
  64. _titleArray = @[@{@"id":@"0",@"name":YZMsg(@"黑名单"),@"des":@"",@"switch":@"0"},
  65. @{@"id":@"5",@"name":YZMsg(@"注销账号"),@"des":@"",@"switch":@"0"},
  66. @{@"id":@"7",@"name":YZMsg(@"声音音效"),@"des":@"",@"switch":@"1"},
  67. #warning rk_
  68. @{@"id":@"8",@"name":YZMsg(@"语言切换"),@"des":showLangStr,@"switch":@"0"},
  69. @{@"id":@"1",@"name":YZMsg(@"我的认证"),@"des":@"",@"switch":@"0"},
  70. @{@"id":@"2",@"name":aboutStr,@"des":@"",@"switch":@"0"},
  71. @{@"id":@"6",@"name":YZMsg(@"隐私政策"),@"des":@"",@"switch":@"0"},
  72. @{@"id":@"3",@"name":updateTitle,@"des":updateDes,@"switch":@"0"},
  73. @{@"id":@"4",@"name":YZMsg(@"清除缓存"),@"des":cacheStr,@"switch":@"0"},
  74. ].mutableCopy;
  75. // if ([[common getAuthSwitch]isEqual:@"0"]) {
  76. // [_titleArray removeObject:@{@"id":@"1",@"name":YZMsg(@"我的认证"),@"des":@"",}];
  77. // }
  78. }
  79. - (void)viewWillDisappear:(BOOL)animated
  80. {
  81. [super viewWillDisappear:animated];
  82. }
  83. -(void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:YES];
  86. // 获取到是字节
  87. //double size = (double)[[SDImageCache sharedImageCache] getSize];
  88. self.navigationController.navigationBarHidden = YES;
  89. [self navtion];
  90. [self.tableView reloadData];
  91. }
  92. -(void)navtion{
  93. UIView *navtion = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 64+statusbarHeight)];
  94. navtion.backgroundColor = CellRow_Cor;
  95. UILabel *labels = [[UILabel alloc]init];
  96. labels.text = YZMsg(@"个性设置");
  97. [labels setFont:SYS_Font(17)];
  98. labels.textColor = [UIColor whiteColor];
  99. labels.frame = CGRectMake(0, 0+statusbarHeight,_window_width,84);
  100. labels.textAlignment = NSTextAlignmentCenter;
  101. [navtion addSubview:labels];
  102. UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  103. returnBtn.tintColor = [UIColor whiteColor];
  104. UIButton *bigBTN = [[UIButton alloc]initWithFrame:CGRectMake(0, 0+statusbarHeight, _window_width/2, 64)];
  105. [bigBTN addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  106. [navtion addSubview:bigBTN];
  107. returnBtn.frame = CGRectMake(10,22+statusbarHeight,40,40);[returnBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
  108. returnBtn.contentEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
  109. returnBtn.tintColor = [UIColor whiteColor];
  110. [returnBtn setImage:[UIImage imageNamed:@"pub_back"] forState:UIControlStateNormal];
  111. [returnBtn addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  112. [navtion addSubview:returnBtn];
  113. UIButton *btnttttt = [UIButton buttonWithType:UIButtonTypeCustom];
  114. btnttttt.backgroundColor = [UIColor clearColor];
  115. [btnttttt addTarget:self action:@selector(doReturn) forControlEvents:UIControlEventTouchUpInside];
  116. btnttttt.frame = CGRectMake(0,0+statusbarHeight,100,64);
  117. [navtion addSubview:btnttttt];
  118. [self.view addSubview:navtion];
  119. }
  120. -(void)doReturn{
  121. [self.navigationController popViewControllerAnimated:YES];
  122. [self dismissViewControllerAnimated:YES completion:nil];
  123. }
  124. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  125. UIFont *font = SYS_Font(16);//[UIFont fontWithName:@"Heiti SC" size:15];
  126. if (indexPath.section == 0) {
  127. NSDictionary *subDic = _titleArray[indexPath.row];
  128. BOOL switchShow = [minstr([subDic valueForKey:@"switch"]) boolValue];
  129. SetCell *cell = [SetCell cellWithTableView:tableView];
  130. cell.labContrName.text = minstr([subDic valueForKey:@"name"]);
  131. cell.labContrName.textColor = GrayText;
  132. cell.labContrName.font = font;
  133. cell.labDetail.text = minstr([subDic valueForKey:@"des"]);
  134. cell.labDetail.textColor = UIColor.whiteColor;
  135. cell.backgroundColor = cell.contentView.backgroundColor = CellRow_Cor;
  136. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  137. cell.arrowIV.hidden = switchShow;
  138. cell.switchBtn.hidden = !switchShow;
  139. cell.switchBtn.selected = [common getMsgVoiceSwitch];
  140. return cell;
  141. }else{
  142. SetLogoutCell *cell = [[NSBundle mainBundle]loadNibNamed:@"SetLogoutCell" owner:self options:nil].lastObject;
  143. cell.backgroundColor = cell.contentView.backgroundColor = CellRow_Cor;
  144. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  145. return cell;
  146. }
  147. }
  148. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  149. return nil;
  150. }
  151. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  152. //判断当前分区返回分区行数
  153. if (section == 0 ) {
  154. return _titleArray.count;
  155. }
  156. else
  157. {
  158. return 1;
  159. }
  160. }
  161. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  162. {
  163. //返回分区数
  164. return 2;
  165. }
  166. - ( CGFloat )tableView:( UITableView *)tableView heightForHeaderInSection:( NSInteger )section
  167. {
  168. if (section==1) {
  169. return 30;
  170. }else{
  171. return 0.01;
  172. }
  173. }
  174. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger) section
  175. {
  176. return 1;
  177. }
  178. //点击事件
  179. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  180. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  181. if (indexPath.section == 0) {
  182. NSDictionary *subDic = _titleArray[indexPath.row];
  183. int idInt = [minstr([subDic valueForKey:@"id"]) intValue];
  184. switch (idInt) {
  185. case 0:{
  186. //黑名单
  187. BlackListVC *blac = [[BlackListVC alloc]init];
  188. [self.navigationController pushViewController:blac animated:YES];
  189. }break;
  190. case 1:{
  191. //我的认证
  192. /*
  193. PubH5 *h5 = [[PubH5 alloc]init];
  194. h5.url = [NSString stringWithFormat:@"%@/Appapi/Auth/index?uid=%@&token=%@",h5url,[Config getOwnID],[Config getOwnToken]];
  195. [self.navigationController pushViewController:h5 animated:YES];
  196. */
  197. YBUserAuthVC *authVC = [[YBUserAuthVC alloc]init];
  198. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:authVC animated:YES];
  199. }break;
  200. case 2:{
  201. //关于云视
  202. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  203. NSNumber *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  204. NSString *build = [NSString stringWithFormat:@"%@",app_build];
  205. PubH5 *h5vc = [[PubH5 alloc]init];
  206. h5vc.url = [NSString stringWithFormat:@"%@/appapi/about/index?version=%@&uid=%@&token=%@&device=%@&ios=1",h5url,build,[Config getOwnID],[Config getOwnToken],[PublicObj iphoneType]];
  207. [self.navigationController pushViewController:h5vc animated:YES];
  208. }break;
  209. case 3:{
  210. //版本更新
  211. [self getbanben];
  212. }break;
  213. case 4:{
  214. [StorageConfig clearResTime];
  215. //清除缓存
  216. //[[SDImageCache sharedImageCache] clearDisk];
  217. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  218. }];
  219. // 设置为0
  220. //NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches/ImageCache"];
  221. // 获取到是字节
  222. //double size = (double)[[SDImageCache sharedImageCache] getSize];
  223. double size = (double)[[SDImageCache sharedImageCache] totalDiskSize];
  224. _cacheSize = size /1024.0/1024.0;
  225. [MBProgressHUD showPop:YZMsg(@"清除成功!")];
  226. [self updateCache];
  227. [_tableView reloadData];
  228. }break;
  229. case 5:{
  230. //注销账号
  231. YBDestroyAccount *desVC = [[YBDestroyAccount alloc]init];
  232. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:desVC animated:YES];
  233. }break;
  234. case 6:{
  235. //隐私政策
  236. YBPrivateVC *desVC = [[YBPrivateVC alloc]init];
  237. desVC.hideBottom = YES;
  238. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:desVC animated:YES];
  239. }break;
  240. case 8:{
  241. //语言设置
  242. [self setLanguage];
  243. }break;
  244. default:{
  245. }break;
  246. }
  247. }else if (indexPath.section == 1){
  248. [self quitAlert];
  249. }
  250. }
  251. -(void)setLanguage {
  252. YBWeakSelf;
  253. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:nil];
  254. [sheet addActionWithType:RKSheet_Default andTitle:@"简体中文" complete:^{
  255. [weakSelf chageLang:ZH_CN];
  256. }];
  257. [sheet addActionWithType:RKSheet_Default andTitle:@"English" complete:^{
  258. [weakSelf chageLang:EN];
  259. }];
  260. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  261. }];
  262. [sheet showSheet];
  263. }
  264. -(void)chageLang:(NSString *)curLang {
  265. [[YBLanguageTools shareInstance] resetLanguage:curLang withFrom:@"setvc"];
  266. }
  267. -(void)getbanben{
  268. if ([PublicObj isUp]) {
  269. return;
  270. }
  271. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  272. NSNumber *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];//本地
  273. NSNumber *build = (NSNumber *)[common ipa_ver];//远程
  274. NSComparisonResult r = [app_build compare:build];
  275. if (r == NSOrderedAscending || r == NSOrderedDescending) {//可改为if(r == -1L)
  276. [[UIApplication sharedApplication]openURL:[NSURL URLWithString:[common app_ios]]];
  277. }else if(r == NSOrderedSame) {//可改为if(r == 0L)
  278. [MBProgressHUD showPop:YZMsg(@"当前已是最新版本")];
  279. }
  280. }
  281. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  282. return 50;
  283. }
  284. - (void)clearTmpPics
  285. {
  286. //[[SDImageCache sharedImageCache] clearDisk];
  287. [[SDImageCache sharedImageCache]clearDiskOnCompletion:^{
  288. }];
  289. }
  290. //MARK:-设置tableivew分割线
  291. -(void)setTableViewSeparator
  292. {
  293. if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
  294. [self.tableView setSeparatorInset:UIEdgeInsetsZero];
  295. }
  296. if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
  297. [self.tableView setLayoutMargins:UIEdgeInsetsZero];
  298. }
  299. }
  300. -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPa
  301. {
  302. if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
  303. [cell setLayoutMargins:UIEdgeInsetsZero];
  304. }
  305. if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
  306. [cell setSeparatorInset:UIEdgeInsetsZero];
  307. }
  308. }
  309. -(void)quitAlert {
  310. YBWeakSelf;
  311. RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
  312. [sheet addActionWithType:RKSheet_FunPink andTitle:YZMsg(@"继续退出") complete:^{
  313. [weakSelf quitLogin];
  314. }];
  315. [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
  316. }];
  317. [sheet showSheet];
  318. }
  319. -(void)quitLogin
  320. {
  321. [[NSNotificationCenter defaultCenter]postNotificationName:@"hideHomeVideoRed" object:nil];
  322. //清空所有缓存
  323. //NSString*appDomain = [[NSBundle mainBundle]bundleIdentifier];
  324. //[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
  325. [PublicObj resetUserToVisitor];
  326. YBTabBarController *root = [[YBTabBarController alloc]initWithAlert:NO];
  327. YBNavigationController *navroot = [[YBNavigationController alloc]initWithRootViewController:root];
  328. UIApplication *app =[UIApplication sharedApplication];
  329. AppDelegate *app2 = (AppDelegate*)app.delegate;
  330. [app2.window removeAllSubViews];
  331. app2.window.rootViewController = navroot;
  332. }
  333. @end