Permalink
Browse files

Small fixes

1. Added unescaping for some special chars, may be needed to change in future
2. Fixed the formation of rep changes.
  • Loading branch information...
1 parent 2589e73 commit f944531486ff75a167e1405c2fe112de0fc69784 @BinyaminSharet committed Apr 13, 2012
Showing with 23 additions and 13 deletions.
  1. +18 −12 SONotifier/LinkMenuItem.m
  2. +4 −1 SONotifier/UpdateManager.m
  3. +1 −0 SONotifier/UserData.m
View
@@ -24,25 +24,31 @@ @implementation LinkMenuItem
@synthesize url;
- (NSAttributedString *) createTitleFromDictionary:(NSDictionary *)dict {
- NSString * simpleString;
- NSMutableAttributedString * finalStr;
+ NSMutableAttributedString * finalStr = [[[NSMutableAttributedString alloc] init] autorelease];
+ NSAttributedString * current;
+ NSString * title;
NSDictionary * attributes;
NSColor * repColor;
NSNumber * reputation = [dict objectForKey:API_KEY_REPUTATION_CHANGE];
repColor = ([reputation intValue] > 0) ? [NSColor greenColor] : [NSColor redColor];
- attributes = [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSFont fontWithName:@"Helvetica" size:12], NSFontAttributeName,
+ attributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSFont fontWithName:@"Helvetica" size:14], NSFontAttributeName,
repColor, NSForegroundColorAttributeName,
nil];
- simpleString = [NSString stringWithFormat:@"%@ \t%@", reputation, [dict objectForKey:API_KEY_REPUTATION_TITLE]];
- if ([simpleString length] > 60) {
- simpleString = [NSString stringWithFormat:@"%@...",
- [simpleString substringToIndex:57]];
+ current = [[[NSAttributedString alloc]
+ initWithString:[NSString stringWithFormat:@"%@\t", reputation]
+ attributes:attributes] autorelease];
+ [finalStr appendAttributedString:current];
+ attributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSFont fontWithName:@"Helvetica" size:14], NSFontAttributeName,
+ nil];
+ title = [dict objectForKey:API_KEY_REPUTATION_TITLE];
+ if ([title length] > 50) {
+ title = [NSString stringWithFormat:@"%@...", [title substringToIndex:47]];
}
- finalStr = [[NSMutableAttributedString alloc] initWithString:simpleString];
- [finalStr setAttributes:attributes range:NSMakeRange(0, 4)];
- [attributes release];
- [finalStr autorelease];
+ current = [[[NSAttributedString alloc]
+ initWithString:title attributes:attributes] autorelease];
+ [finalStr appendAttributedString:current];
return finalStr;
}
@@ -54,6 +54,8 @@ - (NSString *) getDataForUrl:(NSString *)urlString {
response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (response != nil) {
responseStr = [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease];
+ responseStr = [responseStr stringByReplacingOccurrencesOfString:@""" withString:@"\\\""];
+ responseStr = [responseStr stringByReplacingOccurrencesOfString:@"'" withString:@"'"];
NSLog(@"Received data: %@", responseStr);
}
return responseStr;
@@ -65,7 +67,8 @@ - (NSString *) getDataForApiRequest:(NSString *) apiRequest {
}
- (NSString *) buildNewQuestionQuery {
- return @"/questions?page=1&pagesize=10&order=desc&sort=activity&site=stackoverflow";
+ //return @"/questions?page=1&pagesize=10&order=desc&sort=activity&site=stackoverflow";
+ return @"/questions?page=1&pagesize=10&order=desc&sort=activity&site=stackoverflow&filter=!-rf7acLF";
}
- (void) bgUpdate {
View
@@ -49,6 +49,7 @@ - (id) init {
- (BOOL) updateLastChangesFromJsonString:(NSString *)jsonString {
NSError *jsonParsingError = nil;
+ NSLog(@"Asking to parse jsonString:!!!!!%@!!!!!", jsonString);
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&jsonParsingError];
if (data) {

0 comments on commit f944531

Please sign in to comment.