Permalink
Browse files

Improved support for contacts, search is temporarily broke though.

  • Loading branch information...
1 parent f545ea7 commit 0fcaa24891857aec38da55c2db1da5373146616f @shnhrrsn shnhrrsn committed Jan 27, 2010
@@ -0,0 +1,16 @@
+//
+// ContactViewController.h
+// Voice
+//
+// Created by Shaun Harrison on 1/27/10.
+// Copyright 2010 enormego. All rights reserved.
+//
+
+#import "PageViewController.h"
+
+
+@interface ContactViewController : PageViewController {
+
+}
+
+@end
@@ -0,0 +1,48 @@
+//
+// ContactViewController.m
+// Voice
+//
+// Created by Shaun Harrison on 1/27/10.
+// Copyright 2010 enormego. All rights reserved.
+//
+
+#import "ContactViewController.h"
+#import "ContactsViewController.h"
+
+@implementation ContactViewController
+
++ (UIWebView*)globalWebView {
+ return [ContactsViewController globalWebView];
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.title = @"Contact Info";
+}
+
+- (void)cleanUpUI {
+ // No need to call super here, since it's a different webapp
+ [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('hc-chrome').parentNode.style.marginTop='-10px';"];
+ [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('hc-chrome').parentNode.style.paddingTop='7px';"];
+ [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('hc-chrome').style.display='none';"];
+}
+
+- (void)didReceiveMemoryWarning {
+ // Releases the view if it doesn't have a superview.
+ [super didReceiveMemoryWarning];
+
+ // Release any cached data, images, etc that aren't in use.
+}
+
+- (void)viewDidUnload {
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
+}
+
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+
+@end
@@ -10,7 +10,11 @@
@interface ContactsViewController : WebViewController {
-
+@private
+ UISegmentedControl* titleSegmentedControl;
}
+- (IBAction)toggleContacts;
+
+@property(nonatomic,retain) IBOutlet UISegmentedControl* titleSegmentedControl;
@end
@@ -7,26 +7,75 @@
//
#import "ContactsViewController.h"
+#import "ContactViewController.h"
+static UIWebView* __contactsWebView;
@implementation ContactsViewController
+@synthesize titleSegmentedControl;
-- (void)awakeFromNib {
- [super awakeFromNib];
- self.title = @"Contacts";
+// Contacts is actually run through a different app than the main GV app.
+// Google uses an iframe in the main app, so we'll call directly
++ (UIWebView*)globalWebView {
+ @synchronized(self) {
+ if(!__contactsWebView) {
+ __contactsWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
+ __contactsWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ __contactsWebView.backgroundColor = [UIColor whiteColor];
+
+ for(UIImageView* imageView in [[[__contactsWebView subviews] lastObject] subviews]) {
+ if(![imageView isKindOfClass:[UIImageView class]]) continue;
+ imageView.hidden = YES;
+ }
+ }
+ }
+
+ return __contactsWebView;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Contacts" style:UIBarButtonItemStyleBordered target:nil action:NULL] autorelease];
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [self toggleContacts];
+ [super viewDidAppear:animated];
+}
+
+- (IBAction)toggleContacts {
+ if(self.titleSegmentedControl.selectedSegmentIndex == 1) {
+ [self.webView stringByEvaluatingJavaScriptFromString:@"var evt = document.createEvent('MouseEvents');evt.initEvent('click', true, true);_e(evt,'cmy');"];
+ } else {
+ [self.webView stringByEvaluatingJavaScriptFromString:@"var evt = document.createEvent('MouseEvents');evt.initEvent('click', true, true);_e(evt,'ctp');"];
+ }
+
+ [self cleanUpUI];
+}
+
+- (void)cleanUpUI {
+ // No need to call super here, since it's a different webapp
+ [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('cl-chrome').style.display='none';"];
}
- (NSURL*)defaultURL {
- return [NSURL URLWithString:@"https://www.google.com/voice/m?dc=gorganic#~contacts:v=cl&m=v"];
+ return [NSURL URLWithString:@"https://www.google.com/app/contacts"];
}
-/*
-// Override to allow orientations other than the default portrait orientation.
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
+- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
+ if([[[request URL] description] rangeOfString:@":v=hc"].location != NSNotFound) {
+ ContactViewController* viewController = [[ContactViewController alloc] initWithURL:[request URL]];
+ [self.navigationController pushViewController:viewController animated:YES];
+ [viewController release];
+ return NO;
+ } else {
+ return [super webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
+ }
}
-*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
@@ -36,12 +85,12 @@ - (void)didReceiveMemoryWarning {
}
- (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
+ self.titleSegmentedControl = nil;
}
- (void)dealloc {
+ self.titleSegmentedControl = nil;
[super dealloc];
}
@@ -16,8 +16,15 @@
CGPoint scrollPosition;
}
+// Global web view thats reused across all webViews
++ (UIWebView*)globalWebView;
+
- (void)loadURL:(NSURL*)URL;
+// Subclasses should remove UI elements specifically targeted to their URL and must call back to super
+// Do not call directly, WebViewController will call as needed
+- (void)cleanUpUI;
+
@property(nonatomic,readonly) UIWebView* webView;
@property(nonatomic,assign) BOOL allowScrolling;
@property(nonatomic,readonly) NSURL* defaultURL;
@@ -17,9 +17,28 @@ @interface UIView (UIScroller)
static UIWebView* __webView;
+#define myWebView [[self class] globalWebView]
+
@implementation WebViewController
@synthesize allowScrolling, scrollPosition;
++ (UIWebView*)globalWebView {
+ @synchronized(self) {
+ if(!__webView) {
+ __webView = [[UIWebView alloc] initWithFrame:CGRectZero];
+ __webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ __webView.backgroundColor = [UIColor whiteColor];
+
+ for(UIImageView* imageView in [[[__webView subviews] lastObject] subviews]) {
+ if(![imageView isKindOfClass:[UIImageView class]]) continue;
+ imageView.hidden = YES;
+ }
+ }
+ }
+
+ return __webView;
+}
+
- (id)init {
if((self = [super init])) {
self.allowScrolling = YES;
@@ -51,23 +70,11 @@ - (void)awakeFromNib {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
- @synchronized(self) {
- if(!__webView) {
- __webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
- __webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- __webView.backgroundColor = [UIColor whiteColor];
-
- for(UIImageView* imageView in [[[__webView subviews] lastObject] subviews]) {
- if(![imageView isKindOfClass:[UIImageView class]]) continue;
- imageView.hidden = YES;
- }
- }
- }
- [self.view addSubview:__webView];
- __webView.frame = self.view.bounds;
- __webView.delegate = self;
- ((UIView*)[[__webView subviews] lastObject]).scrollingEnabled = self.allowScrolling;
+ [self.view addSubview:myWebView];
+ myWebView.frame = self.view.bounds;
+ myWebView.delegate = self;
+ ((UIView*)[[myWebView subviews] lastObject]).scrollingEnabled = self.allowScrolling;
[self loadURL:self.defaultURL];
if(placeHolderImageView.image) {
@@ -78,7 +85,7 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.view bringSubviewToFront:self.webView];
- ((UIView*)[[__webView subviews] lastObject]).offset = self.scrollPosition;
+ ((UIView*)[[myWebView subviews] lastObject]).offset = self.scrollPosition;
}
- (void)viewWillDisappear:(BOOL)animated {
@@ -87,7 +94,7 @@ - (void)viewWillDisappear:(BOOL)animated {
placeHolderImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
- self.scrollPosition = ((UIView*)[[__webView subviews] lastObject]).offset;
+ self.scrollPosition = ((UIView*)[[myWebView subviews] lastObject]).offset;
[self.view bringSubviewToFront:placeHolderImageView];
[super viewWillDisappear:animated];
@@ -98,8 +105,8 @@ - (void)loadURL:(NSURL*)URL {
}
- (UIWebView*)webView {
- if([__webView superview] == self.view) {
- return __webView;
+ if([myWebView superview] == self.view) {
+ return myWebView;
} else {
return nil;
}
Oops, something went wrong.

0 comments on commit 0fcaa24

Please sign in to comment.