VLCAboutViewController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*****************************************************************************
  2. * VLCAboutViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2014 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 "VLCAppDelegate.h"
  16. #import "UIBarButtonItem+Theme.h"
  17. @interface VLCAboutViewController ()
  18. {
  19. UIWebView *_webView;
  20. }
  21. @end
  22. @implementation VLCAboutViewController
  23. - (void)loadView
  24. {
  25. _webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  26. _webView.clipsToBounds = YES;
  27. _webView.delegate = self;
  28. _webView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  29. self.view = _webView;
  30. }
  31. - (void)viewDidLoad
  32. {
  33. [super viewDidLoad];
  34. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title"]];
  35. UIBarButtonItem *contributeButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_CONTRIBUTE",@"") style:UIBarButtonItemStyleBordered target:self action:@selector(openContributePage:)];
  36. if (SYSTEM_RUNS_IOS7_OR_LATER)
  37. contributeButton.tintColor = [UIColor whiteColor];
  38. else {
  39. [contributeButton setBackgroundImage:[UIImage imageNamed:@"button"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  40. [contributeButton setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  41. }
  42. self.navigationItem.rightBarButtonItem = contributeButton;
  43. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
  44. NSMutableString *htmlContent = [NSMutableString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"About Contents" ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
  45. [htmlContent replaceOccurrencesOfString:@"VLCFORIOSVERSION" withString:[[NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT",@""), [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]] stringByAppendingFormat:@"<br /><i>%@</i>", kVLCVersionCodename] options:NSLiteralSearch range:NSMakeRange(800, 1000)];
  46. [htmlContent replaceOccurrencesOfString:@"MOBILEVLCKITVERSION" withString:[NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT",@""),[[VLCLibrary sharedLibrary] version]] options:NSLiteralSearch range:NSMakeRange(800, 1100)];
  47. [_webView loadHTMLString:[NSString stringWithString:htmlContent] baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
  48. htmlContent = nil;
  49. }
  50. - (BOOL)shouldAutorotate
  51. {
  52. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  53. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  54. return NO;
  55. return YES;
  56. }
  57. - (IBAction)goBack:(id)sender
  58. {
  59. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  60. }
  61. - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
  62. {
  63. NSURL *requestURL = request.URL;
  64. if (![requestURL.scheme isEqualToString:@""])
  65. return ![[UIApplication sharedApplication] openURL:requestURL];
  66. else
  67. return YES;
  68. }
  69. - (void)webViewDidFinishLoad:(UIWebView *)webView
  70. {
  71. webView.alpha = 0.;
  72. CGFloat alpha = 1.;
  73. void (^animationBlock)() = ^() {
  74. webView.alpha = alpha;
  75. };
  76. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  77. webView.hidden = NO;
  78. };
  79. [UIView animateWithDuration:.3 animations:animationBlock completion:completionBlock];
  80. }
  81. - (IBAction)openContributePage:(id)sender
  82. {
  83. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.videolan.org/contribute.html"]];
  84. }
  85. @end