Skip to content

Commit

Permalink
Add refresh support for single topic controller
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Mar 1, 2014
1 parent a4cd558 commit 8a02040
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 29 deletions.
6 changes: 6 additions & 0 deletions V2EX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
5E98FF2618B0AD5000D9D2C2 /* V2EXNodesListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E98FF2518B0AD5000D9D2C2 /* V2EXNodesListCell.m */; };
5E98FF2718B0AD5000D9D2C2 /* V2EXNodesListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E98FF2518B0AD5000D9D2C2 /* V2EXNodesListCell.m */; };
5E98FF2B18B0AD9A00D9D2C2 /* V2EXNodesListCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5E98FF2A18B0AD9A00D9D2C2 /* V2EXNodesListCell.xib */; };
5ED82F0218C1788A00ADE079 /* V2EXSelfViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5ED82F0118C1788A00ADE079 /* V2EXSelfViewController.m */; };
5EDEFF3318B43C7700241C3F /* V2EXSingleTopicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EDEFF3218B43C7700241C3F /* V2EXSingleTopicViewController.m */; };
5EE2A26918AA79E700A63885 /* UIView+FrameMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE2A26718AA79E700A63885 /* UIView+FrameMethods.m */; };
5EE2A26C18ADAAA000A63885 /* V2EXNodesListModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE2A26B18ADAAA000A63885 /* V2EXNodesListModel.m */; };
Expand Down Expand Up @@ -136,6 +137,8 @@
5E98FF2418B0AD5000D9D2C2 /* V2EXNodesListCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = V2EXNodesListCell.h; sourceTree = "<group>"; };
5E98FF2518B0AD5000D9D2C2 /* V2EXNodesListCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = V2EXNodesListCell.m; sourceTree = "<group>"; };
5E98FF2A18B0AD9A00D9D2C2 /* V2EXNodesListCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = V2EXNodesListCell.xib; sourceTree = "<group>"; };
5ED82F0018C1788A00ADE079 /* V2EXSelfViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = V2EXSelfViewController.h; sourceTree = "<group>"; };
5ED82F0118C1788A00ADE079 /* V2EXSelfViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = V2EXSelfViewController.m; sourceTree = "<group>"; };
5EDEFF3118B43C7700241C3F /* V2EXSingleTopicViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = V2EXSingleTopicViewController.h; sourceTree = "<group>"; };
5EDEFF3218B43C7700241C3F /* V2EXSingleTopicViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = V2EXSingleTopicViewController.m; sourceTree = "<group>"; };
5EE2A26718AA79E700A63885 /* UIView+FrameMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+FrameMethods.m"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -222,6 +225,8 @@
5E23700E18B0FDA300B00501 /* V2EXTopicsListInSingleNodeViewController.m */,
5EDEFF3118B43C7700241C3F /* V2EXSingleTopicViewController.h */,
5EDEFF3218B43C7700241C3F /* V2EXSingleTopicViewController.m */,
5ED82F0018C1788A00ADE079 /* V2EXSelfViewController.h */,
5ED82F0118C1788A00ADE079 /* V2EXSelfViewController.m */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -619,6 +624,7 @@
5E66EAF9189A324700500B35 /* main.m in Sources */,
5E5B6763189A4CBF00EDF8FD /* V2EXSettingsViewController.m in Sources */,
5E0553D4189E7310002CEAAA /* V2EXMBProgressHUDUtil.m in Sources */,
5ED82F0218C1788A00ADE079 /* V2EXSelfViewController.m in Sources */,
5E98FED818B085B500D9D2C2 /* DRPaginatedScrollView.m in Sources */,
5E72BFBF18A4663D00BB88DD /* V2EXTableViewController.m in Sources */,
5EDEFF3318B43C7700241C3F /* V2EXSingleTopicViewController.m in Sources */,
Expand Down
5 changes: 3 additions & 2 deletions V2EX/Controllers/V2EXLatestTopicsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ - (void)loadListData {
[self.model getLatestTopics];
}

