SLMsgBgSetVc.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  51. if ([detail.title isEqualToString:@"简体中文"] || [detail.title isEqualToString:@"English"]) {
  52. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  53. if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
  54. return;
  55. }
  56. for (UITableViewCell *acell in tableView.visibleCells) {
  57. acell.accessoryType = acell == cell ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
  58. }
  59. if (indexPath.row == 0) {
  60. [DAConfig setUserLanguage:@"zh-Hans"];
  61. } else if (indexPath.row == 1) {
  62. [DAConfig setUserLanguage:@"en"];
  63. } else {
  64. [DAConfig setUserLanguage:nil];
  65. }
  66. //更新当前
  67. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  68. [appDelegate setTabWithRootWindow];
  69. }
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  72. return 50.0f;
  73. }
  74. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  75. return 20.f;
  76. }
  77. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  78. return 0.001f;
  79. }
  80. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  81. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 20)];
  82. view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  83. return view;
  84. }
  85. - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
  86. if (!_dataModels) {
  87. NSArray *arr = @[
  88. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"选择背景图", nil) subTitle:@""],],
  89. @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"拍一张", nil) subTitle:@"" bgImage:@""],
  90. [SLPageModelDetail initWithTitle:NSLocalizedString(@"手机相册选择", nil) subTitle:@"" bgImage:@""]],
  91. ];
  92. _dataModels = [NSMutableArray arrayWithArray:arr];
  93. }
  94. return _dataModels;
  95. }
  96. - (SLImagePickerAndUpload *)imageUpload {
  97. if (!_imageUpload) {
  98. _imageUpload = [[SLImagePickerAndUpload alloc] init];
  99. _imageUpload.isOriginImage = YES;
  100. WS(weakSelf);
  101. _imageUpload.uploadBlock = ^(NSString *imageUrl) {
  102. [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/SetFriendCircleImage" parameter:@{@"imageUrl" : imageUrl ?: @""} success:^(id responseObject) {
  103. SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
  104. loginInfo.user.friendCircleImage = imageUrl;
  105. [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
  106. [weakSelf.navigationController popViewControllerAnimated:YES];
  107. } failure:^(SPRequestError *error) {
  108. }];
  109. };
  110. }
  111. return _imageUpload;
  112. }
  113. @end