VLCAboutViewController.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*****************************************************************************
  2. * VLCAboutViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre Sagaspe <pierre.sagaspe # me.com>
  10. * Tamas Timar <ttimar.vlc # gmail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCAboutViewController.h"
  15. #import "VLC-Swift.h"
  16. @interface VLCAboutViewController ()
  17. {
  18. UIWebView *_webView;
  19. }
  20. @end
  21. @implementation VLCAboutViewController
  22. - (void)loadView
  23. {
  24. self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  25. self.view.backgroundColor = PresentationTheme.current.colors.background;
  26. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  27. _webView = [[UIWebView alloc] initWithFrame:self.view.frame];
  28. _webView.clipsToBounds = YES;
  29. _webView.delegate = self;
  30. _webView.backgroundColor = [UIColor clearColor];
  31. _webView.opaque = NO;
  32. _webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  33. _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  34. [self.view addSubview:_webView];
  35. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
  36. }
  37. - (void)viewDidLoad
  38. {
  39. [super viewDidLoad];
  40. if (@available(iOS 11.0, *)) {
  41. self.navigationController.navigationBar.prefersLargeTitles = NO;
  42. }
  43. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title"]];
  44. [self.navigationItem.titleView setTintColor:PresentationTheme.current.colors.navigationbarTextColor];
  45. UIBarButtonItem *contributeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_CONTRIBUTE", nil) style:UIBarButtonItemStylePlain target:self action:@selector(openContributePage:)];
  46. contributeButton.accessibilityIdentifier = VLCAccessibilityIdentifier.contribute;
  47. UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_DONE", nil) style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)];
  48. doneButton.accessibilityIdentifier = VLCAccessibilityIdentifier.done;
  49. self.navigationItem.leftBarButtonItem = contributeButton;
  50. self.navigationItem.rightBarButtonItem = doneButton;
  51. [self loadWebContent];
  52. }
  53. - (void)dismiss
  54. {
  55. [self dismissViewControllerAnimated:YES completion:nil];
  56. }
  57. - (void)loadWebContent
  58. {
  59. NSBundle *mainBundle = [NSBundle mainBundle];
  60. NSString *textColor = PresentationTheme.current.colors.cellTextColor.toHex;
  61. NSString *backgroundColor = PresentationTheme.current.colors.background.toHex;
  62. NSString *version = [NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
  63. NSString *versionBuildNumberAndCodeName = [version stringByAppendingFormat:@" (%@)<br /><i>%@</i>", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"], kVLCVersionCodename];
  64. NSString *vlcLibraryVersion = [NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil), [[VLCLibrary sharedLibrary] version]];
  65. NSString *htmlFilePath = [mainBundle pathForResource:@"About Contents" ofType:@"html"];
  66. NSMutableString *htmlContent = [NSMutableString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
  67. NSRange rangeOfLastStringToReplace = [htmlContent rangeOfString:@"MOBILEVLCKITVERSION"];
  68. NSUInteger lengthOfStringToSearch = rangeOfLastStringToReplace.location + rangeOfLastStringToReplace.length + versionBuildNumberAndCodeName.length + textColor.length + backgroundColor.length + vlcLibraryVersion.length;
  69. NSRange searchRange = NSMakeRange(0, lengthOfStringToSearch);
  70. [htmlContent replaceOccurrencesOfString:@"VLCFORIOSVERSION" withString:versionBuildNumberAndCodeName options:NSLiteralSearch range:searchRange];
  71. [htmlContent replaceOccurrencesOfString:@"TEXTCOLOR" withString:textColor options:NSLiteralSearch range:searchRange];
  72. [htmlContent replaceOccurrencesOfString:@"BACKGROUNDCOLOR" withString:backgroundColor options:NSLiteralSearch range:searchRange];
  73. [htmlContent replaceOccurrencesOfString:@"MOBILEVLCKITVERSION" withString:vlcLibraryVersion options:NSLiteralSearch range:searchRange];
  74. [_webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[mainBundle bundlePath]]];
  75. }
  76. - (void)themeDidChange
  77. {
  78. self.view.backgroundColor = PresentationTheme.current.colors.background;
  79. _webView.backgroundColor = PresentationTheme.current.colors.background;
  80. [self loadWebContent];
  81. }
  82. - (BOOL)shouldAutorotate
  83. {
  84. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  85. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  86. return NO;
  87. return YES;
  88. }
  89. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  90. {
  91. NSURL *requestURL = request.URL;
  92. if (![requestURL.scheme isEqualToString:@""])
  93. return ![[UIApplication sharedApplication] openURL:requestURL];
  94. else
  95. return YES;
  96. }
  97. - (void)webViewDidFinishLoad:(UIWebView *)webView
  98. {
  99. _webView.backgroundColor = PresentationTheme.current.colors.background;
  100. _webView.opaque = YES;
  101. }
  102. - (IBAction)openContributePage:(id)sender
  103. {
  104. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.videolan.org/contribute.html"]];
  105. }
  106. - (UIStatusBarStyle)preferredStatusBarStyle
  107. {
  108. return PresentationTheme.current.colors.statusBarStyle;
  109. }
  110. @end