Skip to content

Commit

Permalink
Version 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gal3riel committed Mar 18, 2013
1 parent 28e44a1 commit 8cb0c2a
Show file tree
Hide file tree
Showing 12 changed files with 2,027 additions and 52 deletions.
Binary file added Resources/Placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Stage1st.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
C096CD3D16EADD3300D4FF7F /* SVWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C096CD3716EADD3300D4FF7F /* SVWebViewController.m */; };
C096CD3F16EADE0000D4FF7F /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C096CD3E16EADE0000D4FF7F /* MessageUI.framework */; };
C0AEAE8116F5F88D00CB0E71 /* S1BaseURLViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C0AEAE8016F5F88D00CB0E71 /* S1BaseURLViewController.m */; };
C0AEAE8316F60D7900CB0E71 /* Placeholder.png in Resources */ = {isa = PBXBuildFile; fileRef = C0AEAE8216F60D7900CB0E71 /* Placeholder.png */; };
C0AEAE8716F6267900CB0E71 /* MTStatusBarOverlay.m in Sources */ = {isa = PBXBuildFile; fileRef = C0AEAE8616F6267900CB0E71 /* MTStatusBarOverlay.m */; };
C0B1919716F0A80F0053E0C5 /* content_ipad.css in Resources */ = {isa = PBXBuildFile; fileRef = C0B1919616F0A80F0053E0C5 /* content_ipad.css */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -231,6 +233,9 @@
C096CD3E16EADE0000D4FF7F /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; };
C0AEAE7F16F5F88D00CB0E71 /* S1BaseURLViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = S1BaseURLViewController.h; path = Stage1st/S1BaseURLViewController.h; sourceTree = "<group>"; };
C0AEAE8016F5F88D00CB0E71 /* S1BaseURLViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = S1BaseURLViewController.m; path = Stage1st/S1BaseURLViewController.m; sourceTree = "<group>"; };
C0AEAE8216F60D7900CB0E71 /* Placeholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Placeholder.png; path = Resources/Placeholder.png; sourceTree = "<group>"; };
C0AEAE8516F6267900CB0E71 /* MTStatusBarOverlay.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTStatusBarOverlay.h; sourceTree = "<group>"; };
C0AEAE8616F6267900CB0E71 /* MTStatusBarOverlay.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTStatusBarOverlay.m; sourceTree = "<group>"; };
C0B1919616F0A80F0053E0C5 /* content_ipad.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = content_ipad.css; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -384,6 +389,7 @@
C095875416CA8A3E007E0119 /* Vendors */ = {
isa = PBXGroup;
children = (
C0AEAE8416F6267800CB0E71 /* MTStatusBarOverlay */,
C096CD2D16EADD3300D4FF7F /* SVWebViewController */,
C083353B16E647A70035C1AA /* GoogleToolbox */,
C083352216E4E1550035C1AA /* REComposeViewController */,
Expand All @@ -397,6 +403,7 @@
C095875516CA8A43007E0119 /* Resources */ = {
isa = PBXGroup;
children = (
C0AEAE8216F60D7900CB0E71 /* Placeholder.png */,
C08B602116E1B5CE00591827 /* Logo.png */,
C08B602216E1B5CE00591827 /* [email protected] */,
C002D2B916EC665D00A5414E /* Icon-72.png */,
Expand Down Expand Up @@ -551,6 +558,16 @@
path = Vendors/SVWebViewController;
sourceTree = "<group>";
};
C0AEAE8416F6267800CB0E71 /* MTStatusBarOverlay */ = {
isa = PBXGroup;
children = (
C0AEAE8516F6267900CB0E71 /* MTStatusBarOverlay.h */,
C0AEAE8616F6267900CB0E71 /* MTStatusBarOverlay.m */,
);
name = MTStatusBarOverlay;
path = Vendors/MTStatusBarOverlay;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -643,6 +660,7 @@
C002D2BB16EC665D00A5414E /* Icon-72.png in Resources */,
C002D2BC16EC665D00A5414E /* [email protected] in Resources */,
C0B1919716F0A80F0053E0C5 /* content_ipad.css in Resources */,
C0AEAE8316F60D7900CB0E71 /* Placeholder.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -693,6 +711,7 @@
C096CD3B16EADD3300D4FF7F /* SVModalWebViewController.m in Sources */,
C096CD3D16EADD3300D4FF7F /* SVWebViewController.m in Sources */,
C0AEAE8116F5F88D00CB0E71 /* S1BaseURLViewController.m in Sources */,
C0AEAE8716F6267900CB0E71 /* MTStatusBarOverlay.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
41 changes: 25 additions & 16 deletions Stage1st/S1ContentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "S1HUD.h"
#import "REComposeViewController.h"
#import "SVModalWebViewController.h"
#import "MTStatusBarOverlay.h"


#define _REPLY_PER_PAGE 50
Expand Down Expand Up @@ -255,11 +256,12 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger

[replyController setCompletionHandler:^(REComposeViewController *composeViewController, REComposeResult result){
if (result == REComposeResultCancelled) {
[composeViewController dismissViewControllerAnimated:NO completion:nil];
[composeViewController dismissViewControllerAnimated:YES completion:nil];
}
else if (result == REComposeResultPosted) {
if (composeViewController.text.length > 0) {
[self replyWithReplyController:composeViewController];
[self replyWithReplyText:composeViewController.text];
[composeViewController dismissViewControllerAnimated:YES completion:nil];
}
}
}];
Expand All @@ -285,7 +287,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger

if (2 == buttonIndex) {
[self rootViewController].modalPresentationStyle = UIModalPresentationFullScreen;
SVModalWebViewController *controller = [[SVModalWebViewController alloc] initWithAddress:[NSString stringWithFormat:@"http://bbs.saraba1st.com/2b/read-htm-tid-%@.html", self.topic.topicID]];
SVModalWebViewController *controller = [[SVModalWebViewController alloc] initWithAddress:[NSString stringWithFormat:@"%@/2b/read-htm-tid-%@.html",[[NSUserDefaults standardUserDefaults] valueForKey:@"BaseURL"], self.topic.topicID]];
[self presentViewController:controller animated:YES completion:nil];
}
}
Expand Down Expand Up @@ -358,29 +360,36 @@ - (void)fetchContent
}];
}

- (void)replyWithReplyController:(REComposeViewController *)composeViewController
- (void)replyWithReplyText:(NSString *)text
{
NSString *suffix = @"\n\n——— 来自Stage1st Reader Evolution";
NSString *replyWithSuffix = [composeViewController.text stringByAppendingString:suffix];
NSString *replyWithSuffix = [text stringByAppendingString:suffix];
NSString *timestamp = [[NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]] substringToIndex:10];
NSString *path = [NSString stringWithFormat:@"m/post.php?action=reply&tid=%@&tmp=%@", self.topic.topicID, timestamp];

MTStatusBarOverlay *overlay = [MTStatusBarOverlay sharedInstance];
overlay.animation = MTStatusBarOverlayAnimationShrink;

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.HTTPClient postPath:path
parameters:@{ @"fid":self.topic.fID, @"content":replyWithSuffix }
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *HTMLString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Reply Response: %@", HTMLString);
if (_currentPage == _totalPages) {
_needToScrollToBottom = YES;
[self fetchContent];
}
[composeViewController dismissViewControllerAnimated:NO completion:nil];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

NSString *HTMLString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Reply Response: %@", HTMLString);

if (HTMLString.length > 0) {
[overlay postFinishMessage:@"回复成功" duration:2.5 animated:YES];
_needToScrollToBottom = YES;
[self fetchContent];
} else {
[overlay postErrorMessage:@"回复很可能未成功" duration:2.5 animated:YES];
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
NSLog(@"%@", error);
[overlay postErrorMessage:@"回复失败" duration:2.5 animated:YES];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}];
}

Expand Down
2 changes: 1 addition & 1 deletion Stage1st/S1Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

static NSString * const topicPattern = @"<li><a href=.*?t(\\d+).*?>(.*?)</a>.*?\\((\\d+)";
static NSString * const cssPattern = @"</style>";
static NSString * const cleanupPattern = @"(?:<br />(<br />)?\\r\\n<center>.*?</center>)|(?:<table cellspacing=\"1\" cellpadding=\"0\".*?</table>.*?</table>)|(?:src=\"http://.*?/images/back\\.gif\")|(?:onload=\"if\\(this.offsetWidth>'600'\\)this.width='600';\")";
static NSString * const cleanupPattern = @"(?:<br />(<br />)?\\r\\n<center>.*?</center>)|(?:<table cellspacing=\"1\" cellpadding=\"0\".*?</table>.*?</table>)|(?:src=\"http://[-.0-9a-zA-Z]+/2b/images/back\\.gif\")|(?:onload=\"if\\(this.offsetWidth>'600'\\)this.width='600';\")";
static NSString * const indexPattern = @"td><b>(.*?)</b></td>\\r\\n<td align=\"right\" class=\"smalltxt\"";


Expand Down
6 changes: 3 additions & 3 deletions Stage1st/S1TabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
- (id)initWithFrame:(CGRect)frame andKeys:(NSArray *)keys;
- (void)deselectAll;

@property (nonatomic, assign) id<S1TabBarDelegate> tabbarDelegate;

//@property (nonatomic, copy) void (^eventHandler)(NSString *key);
@property (nonatomic, weak) id<S1TabBarDelegate> tabbarDelegate;

@property (nonatomic, strong) NSArray *keys;
@property (nonatomic, assign) BOOL enabled;



@end
Expand Down
2 changes: 2 additions & 0 deletions Stage1st/S1TabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (id)initWithFrame:(CGRect)frame andKeys:(NSArray *)keys
if (!self) return nil;
_keys = keys;
_index = -1;
_enabled = YES;
_buttons = [NSMutableArray arrayWithCapacity:keys.count];
self.backgroundColor = [UIColor blackColor];
self.bounces = NO;
Expand Down Expand Up @@ -98,6 +99,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL

- (void)tapped:(UIButton *)sender
{
if (!_enabled) return;
if (_index >= 0)
[_buttons[_index] setSelected:NO];
_index = sender.tag;
Expand Down
2 changes: 1 addition & 1 deletion Stage1st/S1TopicListCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ - (void)drawRect:(CGRect)rect
[titleContent drawInRect: titleRect withFont:[UIFont boldSystemFontOfSize:15.0f] lineBreakMode: NSLineBreakByTruncatingTail alignment: NSTextAlignmentLeft];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[titleContent drawAtPoint:titlePoint forWidth:self.bounds.size.width-90.0f withFont:[UIFont boldSystemFontOfSize:18.0] fontSize:17.0 lineBreakMode:NSLineBreakByTruncatingTail baselineAdjustment:UIBaselineAdjustmentAlignCenters];
[titleContent drawAtPoint:titlePoint forWidth:self.bounds.size.width-120.0f withFont:[UIFont boldSystemFontOfSize:18.0] fontSize:17.0 lineBreakMode:NSLineBreakByTruncatingTail baselineAdjustment:UIBaselineAdjustmentAlignCenters];
}


Expand Down
63 changes: 34 additions & 29 deletions Stage1st/S1TopicListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,17 @@ - (void)recent:(id)sender
}

[self.scrollTabBar deselectAll];
self.currentKey = nil;
self.currentKey = @"";
}

- (void)refresh:(id)sender
{
if (self.scrollTabBar.userInteractionEnabled) {
if (self.refreshControl.hidden) {
[self.refreshControl endRefreshing];
return;
}

if (self.scrollTabBar.enabled) {
[self fetchTopicsForKeyFromServer:self.currentKey scrollToTop:NO];
} else {
[self.refreshControl endRefreshing];
Expand All @@ -200,12 +205,14 @@ - (void)refresh:(id)sender
- (void)tabbar:(S1TabBar *)tabbar didSelectedKey:(NSString *)key
{
self.naviItem.title = @"Stage1st";

if (self.tableView.hidden) {
self.tableView.hidden = NO;
}
if (self.refreshControl.hidden) {
self.refreshControl.hidden = NO;
}

if (![self.currentKey isEqualToString:key]) {
self.currentKey = key;
[self fetchTopicsForKey:key];
Expand All @@ -232,39 +239,39 @@ - (void)fetchTopicsForKey:(NSString *)key

- (void)fetchTopicsForKeyFromServer:(NSString *)key scrollToTop:(BOOL)toTop
{
self.scrollTabBar.userInteractionEnabled = NO;
self.scrollTabBar.enabled = NO;
S1HUD *HUD = [S1HUD showHUDInView:self.view];
[HUD showActivityIndicator];
NSString *path = [NSString stringWithFormat:@"simple/?f%@.html", self.threadsInfo[key]];
[self.HTTPClient getPath:path
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *HTMLString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
if (HTMLString) {
NSArray *topics = [S1Parser topicsFromHTMLString:HTMLString withContext:@{@"FID": self.threadsInfo[self.currentKey]}];
if (topics.count > 0) {
self.topics = topics;
self.cache[key] = topics;
[self.tableView reloadData];
if (toTop) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
}
}
if (self.refreshControl.refreshing) {
[self.refreshControl endRefreshing];
}
[HUD hideWithDelay:0.3];
self.scrollTabBar.userInteractionEnabled = YES;
NSString *HTMLString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
if (HTMLString) {
NSArray *topics = [S1Parser topicsFromHTMLString:HTMLString withContext:@{@"FID": self.threadsInfo[self.currentKey]}];
if (topics.count > 0) {
self.topics = topics;
self.cache[key] = topics;
[self.tableView reloadData];
if (toTop) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
}
}
if (self.refreshControl.refreshing) {
[self.refreshControl endRefreshing];
}
[HUD hideWithDelay:0.3];
self.scrollTabBar.enabled = YES;

}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[HUD setText:@"Request Failed"];
[HUD hideWithDelay:0.3];
self.scrollTabBar.userInteractionEnabled = YES;
if (self.refreshControl.refreshing) {
[self.refreshControl endRefreshing];
}
[HUD setText:@"Request Failed"];
[HUD hideWithDelay:0.3];
self.scrollTabBar.enabled = YES;
if (self.refreshControl.refreshing) {
[self.refreshControl endRefreshing];
}
}];
}

Expand Down Expand Up @@ -327,10 +334,8 @@ - (NSArray *)keys

- (void)updateTabbar:(id)sender
{
self.currentKey = @"";
self.topics = [NSArray array];
[self.tableView reloadData];
[self.scrollTabBar setKeys:[self keys]];
self.tableView.hidden = YES;
}

- (void)updateHTTPClient:(id)sender
Expand Down
2 changes: 1 addition & 1 deletion Stage1st/S1URLCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
return [super cachedResponseForRequest:request];
}
else {
NSData *imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"placeholder" ofType:@"png"]];
NSData *imageData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Placeholder" ofType:@"png"]];
NSURLResponse *response =
[[NSURLResponse alloc] initWithURL:request.URL
MIMEType:@"image/png"
Expand Down
Loading

0 comments on commit 8cb0c2a

Please sign in to comment.