Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a0586b9

Browse files
清除缓存 & 推荐 Coding
1 parent 9f1d0fd commit a0586b9

File tree

5 files changed

+110
-95
lines changed

5 files changed

+110
-95
lines changed

‎Coding_iOS/Controllers/MeSetting/SettingViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "BaseViewController.h"
1111
#import "User.h"
1212

13-
@interface SettingViewController : BaseViewController<UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
13+
@interface SettingViewController : BaseViewController
1414

1515
@property (strong, nonatomic) User *myUser;
1616

‎Coding_iOS/Controllers/MeSetting/SettingViewController.m

Lines changed: 78 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
#import "SettingViewController.h"
1010
#import "TitleDisclosureCell.h"
11+
#import "TitleValueMoreCell.h"
1112
#import "Login.h"
1213
#import "AppDelegate.h"
1314
#import "SettingAccountViewController.h"
1415
#import "AboutViewController.h"
1516
#import "EditTopicViewController.h"
17+
#import "CodingShareView.h"
18+
#import "WebViewController.h"
1619

17-
@interface SettingViewController ()
20+
@interface SettingViewController ()<UITableViewDataSource, UITableViewDelegate>
1821
@property (strong, nonatomic) UITableView *myTableView;
1922
@end
2023

@@ -34,6 +37,7 @@ - (void)viewDidLoad
3437
tableView.delegate = self;
3538
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
3639
[tableView registerClass:[TitleDisclosureCell class] forCellReuseIdentifier:kCellIdentifier_TitleDisclosure];
40+
[tableView registerClass:[TitleValueMoreCell class] forCellReuseIdentifier:kCellIdentifier_TitleValueMore];
3741
[self.view addSubview:tableView];
3842
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
3943
make.edges.equalTo(self.view);
@@ -43,54 +47,43 @@ - (void)viewDidLoad
4347
_myTableView.tableFooterView = [self tableFooterView];
4448
}
4549

46-
- (void)didReceiveMemoryWarning
47-
{
48-
[super didReceiveMemoryWarning];
49-
// Dispose of any resources that can be recreated.
50+
- (UIView*)tableFooterView{
51+
UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 90)];
52+
UIButton *loginBtn = [UIButton buttonWithStyle:StrapWarningStyle andTitle:@"退出" andFrame:CGRectMake(10, 0, kScreen_Width-10*2, 45) target:self action:@selector(loginOutBtnClicked:)];
53+
[loginBtn setCenter:footerV.center];
54+
[footerV addSubview:loginBtn];
55+
return footerV;
5056
}
5157

58+
- (void)dealloc{
59+
_myTableView.delegate = nil;
60+
_myTableView.dataSource = nil;
61+
}
5262
#pragma mark TableM
5363
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
54-
return 3;
64+
return 4;
5565
}
5666
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
57-
NSInteger row = 0;
58-
switch (section) {
59-
case 0:
60-
row = 1;
61-
break;
62-
case 1:
63-
row = 2;
64-
break;
65-
default:
66-
row = 1;
67-
break;
68-
}
67+
NSInteger row = (section == 1? 3:
68+
section == 3? 2:
69+
1);
6970
return row;
7071
}
7172

7273
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
73-
TitleDisclosureCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleDisclosure forIndexPath:indexPath];
74-
switch (indexPath.section) {
75-
case 0:
76-
[cell setTitleStr:@"账号设置"];
77-
break;
78-
case 1:
79-
switch (indexPath.row) {
80-
case 0:
81-
[cell setTitleStr:@"意见反馈"];
82-
break;
83-
case 1:
84-
[cell setTitleStr:@"去评分"];
85-
break;
86-
default:
87-
[cell setTitleStr:@"分享给好友"];
88-
break;
89-
}
90-
break;
91-
default:
92-
[cell setTitleStr:@"关于Coding"];
93-
break;
74+
UITableViewCell *cell;
75+
if (indexPath.section == 2) {
76+
cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleValueMore forIndexPath:indexPath];
77+
[(TitleValueMoreCell *)cell setTitleStr:@"清除缓存" valueStr:[self p_diskCacheSizeStr]];
78+
}else{
79+
cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TitleDisclosure forIndexPath:indexPath];
80+
81+
NSString *titleStr = (indexPath.section == 0? @"账号设置":
82+
indexPath.section == 1? (indexPath.row == 0? @"意见反馈":
83+
indexPath.row == 1? @"去评分":
84+
@"推荐 Coding"):
85+
indexPath.row == 0? @"帮助中心": @"关于Coding");
86+
[(TitleDisclosureCell *)cell setTitleStr:titleStr];
9487
}
9588
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
9689
return cell;
@@ -109,65 +102,68 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
109102
return 0.5;
110103
}
111104

