| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //
- // testTableViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-8-5.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "CacheViewController.h"
- #import "RAUtils.h"
- #import "AppDelegate.h"
- //#define AL_CACHE 1234
- //#define AL_CLEAN 1235
- @interface CacheViewController ()
- @end
- @implementation CacheViewController
- - (id)initWithStyle:(UITableViewStyle)style
- {
- self = [super initWithStyle:style];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)onCloseClick:(id)sender {
- [self dismissViewControllerAnimated:true completion:nil];
-
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
-
-
- //
- //
- if( appDelegate.bEnable_Cache)
- {
- self.catchSwitch.on=true;
- self.sizeLabel.text = @"Calculating";
- // 创建
- NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(calculate) object:nil];
- // 启动
- [thread start];
- }
- else
- {
- self.catchSwitch.on=false;
- self.sizeLabel.text = @"";
- [self.mum stopAnimating];
- }
-
-
- UIBarButtonItem* closeBTN = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(onCloseClick:)];
-
-
- self.navigationItem.rightBarButtonItem = closeBTN;
- // Uncomment the following line to preserve selection between presentations.
- // self.clearsSelectionOnViewWillAppear = NO;
-
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.rightBarButtonItem = self.editButtonItem;
-
-
-
- }
- - (void)calculate
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-
- // DebugLog(@"%@",cachefolder);
- // DebugLog(@"%@",img_cache);
- float size=[RAUtils fileSizeForDir:img_cache];
- // float size1=[RAUtils fileSizeForDir:img_cache];
-
- self.sizeLabel.text = [NSString stringWithFormat:@" %.2f MB",size];
-
- [self.mum stopAnimating];
- }
- - (void)clear
- {
-
-
-
- // __block UIAlertController * alert = [RAUtils waiting_alert:self message:@"Deleting..." title:nil completion:^{
- PopWaitAlert* pop = [RAUtils waiting_pop:@"Deleting..." completion:nil];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *cachefolder = [paths objectAtIndex:0];
- NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
-
-
- [RAUtils deletefiles:img_cache];
- [RAUtils deletefiles: cachefolder];
-
- // [alert dismissViewControllerAnimated:YES completion:^{
- [pop hide];
- // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- [self.mum startAnimating];
- float size=[RAUtils fileSizeForDir:cachefolder];
- // float size1=[RAUtils fileSizeForDir:img_cache];
-
- self.sizeLabel.text = [NSString stringWithFormat:@"Cache size: %.2f MB",size];
-
- [self.mum stopAnimating];
- // }];
- // }];
-
-
-
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)cacheSwitchChanged:(UISwitch *)sender {
-
- if(!sender.on)
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Disable Cache Confirm", nil) message:NSLocalizedString(@"Disable cache will save some diskspace but cost more network traffic and also slower. Are you sure to Disable cache?", nil) preferredStyle:UIAlertControllerStyleAlert];
-
-
- UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
-
- [defaults setValue:@"false" forKey:@"enable_cache"];
-
- [defaults synchronize];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- appDelegate.bEnable_Cache = false;
-
-
- // 创建
- NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(clear) object:nil];
- // 启动
- [thread start];
- return;
-
-
-
-
-
-
-
- }];
-
- UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- self.catchSwitch.on=YES;
-
-
- }];
- [alertController addAction:action_0];
- [alertController addAction:action_3];
-
-
- [self presentViewController:alertController animated:YES completion:nil];
-
- //
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Disable Cache Confirm", nil) message:NSLocalizedString(@"Disable cache will save some diskspace but cost more network traffic and also slower. Are you sure to Disable cache?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
- //
- //
- // alert.tag = AL_CACHE;
- //
- //
- //
- // [alert show];
- }
- else
- {
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-
-
- [defaults setValue:@"true" forKey:@"enable_cache"];
-
- [defaults synchronize];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.bEnable_Cache = true;
- }
- }
- //#pragma mark - UIAlertViewDelegate
- //// Called when a button is clicked. The view will be automatically dismissed after this call returns
- //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- //{
- // if(alertView.tag==AL_CACHE)
- // {
- // if(buttonIndex!=alertView.cancelButtonIndex)
- // {
- // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- //
- //
- // [defaults setValue:@"false" forKey:@"enable_cache"];
- //
- // [defaults synchronize];
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- // appDelegate.bEnable_Cache = false;
- //
- //
- // // 创建
- // NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(clear) object:nil];
- // // 启动
- // [thread start];
- // return;
- // }
- // else
- // self.catchSwitch.on=YES;
- //
- //
- // }
- //
- //// if(buttonIndex!=alertView.cancelButtonIndex&&alertView.tag==AL_CLEAN)
- //// {
- //// // 创建
- //// NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(clear) object:nil];
- //// // 启动
- //// [thread start];
- //// return;
- //// }
- //}
- #pragma mark - Table view delegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if(indexPath.row==2)
- {
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Clear Cache Confirm", nil) message:NSLocalizedString(@"Clear cache will take some time, click YES to confirm clear.", nil) preferredStyle:UIAlertControllerStyleAlert];
-
-
- UIAlertAction *action_0 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
-
- // 创建
- NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(clear) object:nil];
- // 启动
- [thread start];
- return;
-
-
- }];
-
- UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
-
-
- }];
- [alertController addAction:action_0];
- [alertController addAction:action_3];
-
-
- [self presentViewController:alertController animated:YES completion:nil];
-
-
-
-
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Clear Cache Confirm", nil) message:NSLocalizedString(@"Clear cache will take some time, click YES to confirm clear.", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
- //
- //
- // alert.tag = AL_CLEAN;
- //
- //
- //
- // [alert show];
- }
- }
- @end
|