Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Mais transições; Hyphenate.js retirado por problemas de desempenho (e…
Browse files Browse the repository at this point in the history
… GPL); correcções várias.
  • Loading branch information
goblindegook committed Feb 7, 2011
1 parent 6f67430 commit 3c52a26
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 3,111 deletions.
8 changes: 4 additions & 4 deletions Classes/DARemote.m
Expand Up @@ -50,7 +50,7 @@ - (id)initWithQuery:(NSString *)theQuery ofType:(int)theType delegate:(id<DARemo

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:urlFormat, [query stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

NSLog(@"Remote API call: %@", [url absoluteURL]);
// NSLog(@"Remote API call: %@", [url absoluteURL]);

// Change to NSURLRequestUseProtocolCachePolicy later

Expand Down Expand Up @@ -157,7 +157,7 @@ - (NSCachedURLResponse *) connection:(NSURLConnection *)connection


- (void)cancel {
NSLog(@"Cancelling request for '%@'", self.query);
// NSLog(@"Cancelling request for '%@'", self.query);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[connection cancel];
}
Expand Down Expand Up @@ -199,7 +199,7 @@ + (NSString *)fetchCachedResultForQuery:(NSString *)query ofType:(int)type error

} else if ([cachedResponses count] > 0) {
DASearchCache *cache = (DASearchCache *)[cachedResponses lastObject];
NSLog(@"Fetched cached response '%@' (type %d)", [cache searchQuery], type);
// NSLog(@"Fetched cached response '%@' (type %d)", [cache searchQuery], type);
response = [cache searchResult];

NSDate *now = [[NSDate alloc] init];
Expand All @@ -222,7 +222,7 @@ + (BOOL)cacheResult:(NSString *)theResult forQuery:(NSString *)theQuery ofType:(
NSDate *now = [[NSDate alloc] init];
BOOL success = YES;

NSLog(@"Caching search response (type %d) '%@'", theType, theQuery);
// NSLog(@"Caching search response (type %d) '%@'", theType, theQuery);

DASearchCache *cachedResponse = (DASearchCache *)[NSEntityDescription insertNewObjectForEntityForName:@"DASearchCache" inManagedObjectContext:moc];

Expand Down
8 changes: 7 additions & 1 deletion Classes/DefinitionController.h
Expand Up @@ -10,7 +10,7 @@
#import "DAParser.h"

#import "Entry.h"
#import "Form.h"
#import "EntryForm.h"
#import "EntrySense.h"
#import "EntrySenseUsage.h"
#import "EntryEtymology.h"
Expand All @@ -32,13 +32,19 @@
NSMutableArray *requestResults;
NSMutableString *requestEntry;
int requestN;

BOOL transitioning;

BOOL touchRequest;
NSMutableString *touchRequestPreviousEntry;
int touchRequestPreviousN;
}

- (id)initWithRequest:(NSString *)entry atIndex:(int)n;
- (void)searchDicionarioAberto:(NSString *)query;
- (void)loadNoConnection:(UIWebView *)wv withString:(NSString *)query;
- (void)loadEntry:(UIWebView *)wv withArray:(NSArray *)entries atIndex:(int)n;
- (void)performTransitionTo:(NSArray *)results atIndex:(int)n;
- (NSString *)htmlEntryFrom:(NSArray *)entries atIndex:(int)n;

- (IBAction)changePage:(id)sender;
Expand Down
62 changes: 46 additions & 16 deletions Classes/DefinitionController.m
Expand Up @@ -56,6 +56,7 @@ - (void)viewDidLoad {

pager.numberOfPages = 1;
transitioning = NO;
touchRequest = NO;

[self searchDicionarioAberto:requestEntry];
}
Expand Down Expand Up @@ -88,6 +89,7 @@ - (void)dealloc {
[definitionView1 release];
[definitionView2 release];
[container release];
[touchRequestPreviousEntry release];
[requestEntry release];
[requestResults release];
[super dealloc];
Expand Down Expand Up @@ -191,12 +193,17 @@ - (void)searchDicionarioAberto:(NSString *)query {
if (nil != cachedResponse) {
// Use cached response
requestResults = [[DAParser parseAPIResponse:cachedResponse list:NO] copy];
[self loadEntry:definitionView1 withArray:requestResults atIndex:requestN];
if (touchRequest) {
[self performTransitionTo:requestResults atIndex:requestN];
} else {
[self loadEntry:definitionView1 withArray:requestResults atIndex:requestN];
}

} else {
// Perform new asynchronous request
DARemote *connection = [[DARemote alloc] initWithQuery:query ofType:DARemoteGetEntry delegate:self];
if (nil == connection) {
touchRequest = NO;
// Connection error
[self loadNoConnection:definitionView1 withString:query];
} else {
Expand Down Expand Up @@ -242,38 +249,50 @@ - (void)loadEntry:(UIWebView *)wv withArray:(NSArray *)entries atIndex:(int)n {
}


- (void)performTransitionTo:(int)n {

if (n == requestN) {
- (void)performTransitionTo:(NSArray *)results atIndex:(int)n {
if (!touchRequest && n == requestN) {
return;
}

BOOL transitionForward = NO;

if (touchRequest && [requestEntry caseInsensitiveCompare:touchRequestPreviousEntry] == NSOrderedAscending) {
transitionForward = YES;
} else if (n < requestN) {
transitionForward = YES;
} else {
transitionForward = NO;
}


CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = (n < requestN) ? kCATransitionMoveIn : kCATransitionReveal;
transition.subtype = (n < requestN) ? kCATransitionFromLeft : kCATransitionFromRight;
transition.type = (transitionForward) ? kCATransitionMoveIn : kCATransitionReveal;
transition.subtype = (transitionForward) ? kCATransitionFromLeft : kCATransitionFromRight;
transition.delegate = self;

[container.layer addAnimation:transition forKey:nil];

requestN = n;
transitioning = YES;

[self loadEntry:definitionView2 withArray:requestResults atIndex:n];
[self loadEntry:definitionView2 withArray:results atIndex:n];

// Switch views only when definitionView2 finishes loading, see webViewDidFinishLoad
}


- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
transitioning = NO;
touchRequest = NO;
}


- (IBAction)changePage:(id)sender {
if (!transitioning) {
[self performTransitionTo:(pager.currentPage + 1)];
[self performTransitionTo:requestResults atIndex:(pager.currentPage + 1)];
}
}

Expand All @@ -294,7 +313,7 @@ - (void)webViewDidStartLoad:(UIWebView *)webView {
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Animate only when
// Animate only when not transitioning
if (transitioning && webView == definitionView2) {
definitionView1.hidden = YES;
definitionView2.hidden = NO;
Expand All @@ -318,10 +337,15 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
// Internal links

if ([[url host] isEqualToString:@"define"]) {
touchRequest = YES;
touchRequestPreviousEntry = [requestEntry copy];
touchRequestPreviousN = requestN;

// Definition links (aberto://define:*/*)
requestEntry = [[url lastPathComponent] copy];
requestN = [[url port] integerValue];
NSLog(@"Requested %@:%d", requestEntry, requestN);

// NSLog(@"Requested %@:%d", requestEntry, requestN);
[self searchDicionarioAberto:requestEntry];
}
return NO;
Expand All @@ -344,16 +368,18 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni

- (void)swipeRightAction {
if (!transitioning && pager.currentPage > 0) {
pager.currentPage = pager.currentPage - 1;
[self performTransitionTo:(pager.currentPage + 1)];
int transitionTo = pager.currentPage - 1;
[self performTransitionTo:requestResults atIndex:(transitionTo + 1)];
pager.currentPage = transitionTo;
}
}


- (void)swipeLeftAction {
if (!transitioning && pager.currentPage < pager.numberOfPages) {
pager.currentPage = pager.currentPage + 1;
[self performTransitionTo:(pager.currentPage + 1)];
if (!transitioning && pager.currentPage < pager.numberOfPages - 1) {
int transitionTo = pager.currentPage + 1;
[self performTransitionTo:requestResults atIndex:(transitionTo + 1)];
pager.currentPage = transitionTo;
}
}

Expand All @@ -376,7 +402,11 @@ - (void)connectionDidFinish:(DARemote *)connection {
[DARemote cacheResult:response forQuery:connection.query ofType:connection.type error:nil];
}

[self loadEntry:definitionView1 withArray:requestResults atIndex:requestN];
if (touchRequest) {
[self performTransitionTo:requestResults atIndex:requestN];
} else {
[self loadEntry:definitionView1 withArray:requestResults atIndex:requestN];
}

[response release];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/InfoTableController.m
Expand Up @@ -120,7 +120,7 @@ - (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)index
NSDictionary *sectionDictionary = [infoTableContents objectAtIndex:indexPath.section];
NSDictionary *rowDictionary = [[sectionDictionary objectForKey:@"Rows"] objectAtIndex:indexPath.row];

NSLog(@"Selected (%d, %d)", indexPath.section, indexPath.row);
// NSLog(@"Selected (%d, %d)", indexPath.section, indexPath.row);

InfoPageController *infoPage = [[InfoPageController alloc] initWithURI:[NSURL URLWithString:[rowDictionary objectForKey:@"URI"]] title:[rowDictionary objectForKey:@"Title"]];

Expand Down
8 changes: 4 additions & 4 deletions DicionarioAberto-Info.plist
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
Expand All @@ -22,7 +20,7 @@
<string>Icon-Small@2x.png</string>
</array>
<key>CFBundleIdentifier</key>
<string>pt.log.${PRODUCT_NAME:rfc1034identifier}</string>
<string>28FR7Y5X6M.pt.log.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand All @@ -32,12 +30,14 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.0b2</string>
<key>LSRequiresIPhoneOS</key>
<false/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
<key>UIPrerenderedIcon</key>
<true/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
</dict>
</plist>
38 changes: 38 additions & 0 deletions DicionarioAberto.xcodeproj/project.pbxproj
Expand Up @@ -514,6 +514,8 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = DicionarioAberto_Prefix.pch;
INFOPLIST_FILE = "DicionarioAberto-Info.plist";
LIBRARY_SEARCH_PATHS = /usr/include/libxml2;
OTHER_LDFLAGS = "-lxml2";
PRODUCT_NAME = Aberto;
};
name = Debug;
Expand All @@ -526,6 +528,8 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = DicionarioAberto_Prefix.pch;
INFOPLIST_FILE = "DicionarioAberto-Info.plist";
LIBRARY_SEARCH_PATHS = /usr/include/libxml2;
OTHER_LDFLAGS = "-lxml2";
PRODUCT_NAME = Aberto;
VALIDATE_PRODUCT = YES;
};
Expand Down Expand Up @@ -557,20 +561,53 @@
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
PRODUCT_NAME = Aberto;
SDKROOT = iphoneos;
};
name = Release;
};
DC0B5E9B12FEE12800AD52DC /* Ad Hoc */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/include/libxml2;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
PRODUCT_NAME = Aberto;
SDKROOT = iphoneos;
};
name = "Ad Hoc";
};
DC0B5E9C12FEE12800AD52DC /* Ad Hoc */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = DicionarioAberto_Prefix.pch;
INFOPLIST_FILE = "DicionarioAberto-Info.plist";
LIBRARY_SEARCH_PATHS = /usr/include/libxml2;
OTHER_LDFLAGS = "-lxml2";
PRODUCT_NAME = Aberto;
VALIDATE_PRODUCT = YES;
};
name = "Ad Hoc";
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "DicionarioAberto" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1D6058940D05DD3E006BFB54 /* Debug */,
DC0B5E9C12FEE12800AD52DC /* Ad Hoc */,
1D6058950D05DD3E006BFB54 /* Release */,
);
defaultConfigurationIsVisible = 0;
Expand All @@ -580,6 +617,7 @@
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
DC0B5E9B12FEE12800AD52DC /* Ad Hoc */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
Expand Down
1 change: 0 additions & 1 deletion HTML/abbrev.html
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Hyphenator.js" type="text/javascript"></script>
<script src="JS/Common.js" type="text/javascript"></script>
</head>
<body id="da" class="static">
Expand Down
1 change: 0 additions & 1 deletion HTML/about.html
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Hyphenator.js" type="text/javascript"></script>
<script src="JS/Common.js" type="text/javascript"></script>
</head>
<body id="da" class="static">
Expand Down
8 changes: 3 additions & 5 deletions HTML/credits.html
Expand Up @@ -3,10 +3,9 @@
<head>
<title>Sobre o Dicionário</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Hyphenator.js" type="text/javascript"></script>
<script src="JS/Common.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Common.js" type="text/javascript"></script>
</head>
<body id="da" class="static">
<article class="credits">
Expand All @@ -25,7 +24,6 @@ <h2>Desenho e concepção da aplicação</h2>
<h2>Componentes aplicacionais</h2>
<p>
Ole Begemann <i>(OBGradientView)</i><br>
Mathias Nater <i>(Hyphenator)</i><br>
Jonathan Wight <i>(TouchXML)</i>
</p>

Expand Down
1 change: 0 additions & 1 deletion HTML/intro0.html
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Hyphenator.js" type="text/javascript"></script>
<script src="JS/Common.js" type="text/javascript"></script>
</head>
<body id="da" class="static">
Expand Down
1 change: 0 additions & 1 deletion HTML/intro1.html
Expand Up @@ -5,7 +5,6 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
<link rel="stylesheet" type="text/css" href="DicionarioAberto.css">
<script src="JS/Hyphenator.js" type="text/javascript"></script>
<script src="JS/Common.js" type="text/javascript"></script>
</head>
<body id="da" class="static">
Expand Down

0 comments on commit 3c52a26

Please sign in to comment.