ProfileController.m 4.9 KB
//
//  ProfileController.m
//  DreamSleep
//
//  Created by peter on 2022/4/1.
//

#import "ProfileController.h"
#import "AccountController.h"
#import "SystemSetController.h"
#import "InviteController.h"
#import "PrivacyViewController.h"
#import "ProfileAlertView.h"

@interface ProfileController ()
@property (nonatomic, strong) UIView *userInfoView;
@property (nonatomic, strong) NSArray *tmpDatas;
@end

@implementation ProfileController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"我的";
    self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    self.tmpDatas = @[@"模拟用户登录", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法"];
    self.tableView.tableHeaderView = self.userInfoView;
}

#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle {
    // 我的界面需要对用户是否打开自动切换进行处理
    if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
        return ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) ? NaviStyleDark : NaviStyleLight;
    } else {
        return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
    }
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tmpDatas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"profileCell" forIndexPath:indexPath];
    cell.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    cell.textLabel.text = self.tmpDatas[indexPath.row];
    cell.textLabel.dk_textColorPicker = DKColorPickerWithKey(TEXT);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0: // 模拟跳转到登录页面
        {
            [LoginUtils jumpToLoginControllerWithTarget:self];
        }
            break;
        case 2: // 系统设置入口
        {
            SystemSetController *sysVC = [SystemSetController new];
            [self.navigationController pushViewController:sysVC animated:YES];
        }
            break;
        case 3: // 邀请好友
        {
            InviteController *inviteVC = [InviteController new];
            [self.navigationController pushViewController:inviteVC animated:YES];
        }
            break;
        case 4: // 关于我们
        {
            [self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"关于我们" link:[NSURL URLWithString:AboutUS] isDetail:YES] animated:YES];
        }
            break;
        case 5: // 前往小程序
        {
            [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
        }
            break;
        case 6: // 关注公众号
        {
            [UIPasteboard generalPasteboard].string = @"xiaomeng-sleep";
            [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
        }
            break;
        case 7: // 添加客服微信
        {
            [UIPasteboard generalPasteboard].string = @"xiaomengsleep";
            [[[ProfileAlertView alloc] initWithIndexPath:indexPath] showAlertView];
        }
            break;
        case 8: // CBTI
        {
            [self.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"失眠的认知行为疗法(CBTI)" link:[NSURL URLWithString:MYCBTI] isDetail:YES] animated:YES];
        }
            break;;
        default:
            break;
    }
}

- (void)modifyAction {
    // 判断是否登录成功
    
#warning - 临时屏蔽
    if (![LoginUtils getUserLoginData]) {
        // 进入修改页面
        AccountController *accountVC = [[AccountController alloc] init];
        [self.navigationController pushViewController:accountVC animated:YES];
    } else {
        // 跳转到登录页面
        [LoginUtils jumpToLoginControllerWithTarget:self];
    }
}

- (UIView *)userInfoView {
    if (!_userInfoView) {
        _userInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
        UIButton *btn = [UIButton btnWithTitle:@"点击修改信息" titleColor:BrandColor font:SysFont(16) bgColor:DSClearColor];
        btn.frame = CGRectMake(0, 0, 150, 40);
        btn.center = _userInfoView.center;
        [btn addTarget:self action:@selector(modifyAction) forControlEvents:UIControlEventTouchUpInside];
        [_userInfoView addSubview:btn];
    }
    return _userInfoView;
}

@end