112-
#pragma mark -
113-
114105
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
115106
[tableView deselectRowAtIndexPath:indexPath animated:YES];
116-
switch (indexPath.section) {
117-
case 0:{//账号设置
118-
SettingAccountViewController *vc = [[SettingAccountViewController alloc] init];
107+
108+
if (indexPath.section == 0) {//账号设置
109+
SettingAccountViewController *vc = [[SettingAccountViewController alloc] init];
110+
[self.navigationController pushViewController:vc animated:YES];
111+
}else if (indexPath.section == 1){
112+
if (indexPath.row == 0) {//意见反馈
113+
EditTopicViewController *vc = [[EditTopicViewController alloc] init];
114+
vc.curProTopic = [ProjectTopic feedbackTopic];
115+
vc.type = TopicEditTypeFeedBack;
116+
vc.topicChangedBlock = nil;
119117
[self.navigationController pushViewController:vc animated:YES];
118+
}else if (indexPath.row == 1){//评分
119+
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:kAppReviewURL]];
120+
}else{//推荐 Coding
121+
[CodingShareView showShareViewWithObj:nil];
120122
}
121-
break;
122-
case 1:
123-
switch (indexPath.row) {
124-
case 0:{//意见反馈
125-
EditTopicViewController *vc = [[EditTopicViewController alloc] init];
126-
vc.curProTopic = [ProjectTopic feedbackTopic];
127-
vc.type = TopicEditTypeFeedBack;
128-
vc.topicChangedBlock = nil;
129-
[self.navigationController pushViewController:vc animated:YES];
130-
}
131-
break;
132-
case 1:{//评分
133-
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:kAppReviewURL]];
134-
}
135-
break;
136-
default:
137-
break;
123+
}else if (indexPath.section == 2){//清除缓存
124+
__weak typeof(self) weakSelf = self;
125+
[[UIActionSheet bk_actionSheetCustomWithTitle:@"缓存数据有助于再次浏览或离线查看,你确定要清除缓存吗?" buttonTitles:nil destructiveTitle:@"确定清除" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
126+
if (index == 0) {
127+
[weakSelf clearDiskCache];
138128
}
139-
break;
140-
default:{//关于
129+
}] showInView:self.view];
130+
}else{
131+
if (indexPath.row == 0) {
132+
WebViewController *webVc = [WebViewController webVCWithUrlStr:@"/help/doc/mobile/index.html "];
133+
[self.navigationController pushViewController:webVc animated:YES];
134+
}else{//关于
141135
AboutViewController *vc = [[AboutViewController alloc] init];
142136
[self.navigationController pushViewController:vc animated:YES];
143137
}
144-
break;
138+
145139
}
146140
}
147141

148-
- (UIView*)tableFooterView{
149-
UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 90)];
150-
UIButton *loginBtn = [UIButton buttonWithStyle:StrapWarningStyle andTitle:@"退出" andFrame:CGRectMake(10, 0, kScreen_Width-10*2, 45) target:self action:@selector(loginOutBtnClicked:)];
151-
[loginBtn setCenter:footerV.center];
152-
[footerV addSubview:loginBtn];
153-
return footerV;
154-
}
142+
#pragma mark - Action
155143

