Skip to content

Commit

Permalink
Merge pull request #14 from Oggerschummer/feature/Disable_Star_Switch
Browse files Browse the repository at this point in the history
Replace UIActionSheet with UIActionController
  • Loading branch information
yourtion committed Feb 5, 2015
2 parents 337fc83 + 12ab17a commit 6e38053
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
152 changes: 119 additions & 33 deletions SuperLogger/SuperLogerListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,7 +101,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;
}
Expand All @@ -111,41 +115,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];
Expand All @@ -166,16 +184,84 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
});
}
}];

}];
[alertController addAction:mailAction];
}
else if (buttonIndex == 3) {
[[SuperLogger sharedInstance]deleteLogWithFilename:_tempFilename];
self.fileList = nil;
self.fileList = [[SuperLogger sharedInstance]getLogList];
[self.tableView reloadData];

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];
}];

}
@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
Expand Down
4 changes: 4 additions & 0 deletions SuperLogger/SuperLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions SuperLogger/SuperLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6e38053

Please sign in to comment.