BogoSetViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. //
  2. // BogoSetViewController.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/9/26.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoSetViewController.h"
  9. #import "SetTableViewCell.h"
  10. #import "AccountSecurityViewController.h"
  11. #import "FollowerViewController.h"
  12. #import "LoginViewController.h"
  13. #import "LoginOutModel.h"
  14. #import "PushManageViewController.h"
  15. #import "RecommendedPersonViewController.h"
  16. #import "BogoLanguageAlertView.h"
  17. #import "BogoSetPriviteNobleViewController.h"
  18. #import "BogoSetAccountViewController.h"
  19. #import "ChatSettingVC.h"
  20. @interface BogoSetViewController ()<UITableViewDelegate,UITableViewDataSource>
  21. @property(nonatomic, strong) UITableView *tableView;
  22. @property(nonatomic, strong) NSMutableArray *listArr;
  23. @property(nonatomic, strong) BogoLanguageAlertView *languageView;
  24. @end
  25. @implementation BogoSetViewController
  26. - (void)viewWillAppear:(BOOL)animated {
  27. [super viewWillAppear:animated];
  28. self.navigationController.navigationBar.hidden = YES;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. // Do any additional setup after loading the view.
  33. self.navigationItem.title = ASLocalizedString(@"系统设置");
  34. self.view.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  35. UIImageView * navView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationHeight)];
  36. navView.image = [UIImage imageNamed:@"mine_navbg"];
  37. navView.userInteractionEnabled = YES;
  38. [self.view addSubview:navView];
  39. UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  41. backBtn.frame = CGRectMake(10, StatusBarHeight, 44, 44);
  42. [backBtn addTarget:self action:@selector(backLastVC) forControlEvents:UIControlEventTouchUpInside];
  43. [navView addSubview:backBtn];
  44. UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
  45. titleLabel.centerX = SCREEN_WIDTH/2;
  46. titleLabel.centerY = backBtn.centerY;
  47. titleLabel.text = ASLocalizedString(@"系统设置");
  48. titleLabel.textColor = UIColor.blackColor;
  49. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  50. titleLabel.textAlignment = NSTextAlignmentCenter;
  51. [navView addSubview:titleLabel];
  52. [self setupBackBtnWithBlock:nil];
  53. [self setModel];
  54. [self.view addSubview:self.tableView];
  55. UIButton * logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  56. [logoutBtn setTitle:ASLocalizedString(@"退出登录") forState:UIControlStateNormal];
  57. [logoutBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  58. [logoutBtn addTarget:self action:@selector(loginOutAction) forControlEvents:UIControlEventTouchUpInside];
  59. logoutBtn.frame = CGRectMake(62, self.tableView.bottom + 50, SCREEN_WIDTH - 124, 45);
  60. [logoutBtn setBackgroundImage:[UIImage imageNamed:@"widthBtnBg"] forState:UIControlStateNormal];
  61. [self.view addSubview:logoutBtn];
  62. }
  63. -(void)setModel{
  64. if ([[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"]) {
  65. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"账号与安全")],@[ASLocalizedString(@"黑名单管理"),ASLocalizedString(@"隐私特权设置"),ASLocalizedString(@"消息推送设置"),ASLocalizedString(@"聊天设置"),ASLocalizedString(@"切换语言")],@[ASLocalizedString(@"帮助与反馈"),ASLocalizedString(@"清理缓存"),ASLocalizedString(@"检查更新"),ASLocalizedString(@"关于我们")], nil];
  66. if (kIsCheckingVersion()) {
  67. [_listArr removeAllObjects];
  68. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"账号与安全")],@[ASLocalizedString(@"黑名单管理"),ASLocalizedString(@"隐私特权设置"),ASLocalizedString(@"消息推送设置"),ASLocalizedString(@"聊天设置"),ASLocalizedString(@"切换语言")],@[ASLocalizedString(@"帮助与反馈"),ASLocalizedString(@"清理缓存"),ASLocalizedString(@"关于我们")], nil];
  69. }
  70. }else{
  71. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"账号与安全")],@[ASLocalizedString(@"黑名单管理"),ASLocalizedString(@"消息推送设置"),ASLocalizedString(@"聊天设置"),ASLocalizedString(@"切换语言")],@[ASLocalizedString(@"帮助与反馈"),ASLocalizedString(@"清理缓存"),ASLocalizedString(@"检查更新"),ASLocalizedString(@"关于我们")], nil];
  72. if (kIsCheckingVersion()) {
  73. [_listArr removeAllObjects];
  74. _listArr = [NSMutableArray arrayWithObjects:@[ASLocalizedString(@"账号与安全")],@[ASLocalizedString(@"黑名单管理"),ASLocalizedString(@"消息推送设置"),ASLocalizedString(@"聊天设置"),ASLocalizedString(@"切换语言")],@[ASLocalizedString(@"帮助与反馈"),ASLocalizedString(@"清理缓存"),ASLocalizedString(@"关于我们")], nil];
  75. }
  76. }
  77. }
  78. - (void)setupBackBtnWithBlock:(BackBlock)backBlock
  79. {
  80. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(onReturnBtnPress) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  81. }
  82. #pragma mark - UITableView Datasource
  83. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  84. return 3;
  85. }
  86. #pragma mark -- 返回区头的高度
  87. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  88. {
  89. return section == 0 ? 0 : 5;
  90. }
  91. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  92. {
  93. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 5)];
  94. headView.backgroundColor = kAppSpaceColor2;
  95. return headView;
  96. }
  97. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  98. {
  99. if([[[NSBundle mainBundle]bundleIdentifier] isEqualToString:@"com.zebo.zebolive"])
  100. {
  101. SetTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  102. if([cell.setText.text isEqualToString:ASLocalizedString(@"切换语言")])
  103. {
  104. return kRealValue(0.01);
  105. }
  106. else
  107. {
  108. }
  109. }
  110. return kRealValue(44);
  111. }
  112. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  113. {
  114. switch (section)
  115. {
  116. case 0:
  117. {
  118. return 1;
  119. }
  120. break;
  121. case 1:
  122. {
  123. if ([[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"]) {
  124. return 5;
  125. }
  126. else
  127. return 4;
  128. }
  129. break;
  130. case 2:
  131. {
  132. if (kIsCheckingVersion()) {
  133. return 3;
  134. }
  135. return 4;
  136. }
  137. break;
  138. case 3:
  139. {
  140. return 1;
  141. }
  142. break;
  143. default:
  144. break;
  145. }
  146. return 0;
  147. }
  148. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  149. {
  150. SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SetTableViewCell" forIndexPath:indexPath];
  151. [cell configurationCellWithSection:indexPath.section row:indexPath.row distribution_module:self.BuguLive.appModel.distribution_module];
  152. if (indexPath.section == 3) {
  153. cell.setText.textColor = [UIColor colorWithHexString:@"#9152F8"];
  154. }
  155. cell.line.hidden = YES;
  156. if (indexPath.section == 0 || (indexPath.section == 1 && indexPath.row == 3) || (indexPath.section == 2 && indexPath.row == 2) || indexPath.section == 3) {
  157. cell.line.hidden = YES;
  158. }
  159. cell.loginBack.textColor = [UIColor colorWithHexString:@"#9152F8"];
  160. if([[[NSBundle mainBundle]bundleIdentifier] isEqualToString:@"com.zebo.zebolive"])
  161. {
  162. if([cell.setText.text isEqualToString:ASLocalizedString(@"切换语言")])
  163. {
  164. cell.hidden = YES;
  165. }
  166. else
  167. {
  168. cell.hidden = NO;
  169. }
  170. }
  171. return cell;
  172. }
  173. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  174. {
  175. NSArray *sectionArr = self.listArr[indexPath.section];
  176. NSString *contentStr = sectionArr[indexPath.row];
  177. if ([contentStr isEqualToString:ASLocalizedString(@"账号与安全")]) {
  178. //账户安全点击事件
  179. BogoSetAccountViewController *acVC = [[BogoSetAccountViewController alloc]init];
  180. // acVC.userid = self.userID;
  181. [self.navigationController pushViewController:acVC animated:YES];
  182. return;
  183. }
  184. if ([contentStr isEqualToString:ASLocalizedString(@"黑名单管理")]) {
  185. // 黑名单点击事件
  186. FollowerViewController *followVC = [[FollowerViewController alloc]init];
  187. followVC.type = @"3";
  188. followVC.user_id = self.userID;
  189. [self.navigationController pushViewController:followVC animated:YES];
  190. return;
  191. }
  192. if ([contentStr isEqualToString:ASLocalizedString(@"隐私特权设置")]) {
  193. BogoSetPriviteNobleViewController *vc = [BogoSetPriviteNobleViewController new];
  194. [self.navigationController pushViewController:vc animated:YES];
  195. return;
  196. }
  197. if ([contentStr isEqualToString:ASLocalizedString(@"消息推送设置")]) {
  198. // 推送管理点击事件
  199. PushManageViewController *pushManageVC = [[PushManageViewController alloc]init];
  200. pushManageVC.userId = self.userID;
  201. [self.navigationController pushViewController:pushManageVC animated:YES];
  202. return;
  203. }
  204. if ([contentStr isEqualToString:ASLocalizedString(@"聊天设置")]) {
  205. //点击事件
  206. ChatSettingVC *pushManageVC = [[ChatSettingVC alloc]init];
  207. [self.navigationController pushViewController:pushManageVC animated:YES];
  208. return;
  209. }
  210. if ([contentStr isEqualToString:ASLocalizedString(@"切换语言")]) {
  211. [self gotoLanguage];
  212. return;
  213. }
  214. if ([contentStr isEqualToString:ASLocalizedString(@"帮助与反馈")]) {
  215. // 帮助与反馈点击事件
  216. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_help_feedback isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  217. tmpController.navTitleStr = ASLocalizedString(@"帮助与反馈");
  218. [self.navigationController pushViewController:tmpController animated:YES];
  219. return;
  220. }
  221. if ([contentStr isEqualToString:ASLocalizedString(@"清理缓存")]) {
  222. // 帮助与反馈点击事件
  223. // SetTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  224. [[[SDWebImageManager sharedManager] imageCache] clearWithCacheType:SDImageCacheTypeAll completion:^{
  225. [self.tableView reloadSection:2 withRowAnimation:UITableViewRowAnimationFade];
  226. }];
  227. return;
  228. }
  229. if ([contentStr isEqualToString:ASLocalizedString(@"检查更新")]) {
  230. [self checkUpdate];
  231. return;
  232. }
  233. if ([contentStr isEqualToString:ASLocalizedString(@"关于我们")]) {
  234. // 关于我们
  235. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_about_we isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  236. tmpController.navTitleStr = ASLocalizedString(@"关于我们");
  237. [self.navigationController pushViewController:tmpController animated:YES];
  238. return;
  239. }
  240. if ([contentStr isEqualToString:ASLocalizedString(@"退出登录")]) {
  241. [self loginOutAction];
  242. return;
  243. }
  244. }
  245. - (void)gotoLanguage {
  246. [self.languageView show:[AppDelegate sharedAppDelegate].topViewController.view.superview.superview];
  247. }
  248. -(void)checkUpdate{
  249. if (self.BuguLive.appModel.version.has_upgrade == 1)
  250. {
  251. self.BuguLive.ios_down_url = self.BuguLive.appModel.version.ios_down_url;
  252. // 强制升级:forced_upgrade ; 0:非强制升级,可取消; 1:强制升级
  253. if (self.BuguLive.appModel.version.forced_upgrade == 1)
  254. {
  255. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  256. }
  257. else
  258. {
  259. FWWeakify(self)
  260. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"发现新版本,需要升级吗?")destructiveAction:^{
  261. FWStrongify(self)
  262. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  263. } cancelAction:^{
  264. }];
  265. }
  266. }
  267. else
  268. {
  269. [FanweMessage alert:ASLocalizedString(@"当前已是最新版本!")];
  270. }
  271. if (!self.BuguLive.appModel.short_name || [self.BuguLive.appModel.short_name isEqualToString:@""])
  272. {
  273. self.BuguLive.appModel.short_name = ShortNameStr;
  274. }
  275. }
  276. -(void)loginOutAction{
  277. // 退出登录
  278. NSString * preferredLang = [[NSUserDefaults standardUserDefaults] objectForKey:KAppLanguage];
  279. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  280. //因为上面的方法会全部清除本APP的所有本地存储,所以这里预言再设置一遍
  281. [[LocalizationSystem sharedLocalSystem] setLanguage:preferredLang];
  282. NSLog(@" 5当前语言 = %@",preferredLang);
  283. [self setNetworing];
  284. }
  285. - (void)backLastVC {
  286. [self.navigationController popViewControllerAnimated:YES];
  287. }
  288. #pragma mark -- 退出登录
  289. - (void)setNetworing
  290. {
  291. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  292. [parmDict setObject:@"login" forKey:@"ctl"];
  293. [parmDict setObject:@"loginout" forKey:@"act"];
  294. if (self.userID.length > 0)
  295. {
  296. [parmDict setObject:self.userID forKey:@"to_user_id"];
  297. }
  298. FWWeakify(self)
  299. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  300. if ([responseJson toInt:@"status"] == 1)
  301. {
  302. FWStrongify(self)
  303. [self.tableView reloadData];
  304. // [self.navigationController popViewControllerAnimated:YES];
  305. [self.navigationController popViewControllerAnimated:NO];
  306. [[IMAPlatform sharedInstance] logout:^{
  307. [[AppDelegate sharedAppDelegate] enterLoginUI];
  308. } fail:^(int code, NSString *msg) {
  309. [[AppDelegate sharedAppDelegate] enterLoginUI];
  310. }];
  311. [AppViewModel loadInit];
  312. }else
  313. {
  314. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  315. }
  316. } FailureBlock:^(NSError *error) {
  317. }];
  318. }
  319. -(BogoLanguageAlertView *)languageView{
  320. if (!_languageView) {
  321. _languageView = [[BogoLanguageAlertView alloc]initWithFrame:CGRectMake(kRealValue(20), 0, kScreenW - kRealValue(20 * 2), kRealValue(400))];
  322. }
  323. return _languageView;
  324. }
  325. -(UITableView *)tableView{
  326. if (!_tableView) {
  327. float height = 0;
  328. if ([[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"]) {
  329. height = 44 * 10 + 20;
  330. if (kIsCheckingVersion()) {
  331. height = 44 * 9 + 20;
  332. }
  333. }else{
  334. height = 44 * 9 + 20;
  335. if (kIsCheckingVersion()) {
  336. height = 44 * 8 + 20;
  337. }
  338. }
  339. if (height > kScreenH - NavigationHeight - 100) {
  340. height = kScreenH - NavigationHeight - 100;
  341. }
  342. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavigationHeight, kScreenW, height) style:UITableViewStylePlain];
  343. _tableView.delegate = self;
  344. _tableView.dataSource = self;
  345. _tableView.backgroundColor = UIColor.clearColor;
  346. [_tableView registerNib:[UINib nibWithNibName:@"SetTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SetTableViewCell"];
  347. _tableView.tableFooterView = [UIView new];
  348. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  349. if (@available(iOS 15.0, *)) {
  350. _tableView.sectionHeaderTopPadding = 0;
  351. }
  352. }
  353. return _tableView;
  354. }
  355. @end