156144
- (void)loginOutBtnClicked:(id)sender{
157-
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"确定要退出当前账号" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定退出" otherButtonTitles: nil];
158-
[actionSheet showInView:self.view];
145+
__weak typeof(self) weakSelf = self;
146+
[[UIActionSheet bk_actionSheetCustomWithTitle:@"确定要退出当前账号吗?" buttonTitles:nil destructiveTitle:@"确定退出" cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
147+
if (index == 0) {
148+
[weakSelf loginOutToLoginVC];
149+
}
150+
}] showInView:self.view];
159151
}
160152

161-
#pragma mark UIActionSheetDelegate M
162-
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
163-
if (buttonIndex == 0) {
164-
[self loginOutToLoginVC];
165-
}
153+
- (void)clearDiskCache{
154+
[NSObject showHUDQueryStr:@"正在清除缓存..."];
155+
[NSObject deleteResponseCache];
156+
[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
157+
[NSObject hideHUDQuery];
158+
[NSObject showHudTipStr:@"清除缓存成功"];
159+
[self.myTableView reloadData];
160+
}];
166161
}
167162

168-
- (void)dealloc
169-
{
170-
_myTableView.delegate = nil;
171-
_myTableView.dataSource = nil;
163+
- (NSString *)p_diskCacheSizeStr{
164+
NSUInteger size = [[SDImageCache sharedImageCache] getSize];
165+
size += [NSObjectgetResponseCacheSize];
166+
return [NSStringstringWithFormat:@"%.2f M", size/ 1024.0/ 1024.0];
172167
}
168+
173169
@end

‎Coding_iOS/Util/OC_Category/NSObject+Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
+ (id)loadResponseWithPath:(NSString *)requestPath;//返回一个NSDictionary类型的json数据
4343
+ (BOOL)deleteResponseCacheForPath:(NSString *)requestPath;
4444
+ (BOOL)deleteResponseCache;
45+
+ (NSUInteger)getResponseCacheSize;
4546

4647
#pragma mark NetError
4748
-(id)handleResponse:(id)responseJSON;

‎Coding_iOS/Util/OC_Category/NSObject+Common.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ + (BOOL) deleteResponseCache{
288288
return [self deleteCacheWithPath:kPath_ResponseCache];
289289
}
290290

291+
+ (NSUInteger)getResponseCacheSize {
292+
NSString *dirPath = [self pathInCacheDirectory:kPath_ResponseCache];
293+
NSUInteger size = 0;
294+
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
295+
for (NSString *fileName in fileEnumerator) {
296+
NSString *filePath = [dirPath stringByAppendingPathComponent:fileName];
297+
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
298+
size += [attrs fileSize];
299+
}
300+
return size;
301+
}
302+
303+
291304
+ (BOOL) deleteCacheWithPath:(NSString *)cachePath{
292305
NSString *dirPath = [self pathInCacheDirectory:cachePath];
293306
BOOL isDir = NO;

‎Coding_iOS/Views/CodingShareView.m

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ - (NSString *)p_shareLinkStr{
383383
}else if ([_objToShare isKindOfClass:[UIWebView class]]){
384384
linkStr = [(UIWebView *)_objToShare request].URL.absoluteString;
385385
}else{
386-
linkStr = [NSObject baseURLStr];
386+
linkStr = [NSStringstringWithFormat:@"%@app#download", [NSObject baseURLStr]];
387387
}
388388
return linkStr;
389389
}
@@ -394,7 +394,7 @@ - (NSString *)p_shareTitle{
394394
}else if ([_objToShare isKindOfClass:[UIWebView class]]){
395395
title = @"Coding 链接";
396396
}else{
397-
title = @"Coding";
397+
title = @"Coding - 让开发更简单";
398398
}
399399
return title;
400400
}
@@ -405,7 +405,7 @@ - (NSString *)p_shareText{
405405
}else if ([_objToShare isKindOfClass:[UIWebView class]]){
406406
text =[(UIWebView *)_objToShare stringByEvaluatingJavaScriptFromString:@"document.title"];
407407
}else{
408-
text = @"Coding 让开发更简单!";
408+
text = @"#Coding# 软件开发,云端协作";
409409
}
410410
return text;
411411
}
@@ -429,17 +429,21 @@ - (NSString *)p_imageUrlSquare:(BOOL)needSquare{
429429
return imageUrl;
430430
}
431431
- (void)p_shareENNoteWithompletion:(ENNotePopulateFromWebViewCompletionHandler)completion{
432-
if ([_objToShare respondsToSelector:NSSelectorFromString(@"htmlMedia")]) {
432+
if ([_objToShare isKindOfClass:[UIWebView class]]){
433+
[ENNote populateNoteFromWebView:(UIWebView *)_objToShare completion:completion];
434+
}else{
433435
ENNote *note = [ENNote new];
434436
note.title = [self p_shareTitle];
435437
NSString *htmlStr;
436-
HtmlMedia *htmlMedia = [_objToShare valueForKey:@"htmlMedia"];
437-
htmlStr = htmlMedia.contentOrigional;
438-
htmlStr = [htmlStr stringByAppendingFormat:@"<p><a href=\"%@\">原始链接</a></p>", [self p_shareLinkStr]];
438+
if ([_objToShare respondsToSelector:NSSelectorFromString(@"htmlMedia")]) {
439+
HtmlMedia *htmlMedia = [_objToShare valueForKey:@"htmlMedia"];
440+
htmlStr = htmlMedia.contentOrigional;
441+
htmlStr = [htmlStr stringByAppendingFormat:@"<p><a href=\"%@\">原始链接</a></p>", [self p_shareLinkStr]];
442+
}else{
443+
htmlStr = [self p_shareText];
444+
}
439445
note.content = [ENNoteContent noteContentWithSanitizedHTML:htmlStr];
440446
completion(note);
441-
}else if ([_objToShare isKindOfClass:[UIWebView class]]){
442-
[ENNote populateNoteFromWebView:(UIWebView *)_objToShare completion:completion];
443447
}
444448
}
445449
#pragma mark TranspondMessage
@@ -495,7 +499,7 @@ -(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocial
495499
socialData.extConfig.wechatSessionData = wechatSessionData;
496500
}else if ([platformName isEqualToString:@"wxtimeline"]){
497501
UMSocialWechatTimelineData *wechatTimelineData = [UMSocialWechatTimelineData new];
498-
wechatTimelineData.shareText = [NSString stringWithFormat:@"%@%@", [self p_shareTitle], [self p_shareText]];
502+
wechatTimelineData.shareText = !_objToShare? [selfp_shareTitle]: [NSString stringWithFormat:@"%@%@", [self p_shareTitle], [self p_shareText]];
499503
wechatTimelineData.url = [self p_shareLinkStr];
500504
wechatTimelineData.wxMessageType = UMSocialWXMessageTypeWeb;
501505
socialData.extConfig.wechatTimelineData = wechatTimelineData;
@@ -512,8 +516,9 @@ -(void)didSelectSocialPlatform:(NSString *)platformName withSocialData:(UMSocial
512516
socialData.extConfig.qzoneData = qzoneData;
513517
}else if ([platformName isEqualToString:@"sina"]){
514518
NSString *shareTitle, *shareText, *shareTail;
515-
shareTitle = [NSString stringWithFormat:@"%@", [self p_shareTitle]];
516-
shareText = [self p_shareText];
519+
shareTitle = !_objToShare? @"#Coding# 让开发更简单": [NSString stringWithFormat:@"%@", [self p_shareTitle]];
520+
shareText = !_objToShare? @"": [self p_shareText];
521+
517522
shareTail = [NSString stringWithFormat:@"%@(分享自@Coding)", [self p_shareLinkStr]];
518523
NSInteger maxShareLength = 140;
519524
NSInteger maxTextLength = maxShareLength - shareTitle.length - shareTail.length;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /