Skip to content

Commit

Permalink
Mac version updates tweet timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
luciuskwok committed Aug 12, 2010
1 parent cd9cf9a commit 36d3e58
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 64 deletions.
3 changes: 2 additions & 1 deletion Classes-Mac/ConversationWindowController.m
Expand Up @@ -31,8 +31,9 @@ - (id)init {
// Timeline HTML Controller generates the HTML from a timeline
ConversationHTMLController *controller = [[[ConversationHTMLController alloc] initWithMessageIdentifier:nil] autorelease];
controller.twitter = appDelegate.twitter;
self.htmlController = controller;
controller.delegate = self;
controller.useRewriteHTMLTimer = YES;
self.htmlController = controller;
}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions Classes-Mac/MainWindowController.m
Expand Up @@ -44,6 +44,7 @@ - (id)init {
self.htmlController = [[[TimelineHTMLController alloc] init] autorelease];
htmlController.twitter = appDelegate.twitter;
htmlController.delegate = self;
htmlController.useRewriteHTMLTimer = YES;

// Listen for changes to Twitter state data
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
Expand Down
1 change: 1 addition & 0 deletions Classes-Mac/SearchWindowController.m
Expand Up @@ -36,6 +36,7 @@ - (id)initWithQuery:(NSString*)aQuery {
SearchResultsHTMLController *controller = [[[SearchResultsHTMLController alloc] initWithQuery:aQuery twitter:appDelegate.twitter] autorelease];
controller.twitter = appDelegate.twitter;
controller.delegate = self;
controller.useRewriteHTMLTimer = YES;
self.htmlController = controller;

// Listen for changes to Saved Searches list
Expand Down
1 change: 1 addition & 0 deletions Classes-Mac/UserWindowController.m
Expand Up @@ -40,6 +40,7 @@ - (id)initWithScreenName:(NSString*)aScreenName account:(TwitterAccount *)anAcco
controller.twitter = appDelegate.twitter;
controller.account = anAccount;
controller.delegate = self;
controller.useRewriteHTMLTimer = YES;
self.htmlController = controller;
}
return self;
Expand Down
6 changes: 6 additions & 0 deletions Classes-Shared/HTML Controllers/TimelineHTMLController.h
Expand Up @@ -54,6 +54,9 @@
BOOL noInternetConnection;
BOOL suppressNetworkErrorAlerts;

NSTimer *rewriteHTMLTimer;
BOOL useRewriteHTMLTimer;

id delegate;
}

Expand All @@ -73,6 +76,8 @@
@property (assign) BOOL noInternetConnection;
@property (assign) BOOL suppressNetworkErrorAlerts;

@property (assign) BOOL useRewriteHTMLTimer;

@property (assign) id <TimelineHTMLControllerDelegate> delegate;

// Timeline selection
Expand All @@ -99,6 +104,7 @@
// Web view updating
- (void)loadWebView;
- (void)rewriteTweetArea;
- (void)scheduleRewriteHTMLTimer;

// Web actions
- (BOOL)handleWebAction:(NSString*)action;
Expand Down
29 changes: 28 additions & 1 deletion Classes-Shared/HTML Controllers/TimelineHTMLController.m
Expand Up @@ -34,6 +34,7 @@
#else
const int kDefaultMaxTweetsShown = 160;
#endif
const int kRewriteHTMLTimerInterval = 60;
static NSString *kTimelineIdentifier = @"Timeline";
static NSString *kMentionsIdentifier = @"Mentions";
static NSString *kDirectMessagesIdentifier = @"Direct";
Expand All @@ -45,6 +46,7 @@ @implementation TimelineHTMLController
@synthesize webView, twitter, account, timeline, messages;
@synthesize maxTweetsShown, webViewHasValidHTML, isLoading, noInternetConnection, suppressNetworkErrorAlerts;
@synthesize customPageTitle, customTabName;
@synthesize useRewriteHTMLTimer;
@synthesize delegate;


Expand All @@ -60,7 +62,7 @@ - (id)init {
tweetGapRowTemplate = [[self loadHTMLTemplate:@"load-gap-template"] retain];

// Loading template
loadingHTML = [@"<div class='status'><img class='status_spinner_image' src='spinner.gif'> Loading...</div>"retain];
loadingHTML = [@"<div class='status'><img class='status_spinner_image' src='spinner.gif'> Loading...</div>" retain];

// Misc
isLoading = YES;
Expand Down Expand Up @@ -96,6 +98,9 @@ - (void)dealloc {
[customPageTitle release];
[customTabName release];

[rewriteHTMLTimer invalidate];
rewriteHTMLTimer = nil;

[super dealloc];
}

Expand Down Expand Up @@ -336,6 +341,10 @@ - (void)loadWebView {
[html replaceOccurrencesOfString:@"<tabAreaHTML/>" withString:tabAreaHTML options:0 range:NSMakeRange(0, html.length)];

[self.webView loadHTMLString:html];

if (useRewriteHTMLTimer) {
[self scheduleRewriteHTMLTimer];
}
}

- (void)setLoadingSpinnerVisibility:(BOOL)isVisible {
Expand All @@ -360,6 +369,23 @@ - (void)rewriteTweetArea {
// This isn't really a bug or exception to call this method when the web view isn't ready, so it isn't logged.
//NSLog (@"rewriteTweetArea called when webViewHasValidHTML == NO.");
}

if (useRewriteHTMLTimer) {
[self scheduleRewriteHTMLTimer];
}
}

- (void)scheduleRewriteHTMLTimer {
if (useRewriteHTMLTimer) {
[rewriteHTMLTimer invalidate];
rewriteHTMLTimer = [NSTimer scheduledTimerWithTimeInterval:kRewriteHTMLTimerInterval target:self selector:@selector(fireRewriteHTMLTimer:) userInfo:nil repeats:NO];
}
}

- (void)fireRewriteHTMLTimer:(NSTimer *)timer {
if (useRewriteHTMLTimer) {
[self rewriteTweetArea];
}
}

#pragma mark Web actions
Expand Down Expand Up @@ -406,6 +432,7 @@ - (NSNumber*)number64WithString:(NSString*)string {
return nil;
}


#pragma mark HTML

- (NSString *)htmlWithTemplate:(NSString *)template substitutions:(NSDictionary *)substitutions {
Expand Down

0 comments on commit 36d3e58

Please sign in to comment.