2014-05-10 13:18:46 +00:00
|
|
|
/**
|
|
|
|
* Copyright Maarten Billemont (http://www.lhunath.com, lhunath@lyndir.com)
|
|
|
|
*
|
|
|
|
* See the enclosed file LICENSE for license information (LGPLv3). If you did
|
|
|
|
* not receive this file, see http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
|
|
*
|
|
|
|
* @author Maarten Billemont <lhunath@lyndir.com>
|
|
|
|
* @license http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// MPWebViewController.h
|
|
|
|
// MPWebViewController
|
|
|
|
//
|
|
|
|
// Created by lhunath on 2014-05-09.
|
|
|
|
// Copyright, lhunath (Maarten Billemont) 2014. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "MPWebViewController.h"
|
|
|
|
|
|
|
|
@implementation MPWebViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
2014-07-21 03:54:32 +00:00
|
|
|
[self.webView.scrollView insetOcclusion];
|
2014-05-10 13:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
if (!self.initialURL)
|
|
|
|
self.initialURL = [NSURL URLWithString:@"http://masterpasswordapp.com"];
|
|
|
|
|
2014-06-04 01:04:22 +00:00
|
|
|
self.webNavigationItem.title = self.initialURL.host;
|
|
|
|
|
2014-05-10 13:18:46 +00:00
|
|
|
self.webView.alpha = 0;
|
|
|
|
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:self.initialURL]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle {
|
|
|
|
|
|
|
|
return UIStatusBarStyleLightContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UIWebViewDelegate
|
|
|
|
|
|
|
|
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
|
|
|
|
navigationType:(UIWebViewNavigationType)navigationType {
|
|
|
|
|
2014-10-24 04:35:05 +00:00
|
|
|
if ([[request.URL absoluteString] rangeOfString:@"thanks.lhunath.com"].location != NSNotFound) {
|
2014-09-29 02:25:48 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tipped.thanks"];
|
2014-10-24 04:35:05 +00:00
|
|
|
if (![[NSUserDefaults standardUserDefaults] synchronize])
|
|
|
|
wrn( @"Couldn't synchronize thanks tip." );
|
|
|
|
}
|
2014-09-29 02:25:48 +00:00
|
|
|
|
2014-05-10 13:18:46 +00:00
|
|
|
if ([request.URL isEqual:request.mainDocumentURL]) {
|
|
|
|
self.webNavigationItem.title = request.URL.host;
|
|
|
|
self.webNavigationItem.prompt = strl( @"Loading" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidStartLoad:(UIWebView *)webView {
|
|
|
|
|
|
|
|
UIActivityIndicatorView *activityView =
|
|
|
|
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
|
|
|
|
[self.webNavigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:activityView]];
|
|
|
|
[activityView startAnimating];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView {
|
|
|
|
|
|
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
|
|
self.webView.alpha = 1;
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.webNavigationItem setLeftBarButtonItem:[webView canGoBack]? [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle:@"⬅︎" style:UIBarButtonItemStylePlain target:webView action:@selector( goBack )]: nil];
|
|
|
|
self.webNavigationItem.prompt = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
|
|
- (IBAction)done:(id)sender {
|
|
|
|
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|