VLCAboutViewController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_iOS-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. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title"]];
  41. UIBarButtonItem *contributeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_CONTRIBUTE", nil) style:UIBarButtonItemStylePlain target:self action:@selector(openContributePage:)];
  42. contributeButton.tintColor = [UIColor whiteColor];
  43. self.navigationItem.rightBarButtonItem = contributeButton;
  44. [self loadWebContent];
  45. }
  46. - (void)loadWebContent
  47. {
  48. NSBundle *mainBundle = [NSBundle mainBundle];
  49. NSString *textColor = PresentationTheme.current.colors.cellTextColor.toHex;
  50. NSString *backgroundColor = PresentationTheme.current.colors.background.toHex;
  51. NSString *version = [NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
  52. NSString *versionBuildNumberAndCodeName = [version stringByAppendingFormat:@" (%@)<br /><i>%@</i>", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"], kVLCVersionCodename];
  53. NSString *vlcLibraryVersion = [NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil), [[VLCLibrary sharedLibrary] version]];
  54. NSString *htmlFilePath = [mainBundle pathForResource:@"About Contents" ofType:@"html"];
  55. NSMutableString *htmlContent = [NSMutableString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
  56. NSRange rangeOfLastStringToReplace = [htmlContent rangeOfString:@"MOBILEVLCKITVERSION"];
  57. NSUInteger lengthOfStringToSearch = rangeOfLastStringToReplace.location + rangeOfLastStringToReplace.length + versionBuildNumberAndCodeName.length + textColor.length + backgroundColor.length + vlcLibraryVersion.length;
  58. NSRange searchRange = NSMakeRange(0, lengthOfStringToSearch);
  59. [htmlContent replaceOccurrencesOfString:@"VLCFORIOSVERSION" withString:versionBuildNumberAndCodeName options:NSLiteralSearch range:searchRange];
  60. [htmlContent replaceOccurrencesOfString:@"TEXTCOLOR" withString:textColor options:NSLiteralSearch range:searchRange];
  61. [htmlContent replaceOccurrencesOfString:@"BACKGROUNDCOLOR" withString:backgroundColor options:NSLiteralSearch range:searchRange];
  62. [htmlContent replaceOccurrencesOfString:@"MOBILEVLCKITVERSION" withString:vlcLibraryVersion options:NSLiteralSearch range:searchRange];
  63. [_webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[mainBundle bundlePath]]];
  64. }
  65. - (void)themeDidChange
  66. {
  67. self.view.backgroundColor = PresentationTheme.current.colors.background;
  68. _webView.backgroundColor = PresentationTheme.current.colors.background;
  69. [self loadWebContent];
  70. }
  71. - (BOOL)shouldAutorotate
  72. {
  73. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  74. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  75. return NO;
  76. return YES;
  77. }
  78. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  79. {
  80. NSURL *requestURL = request.URL;
  81. if (![requestURL.scheme isEqualToString:@""])
  82. return ![[UIApplication sharedApplication] openURL:requestURL];
  83. else
  84. return YES;
  85. }
  86. - (void)webViewDidFinishLoad:(UIWebView *)webView
  87. {
  88. _webView.backgroundColor = PresentationTheme.current.colors.background;
  89. _webView.opaque = YES;
  90. }
  91. - (IBAction)openContributePage:(id)sender
  92. {
  93. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.videolan.org/contribute.html"]];
  94. }
  95. @end