- (void)loadTopicData:(NSString *)ID {
- (void)loadTopicData:(NSUInteger)ID {
if ([self canStartNewLoading]) {
_loadingStatus = 2;
[self.model getTopicWithID:ID];
Expand Down Expand Up @@ -108,7 +108,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *ID = [[[self.data objectAtIndex:indexPath.row] valueForKey:@"id"] stringValue];
NSUInteger ID = [[[self.data objectAtIndex:indexPath.row] valueForKey:@"id"] intValue];
_topicIDWillBePushedTo = ID;
[self loadTopicData:ID];
}

Expand Down
13 changes: 13 additions & 0 deletions V2EX/Controllers/V2EXSelfViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// V2EXSelfViewController.h
// V2EX
//
// Created by WildCat on 3/1/14.
// Copyright (c) 2014 WildCat. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface V2EXSelfViewController : UIViewController

@end
38 changes: 38 additions & 0 deletions V2EX/Controllers/V2EXSelfViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// V2EXSelfViewController.m
// V2EX
//
// Created by WildCat on 3/1/14.
// Copyright (c) 2014 WildCat. All rights reserved.
//

#import "V2EXSelfViewController.h"

@interface V2EXSelfViewController ()

@end

@implementation V2EXSelfViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
10 changes: 4 additions & 6 deletions V2EX/Controllers/V2EXSingleTopicViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@

#import "V2EXTableViewController.h"

#import <DTAttributedTextView.h>
#import <DTLazyImageView.h>

@interface V2EXSingleTopicViewController : V2EXTableViewController <UIActionSheetDelegate, DTAttributedTextContentViewDelegate, DTLazyImageViewDelegate>
@interface V2EXSingleTopicViewController : V2EXTableViewController
{
// NSMutableArray *_cellHeightArray;
NSUInteger _topicID;
NSCache *_cellCache;
}

+ (V2EXSingleTopicViewController *)sharedController;

- (void)loadNewTopicWithID:(NSUInteger *)ID;
- (void)loadNewTopicWithData:(NSData *)data;
- (void)loadNewTopicWithID:(NSUInteger)ID;
- (void)loadNewTopicWithID:(NSUInteger)ID andData:(NSData *)data;

@end
21 changes: 18 additions & 3 deletions V2EX/Controllers/V2EXSingleTopicViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,27 @@ + (V2EXSingleTopicViewController *)sharedController
return _sharedSingleTopicViewControllerInstance;
}

- (void)loadNewTopicWithData:(NSData *)data {
- (void)loadNewTopicWithID:(NSUInteger)ID andData:(NSData *)data {
_topicID = ID;
[self requestDataSuccess:data];
}

- (void)loadNewTopicWithID:(NSUInteger *)ID {
//TODO: not implementation yet
- (void)loadNewTopicWithID:(NSUInteger)ID {
if (!self.data) {
[self showProgressView];
} else {
[self setData:nil];
_cellCache = nil;

self.data = [[NSMutableArray alloc] init];
_cellCache = [[NSCache alloc] init];
}

[self.model getTopicWithID:ID];
}

- (void)loadData {
[self loadNewTopicWithID:_topicID];
}

- (void)requestDataSuccess:(id)dataObject {
Expand Down
1 change: 1 addition & 0 deletions V2EX/Controllers/V2EXTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@interface V2EXTableViewController : UITableViewController <V2EXRequestDataDelegate>
{
NSUInteger _loadingStatus; // 0 - No loading ; 1 - Loading topic list ; 2 - Loading single topic
NSUInteger _topicIDWillBePushedTo;
}

@property (nonatomic, strong) NSMutableArray* data;
Expand Down
2 changes: 1 addition & 1 deletion V2EX/Controllers/V2EXTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ - (void)pushToSingleTopicViewController:(NSData *)dataObject {
}

V2EXSingleTopicViewController *singleTopicController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"singleTopicController"];
[singleTopicController loadNewTopicWithData:dataObject];
[singleTopicController loadNewTopicWithID:_topicIDWillBePushedTo andData:dataObject];
[self.navigationController pushViewController:singleTopicController animated:YES];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
@property (weak, nonatomic) NSMutableString *uri;

//+ (V2EXTopicsListInSingleNodeViewController *)sharedController;
- (void)loadNewNodeWithData:(NSData*)data;
- (void)loadNewNodeWithData:(NSData *)data;

@end
18 changes: 9 additions & 9 deletions V2EX/Controllers/V2EXTopicsListInSingleNodeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ - (void)loadData {
}
}

- (void)loadTopic:(NSString *)URI {
- (void)loadTopic:(NSUInteger)ID {
if ([self canStartNewLoading]) {
_loadingStatus = 2;
[self showProgressView];

[self.model getTopicWithLinkURI:URI];
[self.model getTopicWithID:ID];
}
}

Expand All @@ -87,7 +87,6 @@ - (void)requestDataSuccess:(id)dataObject {
}



- (void)requestDataFailure:(NSString *)errorMessage {
[super requestDataFailure:errorMessage];
}
Expand Down Expand Up @@ -164,7 +163,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (NSString *)link2TopicID:(NSString *) urlString{
- (NSUInteger)link2TopicID:(NSString *) urlString{
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"/t/[0-9]+#reply"
options:0
Expand All @@ -177,19 +176,20 @@ - (NSString *)link2TopicID:(NSString *) urlString{
NSTextCheckingResult *match = [array objectAtIndex:0];
NSRange firstHalfRange = [match rangeAtIndex:0];
NSString *result = [[[urlString substringWithRange:firstHalfRange] stringByReplacingOccurrencesOfString:@"/t/" withString:@""] stringByReplacingOccurrencesOfString:@"#reply" withString:@""];
return result;
return (NSUInteger)[result integerValue];
} else {
return nil;
return 0;
}
} else {
return nil;
return 0;
}
}

#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger index = [indexPath row];
[self loadTopic:[[self.data objectAtIndex:index] objectForKey:@"link"]];
NSUInteger topicID = [self link2TopicID:[[self.data objectAtIndex:[indexPath row]] objectForKey:@"link"]];
_topicIDWillBePushedTo = topicID;
[self loadTopic:topicID];
}

@end
4 changes: 2 additions & 2 deletions V2EX/Models/V2EXNormalModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// API
- (void)getIndex;
- (void)getTopicsList:(NSString *)URI;
- (void)getTopicWithLinkURI:(NSString *)URI;
- (void)getTopicWithID:(NSString *)id;
//- (void)getTopicWithLinkURI:(NSString *)URI;
- (void)getTopicWithID:(NSUInteger)ID;


// JSON API
Expand Down
10 changes: 5 additions & 5 deletions V2EX/Models/V2EXNormalModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ - (void)getTopicsList:(NSString *)URI {
[self getHTMLData:[@"go/" stringByAppendingString:URI] parameters:nil];
}

- (void)getTopicWithLinkURI:(NSString *)URI {
[self getHTMLData:[URI stringByReplacingOccurrencesOfString:@"/t/" withString:@"t/"] parameters:nil];
}
//- (void)getTopicWithLinkURI:(NSString *)URI {
// [self getHTMLData:[URI stringByReplacingOccurrencesOfString:@"/t/" withString:@"t/"] parameters:nil];
//}

- (void)getTopicWithID:(NSString *)id {
[self getHTMLData:[@"t/" stringByAppendingString:id] parameters:nil];
- (void)getTopicWithID:(NSUInteger)ID {
[self getHTMLData:[NSString stringWithFormat:@"t/%i", (unsigned int)ID] parameters:nil];
}


Expand Down

0 comments on commit 8a02040

Please sign in to comment.