project_files/HedgewarsMobile/Classes/GameLogViewController.m
author Wuzzy <Wuzzy2@mail.ru>
Mon, 15 Apr 2019 22:00:20 +0200
changeset 14805 af0f06b77908
parent 12872 00215a7ec5f5
permissions -rw-r--r--
Remove outdated main menu tip
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     1
/*
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2015 Anton Malmygin <antonc27@mail.ru>
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     4
 *
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     8
 *
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    13
 *
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    17
 */
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    18
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    19
#import "GameLogViewController.h"
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    20
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    21
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    22
#import <MessageUI/MFMailComposeViewController.h>
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    23
#endif
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    24
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    25
@interface GameLogViewController ()
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    26
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    27
<MFMailComposeViewControllerDelegate>
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    28
#endif
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    29
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    30
@end
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    31
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    32
@implementation GameLogViewController
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    33
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    34
#pragma mark - View life cycle
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    35
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    36
- (void)viewDidLoad
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    37
{
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    38
    [super viewDidLoad];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    39
    
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    40
    self.title = @"Last game log";
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    41
    
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    42
    UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismissAction)];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    43
    self.navigationItem.rightBarButtonItem = closeButton;
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    44
    
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    45
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    46
    if ([self allowSendLogByEmail])
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    47
    {
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    48
        UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStylePlain target:self action:@selector(sendLogByEmailAction)];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    49
        self.navigationItem.leftBarButtonItem = sendButton;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    50
    }
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    51
#endif
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    52
    
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    53
    NSString *debugStr = nil;
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    54
    if ([[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()])
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    55
        debugStr = [[NSString alloc] initWithContentsOfFile:DEBUG_FILE() encoding:NSUTF8StringEncoding error:nil];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    56
    else
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    57
        debugStr = [[NSString alloc] initWithString:@"Here be log"];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    58
    
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    59
    UITextView *logView = [[UITextView alloc] initWithFrame:self.view.frame];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    60
    [logView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    61
    logView.text = debugStr;
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    62
    logView.editable = NO;
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    63
    
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    64
    [self.view addSubview:logView];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    65
}
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    66
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    67
#pragma mark - Parameters
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    68
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    69
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    70
- (BOOL)allowSendLogByEmail
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    71
{
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    72
    return ([MFMailComposeViewController canSendMail] && [[NSFileManager defaultManager] fileExistsAtPath:DEBUG_FILE()]);
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    73
}
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    74
#endif
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    75
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    76
#pragma mark - Actions
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    77
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    78
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    79
- (void)sendLogByEmailAction
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    80
{
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    81
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    82
    picker.mailComposeDelegate = self;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    83
    [picker setSubject:@"Log file of iHedgewars game"];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    84
    
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    85
    // Attach a log file to the email
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    86
    NSData *logData = [NSData dataWithContentsOfFile:DEBUG_FILE()];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    87
    [picker addAttachmentData:logData mimeType:@"text/plain" fileName:@"game0.log"];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    88
    
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    89
    // Fill out the email body text
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    90
    NSString *emailBody = @"Add here description of a problem/log";
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    91
    [picker setMessageBody:emailBody isHTML:NO];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    92
    
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    93
    [self presentViewController:picker animated:YES completion:nil];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    94
}
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    95
#endif
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
    96
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    97
- (void)dismissAction
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    98
{
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    99
    [self dismissViewControllerAnimated:YES completion:nil];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   100
}
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   101
11177
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   102
#pragma mark - MailCompose delegate
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   103
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   104
#ifdef DEBUG
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   105
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   106
{
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   107
    // Notifies users about errors associated with the interface
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   108
    switch (result)
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   109
    {
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   110
        case MFMailComposeResultCancelled:
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   111
            NSLog(@"MailComposeResult: canceled");
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   112
            break;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   113
        case MFMailComposeResultSaved:
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   114
            NSLog(@"MailComposeResult: saved");
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   115
            break;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   116
        case MFMailComposeResultSent:
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   117
            NSLog(@"MailComposeResult: sent");
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   118
            break;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   119
        case MFMailComposeResultFailed:
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   120
            NSLog(@"MailComposeResult: failed");
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   121
            break;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   122
        default:
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   123
            NSLog(@"MailComposeResult: not sent");
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   124
            break;
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   125
    }
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   126
    
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   127
    [self dismissViewControllerAnimated:YES completion:nil];
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   128
}
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   129
#endif
015596575698 - Possibility to send log file by email from app
antonc27 <antonc27@mail.ru>
parents: 11176
diff changeset
   130
11176
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   131
#pragma mark - Memory warning
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   132
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   133
- (void)didReceiveMemoryWarning
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   134
{
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   135
    [super didReceiveMemoryWarning];
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   136
    // Dispose of any resources that can be recreated.
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   137
}
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   138
906c1878bc2c - Refactoring. Separation of game log viewing code to GameLogViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   139
@end