-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestViewController.m
196 lines (162 loc) · 6.44 KB
/
TestViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// TestViewController.m
// BreezyReader
//
// Created by Jin Jin on 10-6-2.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "TestViewController.h"
@implementation TestViewController
@synthesize username;
@synthesize password;
@synthesize queryURL;
@synthesize googleReaderController;
@synthesize label;
@synthesize states;
@synthesize sourceImageTag;
@synthesize parseResult;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqual:@"loginStatus"]){
DebugLog(@"login status changed!!");
// NSString* oldValue = [change objectForKey:NSKeyValueChangeOldKey];
// NSString* newValue = [change objectForKey:NSKeyValueChangeNewKey];
// DebugLog(@"old value is: %@", oldValue);
// DebugLog(@"new value is: %@", newValue);
}
}
-(IBAction)testConnection{
[self testConnectionWithUserName:[username text] andPassword:[password text]];
}
-(IBAction)logout{
DebugLog(@"logout now");
[[GoogleAuthManager shared] logout];
}
-(void)testConnectionWithUserName:(NSString*)aUsername
andPassword:(NSString*)aPassword{
DebugLog(@"connecting starts");
// GoogleAuthManager *authManager = [GoogleAuthManager shared];
// [authManager loginForUser:aUsername withPassword:aPassword];
DebugLog(@"connecting finished");
}
-(IBAction)queryAction{
DebugLog(@"querying the api %@", queryURL.text);
[googleReaderController testGoogleAPIwithURL:queryURL.text];
}
-(IBAction)allSubscription{
[googleReaderController allSubscriptions];
[googleReaderController allTags];
[googleReaderController unreadCount];
}
-(IBAction)readSubscription{
NSString* url = queryURL.text;
// NSString* url = nil;
GRFeed* parsedFeed = [googleReaderController getFeedForURL:url count:nil startFrom:nil exclude:nil continuation:nil];
[parsedFeed retain];
for (GRItem* item in parsedFeed.items){
DebugLog(@"item id is %@, item title is %@", item.ID, item.title);
}
[parsedFeed release];
parsedFeed = nil;
}
-(IBAction)testReadForLabel{
NSString* labelText = self.label.text;
GRFeed* parsedFeed = [googleReaderController getFeedForLabel:labelText count:nil startFrom:nil exclude:nil continuation:nil];
[parsedFeed retain];
for (GRItem* item in parsedFeed.items){
DebugLog(@"item id is %@, item title is %@", item.ID, item.title);
}
[parsedFeed release];
parsedFeed = nil;
}
-(IBAction)testReadForState{
NSString* stateText = self.states.text;
GRFeed* parsedFeed = [googleReaderController getFeedForStates:stateText count:nil startFrom:nil exclude:nil continuation:nil];
[parsedFeed retain];
for (GRItem* item in parsedFeed.items){
DebugLog(@"item id is %@, item title is %@", item.ID, item.title);
}
[parsedFeed release];
parsedFeed = nil;
}
-(IBAction)parseImageTag{
/*
NSString* tagString = @"< iMg width=\"200\" height=300 title=\"每日一美女:Scarlett" "Johansson\" alt=\"每日一美女:Scarlett Johansson / Jandan.net\"src= http://pic.yupoo.com/jdvip/506119acf7bc/medium.jpg ' />< img width=\"200\" height=300 title=\"每日一美女:Scarlett" "Johansson\" alt=\"每日一美女:Scarlett Johansson / Jandan.net\"SrC= http://pic.yupoo.com/jdvip/506119acf7bc/medium222222222222.jpg ' />";
// NSString* htmlString = @"<img src = http://pic.yupoo.com/jdvip/506119acf7bc/medium.jpg ' title=\"每日一美女:Scarlett" "Johansson\" alt=\"每日一美女:Scarlett Johansson / Jandan.net\"/>";
NSString* searchPattern = @"(?<=<img\\s*.*\\s*src=\\s*[\"|’])(.*?)(?=[\"|'])";
// NSString* propertyParttern = @"(?i)(?<=<img).*(?=>)";
NSString* propertyParttern = @"(?i)<\\s*img\\s*.*?\\s*src\\s*=\\s*[\"']?\\s*([^\\s'\"]*)\\s*[\"']?\\s*.*?>";
NSString* srcParttern = @"\\bsrc\\s*=\\s*[\"|'](.+?)[\"|']";
NSString* result = [tagString stringByMatching:searchPattern capture:1L];
NSArray* resultArray = [tagString arrayOfCaptureComponentsMatchedByRegex:propertyParttern];
for (NSString* tempStr in resultArray){
DebugLog(@"tempStr: %@", tempStr);
}
// NSString* imageProperties = [tagString stringByMatching:propertyParttern capture:1];
// NSString* imageSrc = [imageProperties stringByMatching:srcParttern capture:1L];
//
// DebugLog(@"source string is %@", tagString);
// DebugLog(@"regex string is %@", searchPattern);
// DebugLog(@"match string is %@", result);
// DebugLog(@"imageProperties is %@", imageProperties);
// DebugLog(@"image src is %@", imageSrc);
// UIWebView* tempView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
//
// [tempView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.google.com"]];
//
// UIViewController* tempController = [[UIViewController alloc] init];
//
// tempController.view = tempView;
//
// [self presentModelViewController:tempController animated:YES];
self.parseResult.text = result;
*/
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (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 {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(id)init{
if (self = [super init]){
[[GoogleAuthManager shared] addObserver:self
forKeyPath:@"loginStatus"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:self];
GoogleReaderController* tempController = [[GoogleReaderController alloc] init];
self.googleReaderController = tempController;
[tempController release];
}
return self;
}
- (void)dealloc {
[self.googleReaderController release];
[super dealloc];
}
@end