CNMineSettingVC.m
10.8 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//
// CNMineSettingVC.m
// CNLiveCMineModule
//
// Created by CNLive on 2022/1/28.
//
#import "CNMineSettingVC.h"
#import "CNMySettingListModel.h"
#import "CNMineSettingCell.h"
#import "CNMineChangePhoneNumController.h"
#import "CNFontSettingController.h"
#import "CNPrivacyViewController.h"
#import "CNMineAccountManageController.h"
#import "CNCancellationViewController.h"
@interface CNMineSettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIButton *quitButton;
@property (nonatomic, strong) NSMutableArray <CNMySettingListModel*>*data;
@property (nonatomic, copy) NSString *cacheString;
@end
@implementation CNMineSettingVC
static NSString *settingListCellId = @"settingListCellId";
- (void)getSDCacheSize {
weakself
__block NSUInteger fileSize = 0;
NSInteger witnessSize = [[CTMediator sharedInstance] cn_VideoModule_GetVideoCacheSize];
// chatTempSize 聊天图片和视频临时文件大小
NSInteger chatTempSize = [self chatTempFileSizeAtPath:[CNLiveBusinessTools getChatImageAndVideoUploadIMCacheDirectory]];
[[SDImageCache sharedImageCache] calculateSizeWithCompletionBlock:^(NSUInteger fileCount, NSUInteger totalSize) {
fileSize += totalSize;
fileSize += [[YYWebImageManager sharedManager].cache.diskCache totalCount];
NSInteger allSize = fileSize + witnessSize + chatTempSize;
if (allSize/(1024.0*1024) >= 1) {
weakSelf.cacheString = [NSString stringWithFormat:@"%.1fM",allSize/(1024.0*1024)];
} else {
weakSelf.cacheString = [NSString stringWithFormat:@"%.1fKB",allSize/1024.0];
}
NSLog(@"totalSize:%zd,fileCount:%zd",totalSize,fileCount);
for (CNMySettingListModel *model in self.data) {
if([model.title isEqualToString:@"清除缓存"]){
model.content = weakSelf.cacheString;
}
}
[weakSelf.tableView reloadData];
}];
}
//获取聊天临时图片和视频的大小
- (double)chatTempFileSizeAtPath:(NSString *)folderPath
{
NSFileManager* manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:folderPath]) return 0;
NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
NSString* fileName;
long long folderSize = 0;
while ((fileName = [childFilesEnumerator nextObject]) != nil)
{
NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
if([manager fileExistsAtPath:fileAbsolutePath])
{
folderSize += [[manager attributesOfItemAtPath:fileAbsolutePath error:nil] fileSize];
}
}
return folderSize;
}
- (void)getData{
[CNCSubMinePresent requestIsAllowFindStrangerSwichResponse:^(NSString * _Nonnull status) {
for (CNMySettingListModel *model in self.data) {
if([model.title isEqualToString:@"允许陌生人查看生活圈"]){
model.status = status;
}
}
[self.tableView reloadData];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"设置";
self.view.backgroundColor = [UIColor whiteColor];
[self getData];
NSString *status = [[NSUserDefaults standardUserDefaults] valueForKey:@"findStrangerSwitch"];
self.data = [CNCSubMinePresent settingDataSource:status?status:@"success"];
[self getSDCacheSize];
[self.view addSubview:self.tableView];
[self.view addSubview:self.quitButton];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.top.equalTo(self.view).offset(kNavigationBarHeight);
make.bottom.equalTo(self.view.mas_bottom).offset(-kVerticalBottomSafeHeight-60);
}];
[self.quitButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view.mas_bottom).offset(-kVerticalBottomSafeHeight);
make.height.mas_equalTo(60);
}];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
//网络监听
- (void)cn_noNetworking
{
[self.tableView reloadData];
}
- (void)cn_wifiOrWWANNetworking
{
[self.tableView reloadData];
}
#pragma mark - Action
- (void)quitAction:(UIButton *)sender {
[self.view createAlertViewTitleArray:@[@"退出登录"] textColor:UIColorMake(40, 40, 40) font:UIFontCNMake(15.0f) actionBlock:^(UIButton *button, NSInteger didRow) {
switch (didRow) {
case 0:
{
[[CNLiveCMineService shareMineProtocol] appLoginOut:NO];
}
break;
default:
break;
}
}];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNMineSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:settingListCellId forIndexPath:indexPath];
cell.model = self.data[indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.data[indexPath.row].rowHeight*RATIO;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.tableView qmui_clearsSelection];
NSInteger i = 1;
if (indexPath.row == 0) {
// 更换手机号
CNMineChangePhoneNumController *cpnVC = [[CNMineChangePhoneNumController alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:cpnVC withBackTitle:@" "];
}else if (indexPath.row == 1){
//绑定管理
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:26 param:@{} contentVC:self];
}else if (indexPath.row == 2){
//帮助与反馈
[CNLiveCMineService pushCMineIWebVCParam:@{@"path":@"bzfk",@"urlStr":@"/cnhf.html"} CurrentVC:self];
}else if (indexPath.row == 3){
// 字体大小
NSLog(@"字体大小");
CNFontSettingController *fontSettingVC = [[CNFontSettingController alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:fontSettingVC withBackTitle:@" "];
}else if (indexPath.row == 4){
// 设置背景图片
NSLog(@"设置背景图片");
[[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:9 param:@{} contentVC:self ];
}else if (indexPath.row == 5){
//隐私
CNPrivacyViewController *vc = [[CNPrivacyViewController alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:vc withBackTitle:@" "];
}else if (indexPath.row == 6+i)
//清除缓存
{
UIAlertController *actionAlert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:@"您确定要清除本地缓存吗?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//好友和达人头像也存在SD,暂时不能清除
NSString *pathOfLibrary = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
[[NSFileManager defaultManager] removeItemAtPath:[pathOfLibrary stringByAppendingPathComponent:@"CNLiveRequestCache"] error:nil];//清除网络缓存
[[SDImageCache sharedImageCache] clearMemory];
[[YYWebImageManager sharedManager].cache.diskCache removeAllObjects];
[[CTMediator sharedInstance] cn_VideoModule_ClearAllVideoCache];
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
[self getSDCacheSize];
}];
[[CNLiveCMineService shareMineProtocol] clearMemories];
//删除聊天图片视频临时文件
if ([CNLiveBusinessTools deleteChatImageAndVideoUploadImCache]) {
NSLog(@"删除图片视频临时文件成功");
}
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL];
[actionAlert addAction:action2];
[actionAlert addAction:action1];
[action1 setValue:UIColorHex(23D41E) forKey:@"_titleTextColor"];
[action2 setValue:UIColorHex(23D41E) forKey:@"_titleTextColor"];
[self presentViewController:actionAlert animated:YES completion:nil];
}else if (indexPath.row == 7+ i){
//关于我们
CNMineAccountManageController *aboutVC = [[CNMineAccountManageController alloc] initWithType:SettingTypeAbout];
[[BaseAppDelegate sharedAppDelegate] pushViewController:aboutVC withBackTitle:@" "];
}else if (indexPath.row == 8+ i){
//注销账号
CNCancellationViewController *vc = [[CNCancellationViewController alloc] init];
[[BaseAppDelegate sharedAppDelegate] pushViewController:vc withBackTitle:@" "];
}
}
#pragma mark - Getting
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.backgroundColor = RGB(242, 242, 242);
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.showsHorizontalScrollIndicator = NO;
[_tableView registerClass:[CNMineSettingCell class] forCellReuseIdentifier:settingListCellId];
}
return _tableView;
}
- (UIButton *)quitButton {
if (!_quitButton) {
_quitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_quitButton setTitle:@"退出登录" forState:UIControlStateNormal];
[_quitButton setTitleColor:RGB(235, 61, 63) forState:UIControlStateNormal];
_quitButton.backgroundColor = kWhiteColor;
[_quitButton addTarget:self action:@selector(quitAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _quitButton;
}
- (NSMutableArray *)data{
if (!_data) {
_data = [[NSMutableArray alloc] init];
}
return _data;
}
@end