SLMsgBgSetVc.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // SLMsgBgVc.m
  3. // SLAiELTS
  4. //
  5. // Created by Gusont on 2023/6/2.
  6. //
  7. #import "SLMsgBgSetVc.h"
  8. #import "SLBaseTableViewCell.h"
  9. #import "SLImagePickerAndUpload.h"
  10. #import "DAConfig.h"
  11. @interface SLMsgBgSetVc ()
  12. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  13. @property (nonatomic, strong) SLImagePickerAndUpload *imageUpload;
  14. @end
  15. @implementation SLMsgBgSetVc
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. // Do any additional setup after loading the view from its nib.
  19. self.title = NSLocalizedString(@"更换封面相册", nil);
  20. if (@available(iOS 11.0, *)) {
  21. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  22. } else {
  23. self.automaticallyAdjustsScrollViewInsets = NO;
  24. }
  25. self.tableView.estimatedRowHeight = 100;
  26. [self.tableView registerNibCellWithReuseIdentifierClass:SLBaseTableViewCell.class];
  27. self.tableView.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  28. }
  29. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  30. SLBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SLBaseTableViewCell"];
  31. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  32. [cell confignCell:detail];
  33. return cell;
  34. }
  35. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  36. return [self.dataModels objectAtIndex:section].count;
  37. }
  38. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  39. return self.dataModels.count;
  40. }
  41. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  42. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  43. if (indexPath.section == 1) {
  44. if (indexPath.row == 0) {
  45. [self.imageUpload addPicwithCamera];
  46. }else if (indexPath.row == 1) {
  47. [self.imageUpload addPicWithPhotoLibrary];
  48. }
  49. }
  50. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  51. if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
  52. return;
  53. }
  54. for (UITableViewCell *acell in tableView.visibleCells) {
  55. acell.accessoryType = acell == cell ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  56. }
  57. if (indexPath.row == 0) {
  58. [DAConfig setUserLanguage:@"zh-Hans"];
  59. } else if (indexPath.row == 1) {
  60. [DAConfig setUserLanguage:@"en"];
  61. } else {
  62. [DAConfig setUserLanguage:nil];
  63. }
  64. //更新当前storyboard
  65. // UITabBarController *tbc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
  66. // tbc.selectedIndex = 2;
  67. // DALanguageSettingsViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:NSStringFromClass([DALanguageSettingsViewController class])];
  68. // UINavigationController *nvc = tbc.selectedViewController;
  69. // NSMutableArray *vcs = nvc.viewControllers.mutableCopy;
  70. // [vcs addObject:vc];
  71. //解决奇怪的动画bug。异步执行
  72. // dispatch_async(dispatch_get_main_queue(), ^{
  73. // [UIApplication sharedApplication].keyWindow.rootViewController = tbc;
  74. // nvc.viewControllers = vcs;
  75. // NSLog(@"已切换到语言 %@", [NSBundle currentLanguage]);
  76. // });
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  79. return 50.0f;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  82. return 20.f;
  83. }
  84. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  85. return 0.001f;
  86. }
  87. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  88. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 20)];
  89. view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  90. return view;
  91. }
  92. - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
  93. if (!_dataModels) {
  94. NSArray *arr = @[
  95. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"选择背景图", nil) subTitle:@""],],
  96. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"拍一张", nil) subTitle:@"" bgImage:@""],
  97. [SLPageModelDetail initWithTitle:NSLocalizedString(@"手机相册选择", nil) subTitle:@"" bgImage:@""]],
  98. ];
  99. _dataModels = [NSMutableArray arrayWithArray:arr];
  100. }
  101. return _dataModels;
  102. }
  103. - (SLImagePickerAndUpload *)imageUpload {
  104. if (!_imageUpload) {
  105. _imageUpload = [[SLImagePickerAndUpload alloc] init];
  106. _imageUpload.isOriginImage = YES;
  107. WS(weakSelf);
  108. _imageUpload.uploadBlock = ^(NSString *imageUrl) {
  109. [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/SetFriendCircleImage" parameter:@{@"imageUrl" : imageUrl ?: @""} success:^(id responseObject) {
  110. SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
  111. loginInfo.user.friendCircleImage = imageUrl;
  112. [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
  113. [weakSelf.navigationController popViewControllerAnimated:YES];
  114. } failure:^(SPRequestError *error) {
  115. }];
  116. };
  117. }
  118. return _imageUpload;
  119. }
  120. @end