SetViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. //
  2. // SetViewController.m
  3. // BuguLive
  4. //
  5. // Created by GuoMs on 16/7/18.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "SetViewController.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 "LanguageViewController.h"
  17. #import "BogoLanguageAlertView.h"
  18. @interface SetViewController () <UITableViewDelegate, UITableViewDataSource>
  19. @property (strong, nonatomic) IBOutlet UITableView *setTableView;
  20. @property(nonatomic, strong) BogoLanguageAlertView *languageView;
  21. @end
  22. @implementation SetViewController
  23. - (void)viewDidLoad
  24. {
  25. [super viewDidLoad];
  26. self.title = ASLocalizedString(@"设置");
  27. [self initSetTableView];
  28. [self backBtnWithBlock];
  29. }
  30. - (void)initSetTableView
  31. {
  32. self.setTableView.scrollEnabled = NO;
  33. [self.setTableView registerNib:[UINib nibWithNibName:@"SetTableViewCell" bundle:nil] forCellReuseIdentifier:@"setCell"];
  34. self.setTableView.separatorColor = kAppSpaceColor4;
  35. self.setTableView.backgroundColor = kAppSpaceColor2;
  36. }
  37. - (void)backBtnWithBlock
  38. {
  39. // 返回按钮
  40. [self setupBackBtnWithBlock:nil];
  41. }
  42. #pragma mark - Table view data source
  43. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  44. {
  45. return 4;
  46. }
  47. #pragma mark -- 返回区头的高度
  48. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  49. {
  50. return 10.0f;
  51. }
  52. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  53. {
  54. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 10)];
  55. headView.backgroundColor = kAppSpaceColor2;
  56. return headView;
  57. }
  58. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. return 45*kAppRowHScale;
  61. }
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  63. {
  64. switch (section)
  65. {
  66. case 0:
  67. {
  68. if ([[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"]){
  69. return 3;
  70. }
  71. return 1;
  72. }
  73. break;
  74. case 1:
  75. {
  76. if ([self.BuguLive.appModel.distribution_module integerValue] == 1)
  77. {
  78. return 4;
  79. }
  80. else
  81. return 3;
  82. }
  83. break;
  84. case 2:
  85. {
  86. if (kIsCheckingVersion())
  87. {
  88. return 3;
  89. }
  90. else
  91. {
  92. return 4;
  93. }
  94. }
  95. break;
  96. case 3:
  97. {
  98. if (kSupportH5Shopping == 1) return 0;
  99. return 1;
  100. }
  101. break;
  102. default:
  103. break;
  104. }
  105. return 0;
  106. }
  107. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  108. {
  109. SetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setCell"];
  110. [cell configurationCellWithSection:indexPath.section row:indexPath.row distribution_module:self.BuguLive.appModel.distribution_module];
  111. return cell;
  112. }
  113. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  114. {
  115. if (indexPath.section == 0)
  116. {
  117. if (([[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"] && indexPath.row == 0)||( [[GlobalVariables sharedInstance].appModel.open_noble isEqualToString:@"1"] && indexPath.row == 1)){
  118. // //账户安全点击事件
  119. // AccountSecurityViewController *acVC = [[AccountSecurityViewController alloc]init];
  120. // acVC.userid = self.userID;
  121. // [self.navigationController pushViewController:acVC animated:YES];
  122. }else{
  123. //账户安全点击事件
  124. AccountSecurityViewController *acVC = [[AccountSecurityViewController alloc]init];
  125. acVC.userid = self.userID;
  126. [self.navigationController pushViewController:acVC animated:YES];
  127. }
  128. }
  129. else if (indexPath.section == 1)
  130. {
  131. switch (indexPath.row)
  132. {
  133. case 0:
  134. {
  135. // 黑名单点击事件
  136. FollowerViewController *followVC = [[FollowerViewController alloc]init];
  137. followVC.type = @"3";
  138. followVC.user_id = self.userID;
  139. [self.navigationController pushViewController:followVC animated:YES];
  140. }
  141. break;
  142. case 1:
  143. {
  144. // 推送管理点击事件
  145. PushManageViewController *pushManageVC = [[PushManageViewController alloc]init];
  146. pushManageVC.userId = self.userID;
  147. [self.navigationController pushViewController:pushManageVC animated:YES];
  148. }
  149. break;
  150. case 2:
  151. {
  152. SetTableViewCell *cell = [self.setTableView cellForRowAtIndexPath:indexPath];
  153. if ([cell.setText.text isEqualToString:ASLocalizedString(@"切换语言")]) {
  154. [self gotoLanguage];
  155. }else{
  156. // 推荐人ID
  157. RecommendedPersonViewController *recommendPersonVC = [[RecommendedPersonViewController alloc]init];
  158. recommendPersonVC.userID = self.userID;
  159. recommendPersonVC.view.backgroundColor = [UIColor whiteColor];
  160. [self.navigationController pushViewController:recommendPersonVC animated:YES];
  161. }
  162. }
  163. break;
  164. default:
  165. break;
  166. }
  167. }
  168. else if (indexPath.section == 2)
  169. {
  170. if (indexPath.row == 0)
  171. {
  172. // 帮助与反馈点击事件
  173. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_help_feedback isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  174. tmpController.navTitleStr = ASLocalizedString(@"帮助与反馈");
  175. [self.navigationController pushViewController:tmpController animated:YES];
  176. }else if (indexPath.row == 1)
  177. {
  178. // 帮助与反馈点击事件
  179. SetTableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
  180. [[[SDWebImageManager sharedManager] imageCache] clearWithCacheType:SDImageCacheTypeAll completion:^{
  181. [self.setTableView reloadSection:2 withRowAnimation:UITableViewRowAnimationFade];
  182. }];
  183. }
  184. else if (indexPath.row == 2)
  185. {
  186. if ([VersionNum isEqualToString:self.BuguLive.appModel.ios_checkVersionStr] )
  187. {
  188. // 关于我们
  189. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_about_we isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  190. tmpController.navTitleStr = ASLocalizedString(@"关于我们");
  191. [self.navigationController pushViewController:tmpController animated:YES];
  192. }
  193. else
  194. {
  195. // 检查更新
  196. if (self.BuguLive.appModel.version.has_upgrade == 1)
  197. {
  198. self.BuguLive.ios_down_url = self.BuguLive.appModel.version.ios_down_url;
  199. // 强制升级:forced_upgrade ; 0:非强制升级,可取消; 1:强制升级
  200. if (self.BuguLive.appModel.version.forced_upgrade == 1)
  201. {
  202. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  203. }
  204. else
  205. {
  206. FWWeakify(self)
  207. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"发现新版本,需要升级吗?")destructiveAction:^{
  208. FWStrongify(self)
  209. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  210. } cancelAction:^{
  211. }];
  212. }
  213. }
  214. else
  215. {
  216. [FanweMessage alert:ASLocalizedString(@"当前已是最新版本!")];
  217. }
  218. if (!self.BuguLive.appModel.short_name || [self.BuguLive.appModel.short_name isEqualToString:@""])
  219. {
  220. self.BuguLive.appModel.short_name = ShortNameStr;
  221. }
  222. if (!self.BuguLive.appModel.ticket_name || [self.BuguLive.appModel.ticket_name isEqualToString:@""])
  223. {
  224. self.BuguLive.appModel.ticket_name = TicketNameStr;
  225. }
  226. }
  227. }
  228. else if(indexPath.row == 3)
  229. {
  230. // 关于我们
  231. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_about_we isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  232. tmpController.navTitleStr = ASLocalizedString(@"关于我们");
  233. [self.navigationController pushViewController:tmpController animated:YES];
  234. }
  235. }
  236. else if(indexPath.section == 3)
  237. {
  238. // 退出登录
  239. NSString * preferredLang = [[NSUserDefaults standardUserDefaults] objectForKey:KAppLanguage];
  240. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
  241. //因为上面的方法会全部清除本APP的所有本地存储,所以这里预言再设置一遍
  242. [[LocalizationSystem sharedLocalSystem] setLanguage:preferredLang];
  243. NSLog(@" 5当前语言 = %@",preferredLang);
  244. [self setNetworing];
  245. }
  246. }
  247. - (void)gotoLanguage {
  248. [self.languageView show:[AppDelegate sharedAppDelegate].topViewController.view.superview.superview];
  249. // LanguageViewController *vc = [[LanguageViewController alloc] init];
  250. // [self.navigationController pushViewController:vc animated:YES];
  251. }
  252. #pragma mark -- 退出登录
  253. - (void)setNetworing
  254. {
  255. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  256. [parmDict setObject:@"login" forKey:@"ctl"];
  257. [parmDict setObject:@"loginout" forKey:@"act"];
  258. if (self.userID.length > 0)
  259. {
  260. [parmDict setObject:self.userID forKey:@"to_user_id"];
  261. }
  262. FWWeakify(self)
  263. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  264. if ([responseJson toInt:@"status"] == 1)
  265. {
  266. FWStrongify(self)
  267. [self.setTableView reloadData];
  268. // [self.navigationController popViewControllerAnimated:YES];
  269. [self.navigationController popViewControllerAnimated:NO];
  270. [[IMAPlatform sharedInstance] logout:^{
  271. [[AppDelegate sharedAppDelegate] enterLoginUI];
  272. } fail:^(int code, NSString *msg) {
  273. [[AppDelegate sharedAppDelegate] enterLoginUI];
  274. }];
  275. [AppViewModel loadInit];
  276. }else
  277. {
  278. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  279. }
  280. } FailureBlock:^(NSError *error) {
  281. }];
  282. }
  283. -(BogoLanguageAlertView *)languageView{
  284. if (!_languageView) {
  285. _languageView = [[BogoLanguageAlertView alloc]initWithFrame:CGRectMake(kRealValue(20), 0, kScreenW - kRealValue(20 * 2), kRealValue(350))];
  286. }
  287. return _languageView;
  288. }
  289. @end