VLCAboutViewController.m 4.5 KB

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