ProfileController.m
6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// ProfileController.m
// DreamSleep
//
// Created by peter on 2022/4/1.
//
#import "ProfileController.h"
#import "FeedbackController.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;
@property (nonatomic, strong) UIImageView *headIV;
@property (nonatomic, strong) UILabel *nickLab;
@end
@implementation ProfileController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"我的";
self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.tmpDatas = @[@"模拟用户登录", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法"];
self.tableView.tableHeaderView = self.userInfoView;
// 监听用户数据更新通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserView) name:HasUpdateUserDataNoti object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:HasUpdateUserDataNoti object:nil];
}
#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 1: // 意见反馈入口
{
[self jumpViewController:@"FeedbackController"];
}
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;
}
}
#pragma mark - Actions
- (void)modifyUserInfoAction {
// 账户与资料页面
[self jumpViewController:@"AccountController"];
}
- (void)jumpViewController:(NSString *)className {
// 判断是否登录成功
if ([LoginUtils getUserLoginData]) {
// 进入相关页面
Class cls = NSClassFromString(className);
[self.navigationController pushViewController:[cls new] animated:YES];
} else {
// 跳转到登录页面
[LoginUtils jumpToLoginControllerWithTarget:self];
}
}
- (void)updateUserView {
UserModel *model = [LoginUtils getUserLoginData];
if (model) {
[self.headIV yy_setImageWithURL:[NSURL URLWithString:model.face_img] placeholder:[UIImage imageNamed:@"portrait"]];
self.nickLab.text = model.nick_name;
} else {
self.headIV.image = [UIImage imageNamed:@"portrait"];
self.nickLab.text = @"";
}
}
#pragma mark - lazy
- (UIView *)userInfoView {
if (!_userInfoView) {
_userInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
_headIV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 60, 60)];
_headIV.centerY = _userInfoView.centerY;
[_headIV cornerRadius:30];
_headIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
[_userInfoView addSubview:_headIV];
_nickLab = [UILabel dkLabWithFont:BoldFont(15)];
_nickLab.frame = CGRectMake(CGRectGetMaxX(_headIV.frame) + 5, 0, 100, 20);
_nickLab.centerY = _userInfoView.centerY;
[_userInfoView addSubview:_nickLab];
UIButton *btn = [UIButton btnWithTitle:@"点击修改信息" titleColor:BrandColor font:SysFont(16) bgColor:DSClearColor];
btn.frame = CGRectMake(CGRectGetMaxX(_nickLab.frame) + 5, 0, 150, 40);
btn.centerY = _userInfoView.centerY;
[btn addTarget:self action:@selector(modifyUserInfoAction) forControlEvents:UIControlEventTouchUpInside];
[_userInfoView addSubview:btn];
[self updateUserView];
}
return _userInfoView;
}
@end