VLCAboutViewController.m 5.9 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCAboutViewController.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12 13
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Pierre Sagaspe <pierre.sagaspe # me.com>
 *          Tamas Timar <ttimar.vlc # gmail.com>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
14 15

#import "VLCAboutViewController.h"
16
#import "VLC-Swift.h"
17

18 19 20 21 22 23 24
@interface VLCAboutViewController ()
{
    UIWebView *_webView;
}

@end

25 26
@implementation VLCAboutViewController

27 28
- (void)loadView
{
29
    self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
30
    self.view.backgroundColor = PresentationTheme.current.colors.background;
31
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
32

33
    _webView = [[UIWebView alloc] initWithFrame:self.view.frame];
34 35
    _webView.clipsToBounds = YES;
    _webView.delegate = self;
36 37
    _webView.backgroundColor = [UIColor clearColor];
    _webView.opaque = NO;
38
    _webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
39
    _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
40
    [self.view addSubview:_webView];
41 42

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
43 44
}

45 46 47
- (void)viewDidLoad
{
    [super viewDidLoad];
48 49 50 51
    if (@available(iOS 11.0, *)) {
        self.navigationController.navigationBar.prefersLargeTitles = NO;
    }
    
52
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title"]];
53 54
    [self.navigationItem.titleView setTintColor:PresentationTheme.current.colors.navigationbarTextColor];
    
55
    UIBarButtonItem *contributeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_CONTRIBUTE", nil) style:UIBarButtonItemStylePlain target:self action:@selector(openContributePage:)];
56 57 58 59 60 61 62
    contributeButton.accessibilityIdentifier = VLCAccessibilityIdentifier.contribute;
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)];
    doneButton.accessibilityIdentifier = VLCAccessibilityIdentifier.done;
    
    self.navigationItem.leftBarButtonItem = contributeButton;
    self.navigationItem.rightBarButtonItem = doneButton;
    
63 64
    [self loadWebContent];
}
65

66 67 68 69 70
- (void)dismiss
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

71 72
- (void)loadWebContent
{
73
    NSBundle *mainBundle = [NSBundle mainBundle];
74 75 76 77
    NSString *textColor = PresentationTheme.current.colors.cellTextColor.toHex;
    NSString *backgroundColor = PresentationTheme.current.colors.background.toHex;
    NSString *version = [NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    NSString *versionBuildNumberAndCodeName = [version stringByAppendingFormat:@" (%@)<br /><i>%@</i>", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"], kVLCVersionCodename];
78
    NSString *vlcLibraryVersion = [NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil), [[VLCLibrary sharedLibrary] version]];
79
    NSString *htmlFilePath = [mainBundle pathForResource:@"About Contents" ofType:@"html"];
80

81
    NSMutableString *htmlContent = [NSMutableString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
82 83 84 85 86 87 88 89 90

    NSRange rangeOfLastStringToReplace = [htmlContent rangeOfString:@"MOBILEVLCKITVERSION"];
    NSUInteger lengthOfStringToSearch = rangeOfLastStringToReplace.location + rangeOfLastStringToReplace.length + versionBuildNumberAndCodeName.length + textColor.length + backgroundColor.length + vlcLibraryVersion.length;
    NSRange searchRange = NSMakeRange(0, lengthOfStringToSearch);
    [htmlContent replaceOccurrencesOfString:@"VLCFORIOSVERSION" withString:versionBuildNumberAndCodeName options:NSLiteralSearch range:searchRange];
    [htmlContent replaceOccurrencesOfString:@"TEXTCOLOR" withString:textColor options:NSLiteralSearch range:searchRange];
    [htmlContent replaceOccurrencesOfString:@"BACKGROUNDCOLOR" withString:backgroundColor options:NSLiteralSearch range:searchRange];
    [htmlContent replaceOccurrencesOfString:@"MOBILEVLCKITVERSION" withString:vlcLibraryVersion options:NSLiteralSearch range:searchRange];

91 92 93 94 95 96 97 98
    [_webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[mainBundle bundlePath]]];
}

- (void)themeDidChange
{
    self.view.backgroundColor = PresentationTheme.current.colors.background;
    _webView.backgroundColor = PresentationTheme.current.colors.background;
    [self loadWebContent];
99 100
}

101
- (BOOL)shouldAutorotate
102
{
103
    UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
104 105 106 107 108
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        return NO;
    return YES;
}

109 110
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
111 112 113 114 115
    NSURL *requestURL = request.URL;
    if (![requestURL.scheme isEqualToString:@""])
        return ![[UIApplication sharedApplication] openURL:requestURL];
    else
        return YES;
116 117
}

118 119
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
120
    _webView.backgroundColor = PresentationTheme.current.colors.background;
121
    _webView.opaque = YES;
122 123
}

124 125 126 127 128
- (IBAction)openContributePage:(id)sender
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.videolan.org/contribute.html"]];
}

129 130 131 132 133
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return PresentationTheme.current.colors.statusBarStyle;
}

134
@end