From 44c89a35e4380c2c9f0e9975fcb6defb21506b79 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Thu, 5 Feb 2015 12:33:09 +0100 Subject: [PATCH 1/2] Replace UIActionSheet with UIActionController Support for switching log actions on and off Requires iOS8 --- .../de.lproj/SLLocalizable.strings | 10 +- SuperLogger/SuperLogerListView.m | 146 ++++++++++++++---- SuperLogger/SuperLogger.h | 4 + SuperLogger/SuperLogger.m | 4 + 4 files changed, 128 insertions(+), 36 deletions(-) diff --git a/SuperLogger/Resources/SuperLogger.bundle/de.lproj/SLLocalizable.strings b/SuperLogger/Resources/SuperLogger.bundle/de.lproj/SLLocalizable.strings index 069db1c..2f4149c 100644 --- a/SuperLogger/Resources/SuperLogger.bundle/de.lproj/SLLocalizable.strings +++ b/SuperLogger/Resources/SuperLogger.bundle/de.lproj/SLLocalizable.strings @@ -6,12 +6,12 @@ */ "SL_LogList" = "Protokolldateien"; -"SL_Back" = "Zurück"; -"SL_Clean" = "Löschen"; +"SL_Back" = "ZurŸck"; +"SL_Clean" = "Lšschen"; "SL_Cancel" = "Abbrechen"; "SL_Preview" = "Vorschau"; "SL_SendViaMail" = "Per Mail verschicken"; -"SL_Delete" = "Löschen"; +"SL_Delete" = "Lšschen"; "SL_Send" = "Senden"; -"SL_Star" = "Stern"; -"SL_Unstar" = "UnStern"; +"SL_Star" = "AuswŠhlen"; +"SL_Unstar" = "AbwŠhlen"; diff --git a/SuperLogger/SuperLogerListView.m b/SuperLogger/SuperLogerListView.m index 8f8d5cd..3ae5cbc 100644 --- a/SuperLogger/SuperLogerListView.m +++ b/SuperLogger/SuperLogerListView.m @@ -99,7 +99,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N UITableViewCell *cell = [[UITableViewCell alloc]init]; cell.textLabel.text = self.fileList[indexPath.row]; if ([[SuperLogger sharedInstance] isStaredWithFilename:self.fileList[indexPath.row]]) { - cell.accessoryType = UITableViewCellAccessoryDetailButton; + if ([SuperLogger sharedInstance].enableStar){ + cell.accessoryType = UITableViewCellAccessoryDetailButton; + } } return cell; } @@ -111,41 +113,55 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [self exportTapped:self]; } +/** + * Shows Alert controller after user tapped on a log file + * + * @param sender object that triggered the alert controller + */ - (void)exportTapped:(id)sender { + //Oggerschummer 20150205 + //Replace original UIActionSheet implementation mwith modern implementation using UIAlertController + //Thus delegate method below has been commented + + @try { + + NSBundle* myBundle; NSString *path = [[NSBundle mainBundle] pathForResource:@"SuperLogger" ofType:@"bundle"]; myBundle = [NSBundle bundleWithPath:path]; - NSString *isStar = [[SuperLogger sharedInstance] isStaredWithFilename:_tempFilename] ? NSLocalizedStringFromTableInBundle( @"SL_Unstar", @"SLLocalizable", myBundle,@"Unstar"): NSLocalizedStringFromTableInBundle( @"SL_Star", @"SLLocalizable", myBundle, @"Star"); + UIAlertController * alertController = [[UIAlertController alloc] init]; + + if ([SuperLogger sharedInstance].enableStar){ + NSString *isStar =isStar= [[SuperLogger sharedInstance] isStaredWithFilename:_tempFilename] ? NSLocalizedStringFromTableInBundle( @"SL_Unstar", @"SLLocalizable", myBundle,@"Unstar"): NSLocalizedStringFromTableInBundle( @"SL_Star", @"SLLocalizable", myBundle, @"Star"); - UIActionSheet *actionSheet = [[UIActionSheet alloc] - initWithTitle:_tempFilename - delegate:self - cancelButtonTitle:NSLocalizedStringFromTableInBundle( @"SL_Cancel", @"SLLocalizable", myBundle, @"Cancel") - destructiveButtonTitle:nil - otherButtonTitles:isStar ,NSLocalizedStringFromTableInBundle( @"SL_Preview", @"SLLocalizable",myBundle, @"Preview"),NSLocalizedStringFromTableInBundle( @"SL_SendViaMail", @"SLLocalizable", myBundle, @"Send via Email"), NSLocalizedStringFromTableInBundle( @"SL_Delete", @"SLLocalizable",myBundle, @"Delete"), nil]; - [actionSheet showInView:self.view]; -} - -- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex -{ - if (buttonIndex == 0) { - [[SuperLogger sharedInstance]starWithFilename:_tempFilename]; - self.fileList = nil; - self.fileList = [[SuperLogger sharedInstance]getLogList]; - [self.tableView reloadData]; + UIAlertAction * starAction = [UIAlertAction actionWithTitle:isStar style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ + [[SuperLogger sharedInstance]starWithFilename:_tempFilename]; + self.fileList = nil; + self.fileList = [[SuperLogger sharedInstance]getLogList]; + [self.tableView reloadData]; + }]; + [alertController addAction:starAction]; } - else if (buttonIndex == 1) { - SuperLoggerPreviewView *pre = [[SuperLoggerPreviewView alloc]init]; - pre.logData = [[SuperLogger sharedInstance] getDataWithFilename:_tempFilename]; - pre.logFilename = _tempFilename; - dispatch_async(dispatch_get_main_queue(), ^(void){ - [self presentViewController:pre animated:YES completion:nil]; - }); + + if ([SuperLogger sharedInstance].enablePreview){ + UIAlertAction * previewAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Preview", @"SLLocalizable",myBundle, @"Preview") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ + + SuperLoggerPreviewView *pre = [[SuperLoggerPreviewView alloc]init]; + pre.logData = [[SuperLogger sharedInstance] getDataWithFilename:_tempFilename]; + pre.logFilename = _tempFilename; + dispatch_async(dispatch_get_main_queue(), ^(void){ + [self presentViewController:pre animated:YES completion:nil]; + }); + + }]; + + [alertController addAction:previewAction]; } - else if (buttonIndex == 2) { + if ([SuperLogger sharedInstance].enableMail){ + UIAlertAction * mailAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle( @"SL_SendViaMail", @"SLLocalizable", myBundle, @"Send via Email") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ [[NSOperationQueue mainQueue] addOperationWithBlock:^{ SuperLogger *logger = [SuperLogger sharedInstance]; NSData *tempData = [logger getDataWithFilename:_tempFilename]; @@ -166,16 +182,84 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger }); } }]; + + }]; + [alertController addAction:mailAction]; + } + + if ([SuperLogger sharedInstance].enableDelete){ + UIAlertAction * deleteAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Delete", @"SLLocalizable",myBundle, @"Delete") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){ + [[SuperLogger sharedInstance]deleteLogWithFilename:_tempFilename]; + self.fileList = nil; + self.fileList = [[SuperLogger sharedInstance]getLogList]; + [self.tableView reloadData]; + }]; + [alertController addAction:deleteAction]; + + } + UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Cancel", @"SLLocalizable", myBundle, @"Cancel") style:UIAlertActionStyleDefault handler:Nil]; + [alertController addAction:cancelAction]; + + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + [self presentViewController:alertController animated:YES completion:Nil]; + }]; + } - else if (buttonIndex == 3) { - [[SuperLogger sharedInstance]deleteLogWithFilename:_tempFilename]; - self.fileList = nil; - self.fileList = [[SuperLogger sharedInstance]getLogList]; - [self.tableView reloadData]; + @catch (NSException *exception) { + //non critial error, lets ignore this for the time being } + } +//- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex +//{ +// +// if (buttonIndex == 0) { +// [[SuperLogger sharedInstance]starWithFilename:_tempFilename]; +// self.fileList = nil; +// self.fileList = [[SuperLogger sharedInstance]getLogList]; +// [self.tableView reloadData]; +// } +// else if (buttonIndex == 1) { +// SuperLoggerPreviewView *pre = [[SuperLoggerPreviewView alloc]init]; +// pre.logData = [[SuperLogger sharedInstance] getDataWithFilename:_tempFilename]; +// pre.logFilename = _tempFilename; +// dispatch_async(dispatch_get_main_queue(), ^(void){ +// [self presentViewController:pre animated:YES completion:nil]; +// }); +// } +// else if (buttonIndex == 2) { +// [[NSOperationQueue mainQueue] addOperationWithBlock:^{ +// SuperLogger *logger = [SuperLogger sharedInstance]; +// NSData *tempData = [logger getDataWithFilename:_tempFilename]; +// if (tempData != nil) { +// MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; +// [picker setSubject:logger.mailTitle]; +// [picker setToRecipients:logger.mailRecipients]; +// [picker addAttachmentData:tempData mimeType:@"application/text" fileName:_tempFilename]; +// [picker setToRecipients:[NSArray array]]; +// [picker setMessageBody:logger.mailContect isHTML:NO]; +// [picker setMailComposeDelegate:self]; +// dispatch_async(dispatch_get_main_queue(), ^(void){ +// @try { +// [self presentViewController:picker animated:YES completion:nil]; +// } +// @catch (NSException * e) +// { NSLog(@"Exception: %@", e); } +// }); +// } +// }]; +// } +// else if (buttonIndex == 3) { +// [[SuperLogger sharedInstance]deleteLogWithFilename:_tempFilename]; +// self.fileList = nil; +// self.fileList = [[SuperLogger sharedInstance]getLogList]; +// [self.tableView reloadData]; +// } +// +//} + - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error diff --git a/SuperLogger/SuperLogger.h b/SuperLogger/SuperLogger.h index aec5ae6..bac8b56 100644 --- a/SuperLogger/SuperLogger.h +++ b/SuperLogger/SuperLogger.h @@ -12,6 +12,10 @@ @property(strong, nonatomic) NSString *mailTitle; @property(strong, nonatomic) NSString *mailContect; @property(strong, nonatomic) NSArray *mailRecipients; +@property(assign,nonatomic) BOOL enableStar; +@property(assign,nonatomic) BOOL enablePreview; +@property(assign,nonatomic) BOOL enableMail; +@property(assign,nonatomic) BOOL enableDelete; /** * SuperLogger sharedInstance diff --git a/SuperLogger/SuperLogger.m b/SuperLogger/SuperLogger.m index e1dba71..c7eae91 100644 --- a/SuperLogger/SuperLogger.m +++ b/SuperLogger/SuperLogger.m @@ -34,6 +34,10 @@ + (SuperLogger *)sharedInstance static dispatch_once_t oncePredicate; dispatch_once(&oncePredicate, ^{ _sharedInstance = [[SuperLogger alloc] init]; + _sharedInstance.enableStar =YES; //Default: Allow Star + _sharedInstance.enableDelete =YES; + _sharedInstance.enableMail=YES; + _sharedInstance.enablePreview=YES; }); return _sharedInstance; } From 12ab17ad032627002087103aa655db9b6628ae93 Mon Sep 17 00:00:00 2001 From: Thomas May Date: Thu, 5 Feb 2015 13:51:45 +0100 Subject: [PATCH 2/2] Disable delete button in navigation bar is delete was disabled for log files --- SuperLogger/SuperLogerListView.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SuperLogger/SuperLogerListView.m b/SuperLogger/SuperLogerListView.m index 3ae5cbc..0312f32 100644 --- a/SuperLogger/SuperLogerListView.m +++ b/SuperLogger/SuperLogerListView.m @@ -66,8 +66,10 @@ - (void)viewDidLoad [self.navigationBar pushNavigationItem:self.navigationItem animated:NO]; UIBarButtonItem *backBtn=[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Back", @"SLLocalizable",myBundle, @"Back") style:UIBarButtonItemStylePlain target:self action:@selector(done)]; [self.navigationItem setLeftBarButtonItem:backBtn]; - UIBarButtonItem *cleanBtn=[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Clean",@"SLLocalizable", myBundle, @"Clean") style:UIBarButtonItemStylePlain target:self action:@selector(clean)]; - [self.navigationItem setRightBarButtonItem:cleanBtn]; + if ([SuperLogger sharedInstance].enableDelete){ + UIBarButtonItem *cleanBtn=[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTableInBundle( @"SL_Clean",@"SLLocalizable", myBundle, @"Clean") style:UIBarButtonItemStylePlain target:self action:@selector(clean)]; + [self.navigationItem setRightBarButtonItem:cleanBtn]; + } } -(void)done @@ -214,7 +216,7 @@ - (void)exportTapped:(id)sender //- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex //{ -// +// // if (buttonIndex == 0) { // [[SuperLogger sharedInstance]starWithFilename:_tempFilename]; // self.fileList = nil;