123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // SLMsgBgVc.m
- // SLAiELTS
- //
- // Created by Gusont on 2023/6/2.
- //
- #import "SLMsgBgSetVc.h"
- #import "SLBaseTableViewCell.h"
- #import "SLImagePickerAndUpload.h"
- #import "DAConfig.h"
- @interface SLMsgBgSetVc ()
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic, strong) SLImagePickerAndUpload *imageUpload;
- @end
- @implementation SLMsgBgSetVc
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.title = NSLocalizedString(@"更换相册封面", nil);
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.estimatedRowHeight = 100;
- [self.tableView registerNibCellWithReuseIdentifierClass:SLBaseTableViewCell.class];
- self.tableView.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
- }
- - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- SLBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SLBaseTableViewCell"];
- SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
- [cell confignCell:detail];
- return cell;
- }
- - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.dataModels objectAtIndex:section].count;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return self.dataModels.count;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (indexPath.section == 1) {
- if (indexPath.row == 0) {
- [self.imageUpload addPicwithCamera];
- }else if (indexPath.row == 1) {
- [self.imageUpload addPicWithPhotoLibrary];
- }
- }
- SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
- if ([detail.title isEqualToString:@"简体中文"] || [detail.title isEqualToString:@"English"]) {
- UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
- if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
- return;
- }
- for (UITableViewCell *acell in tableView.visibleCells) {
- acell.accessoryType = acell == cell ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
- }
- if (indexPath.row == 0) {
- [DAConfig setUserLanguage:@"zh-Hans"];
- } else if (indexPath.row == 1) {
- [DAConfig setUserLanguage:@"en"];
- } else {
- [DAConfig setUserLanguage:nil];
- }
- //更新当前
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate setTabWithRootWindow];
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 50.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 20.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.001f;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 20)];
- view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
- return view;
- }
- - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
- if (!_dataModels) {
- NSArray *arr = @[
- @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"选择背景图", nil) subTitle:@""],],
- @[[SLPageModelDetail initWithTitle:NSLocalizedString(@"拍一张", nil) subTitle:@"" bgImage:@""],
- [SLPageModelDetail initWithTitle:NSLocalizedString(@"手机相册选择", nil) subTitle:@"" bgImage:@""]],
- ];
- _dataModels = [NSMutableArray arrayWithArray:arr];
- }
- return _dataModels;
- }
- - (SLImagePickerAndUpload *)imageUpload {
- if (!_imageUpload) {
- _imageUpload = [[SLImagePickerAndUpload alloc] init];
- _imageUpload.isOriginImage = YES;
- WS(weakSelf);
- _imageUpload.uploadBlock = ^(NSString *imageUrl) {
- [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/SetFriendCircleImage" parameter:@{@"imageUrl" : imageUrl ?: @""} success:^(id responseObject) {
- SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
- loginInfo.user.friendCircleImage = imageUrl;
- [SLGlobalInfo SharedInstance].loginInfo = loginInfo;
- [weakSelf.navigationController popViewControllerAnimated:YES];
- } failure:^(SPRequestError *error) {
-
- }];
- };
- }
- return _imageUpload;
- }
- @end
|