summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2013-11-10 18:51:44 +0400
committerGravatar Vitaly Takmazov2013-11-10 18:51:44 +0400
commit4e6a313148890e30774757b382aa3b3ba1622bb6 (patch)
tree999cfdbb23948a63d98ed0297ff337a8062d41fe
parent44ad254eb2533b922e5de47c65f4af8c37813519 (diff)
refactoring and threadview
-rw-r--r--Juick/AppDelegate.m9
-rw-r--r--Juick/Message.h2
-rw-r--r--Juick/Message.m8
-rw-r--r--Juick/MessageCell.h1
-rw-r--r--Juick/MessageCell.m7
-rw-r--r--Juick/MessagesViewController.m34
-rw-r--r--Juick/NewPostViewController.m16
7 files changed, 58 insertions, 19 deletions
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m
index b47e710..874ea94 100644
--- a/Juick/AppDelegate.m
+++ b/Juick/AppDelegate.m
@@ -12,6 +12,7 @@
#import "SWRevealViewController.h"
#import "ColorsAndButtons.h"
+#import "Message.h"
@implementation AppDelegate
@@ -35,12 +36,20 @@
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
SWRevealViewController *reveal = [[SWRevealViewController alloc] initWithRearViewController:rearNav frontViewController:main];
self.viewController = reveal;
+ [messages.navigationController.navigationBar addGestureRecognizer:reveal.panGestureRecognizer];
+ UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
+ style:UIBarButtonItemStyleBordered target:reveal action:@selector(revealToggle:)];
+ messages.navigationItem.leftBarButtonItem = revealButtonItem;
+ UIBarButtonItem *compose = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
+ target:messages action:@selector(composePressed)];
+ messages.navigationItem.rightBarButtonItem = compose;
} else {
UISplitViewController *split = [[UISplitViewController alloc] init];
split.viewControllers = [NSArray arrayWithObjects:rearNav, main, nil];
split.delegate = messages;
self.viewController = split;
}
+ [messages loadFromURL:[NSURL URLWithString:[Message messagesUrl]] withTitle:@"Discover"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.viewController;
diff --git a/Juick/Message.h b/Juick/Message.h
index 10e9fb3..51541a7 100644
--- a/Juick/Message.h
+++ b/Juick/Message.h
@@ -23,5 +23,7 @@
@property(nonatomic, copy) NSDecimalNumber *repliesCount;
+(void) pullNextFromURL:(NSURL *)url callback:(void(^)(NSArray *))callback;
++(NSString *) messagesUrl;
++(NSString *) threadUrl;
@end
diff --git a/Juick/Message.m b/Juick/Message.m
index 1d023c1..70d483c 100644
--- a/Juick/Message.m
+++ b/Juick/Message.m
@@ -39,4 +39,12 @@
[operation start];
}
++(NSString *) messagesUrl {
+ return @"https://api.juick.com/messages";
+}
+
++(NSString *) threadUrl {
+ return @"https://api.juick.com/thread";
+}
+
@end
diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h
index c1298af..7972470 100644
--- a/Juick/MessageCell.h
+++ b/Juick/MessageCell.h
@@ -16,6 +16,7 @@
#define kLabelHorizontalInsets 20.0f
+
@interface MessageCell : UITableViewCell<TTTAttributedLabelDelegate>
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m
index ad3a849..0777dfd 100644
--- a/Juick/MessageCell.m
+++ b/Juick/MessageCell.m
@@ -24,7 +24,6 @@
if (self) {
[self setBackgroundColor:[UIColor whiteColor]];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
self.avatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
[self.avatar setBackgroundColor:[UIColor clearColor]];
@@ -154,7 +153,11 @@
self.titleLabel.text = msg.user;
self.timestampLabel.text = msg.timestamp;
if (msg.repliesCount > 0) {
- self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy];
+ if ([msg.repliesBy length] > 0) {
+ self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy];
+ } else {
+ self.summaryLabel.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount];
+ }
} else {
self.summaryLabel.text = nil;
}
diff --git a/Juick/MessagesViewController.m b/Juick/MessagesViewController.m
index 372345a..7369bd9 100644
--- a/Juick/MessagesViewController.m
+++ b/Juick/MessagesViewController.m
@@ -61,6 +61,9 @@ static NSString *CellIdentifier = @"MessageCell";
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
+ if (self.url.absoluteString == [Message threadUrl]) {
+ return;
+ }
CGPoint pos = scrollView.contentOffset;
CGFloat contentHeight = scrollView.contentSize.height - scrollView.contentSize.height / 3;
if (pos.y >= contentHeight && !self.dataLoading) {
@@ -88,16 +91,6 @@ static NSString *CellIdentifier = @"MessageCell";
[super viewDidLoad];
self.dataLoading = NO;
[self.view setBackgroundColor:[ColorsAndButtons mainBackground]];
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- SWRevealViewController *revealController = [self revealViewController];
- [self.navigationController.navigationBar addGestureRecognizer:revealController.panGestureRecognizer];
- UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
- style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)];
- self.navigationItem.leftBarButtonItem = revealButtonItem;
- UIBarButtonItem *compose = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
- target:self action:@selector(composePressed)];
- self.navigationItem.rightBarButtonItem = compose;
- }
self.messages = [NSMutableArray array];
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
[refresh addTarget:self action:@selector(refreshData:) forControlEvents:UIControlEventValueChanged];
@@ -106,12 +99,16 @@ static NSString *CellIdentifier = @"MessageCell";
//UINib *cellNib = [UINib nibWithNibName:@"MessageCell" bundle:nil];
//[self.tableView registerNib:cellNib forCellReuseIdentifier:@"MessageCell"];
[self.tableView registerClass:[MessageCell class] forCellReuseIdentifier:CellIdentifier];
- [self loadFromURL:[NSURL URLWithString:@"https://api.juick.com/messages"] withTitle:@"Discover"];
-
}
- (void) composePressed {
- [self.navigationController pushViewController:[[NewPostViewController alloc] init] animated:YES];
+ CATransition* transition = [CATransition animation];
+ transition.duration = 0.3;
+ transition.type = kCATransitionFade;
+ transition.subtype = kCATransitionFromTop;
+
+ [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
+ [self.navigationController pushViewController:[[NewPostViewController alloc] init] animated:NO];
}
- (void)viewDidAppear:(BOOL)animated
@@ -165,8 +162,6 @@ static NSString *CellIdentifier = @"MessageCell";
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
-
-
MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell updateFonts];
@@ -192,6 +187,15 @@ static NSString *CellIdentifier = @"MessageCell";
return 100.0f;
}
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ if ([self.url.absoluteString hasPrefix:[Message threadUrl]])
+ return;
+ Message *msg = [_messages objectAtIndex:indexPath.row];
+ MessagesViewController *threadViewController = [[MessagesViewController alloc] init];
+ [threadViewController loadFromURL:[[NSURL URLWithString:[Message threadUrl]] URLByAppendingParameters:[NSDictionary dictionaryWithObjectsAndKeys:msg.MID, @"mid", nil]] withTitle:[NSString stringWithFormat:@"#%@", msg.MID]];
+ [self.navigationController pushViewController:threadViewController animated:NO];
+}
+
-(void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
self.navigationItem.leftBarButtonItem = nil;
}
diff --git a/Juick/NewPostViewController.m b/Juick/NewPostViewController.m
index 9e3db14..8c8fbf0 100644
--- a/Juick/NewPostViewController.m
+++ b/Juick/NewPostViewController.m
@@ -33,11 +33,23 @@
}
- (void) cancelCompose {
- [self.navigationController popViewControllerAnimated:YES];
+ CATransition* transition = [CATransition animation];
+ transition.duration = 0.3;
+ transition.type = kCATransitionFade;
+ transition.subtype = kCATransitionFromTop;
+
+ [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
+ [self.navigationController popViewControllerAnimated:NO];
}
- (void) doneCompose {
- [self.navigationController popToRootViewControllerAnimated:YES];
+ CATransition* transition = [CATransition animation];
+ transition.duration = 0.3;
+ transition.type = kCATransitionFade;
+ transition.subtype = kCATransitionFromTop;
+
+ [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
+ [self.navigationController popToRootViewControllerAnimated:NO];
}
- (void)didReceiveMemoryWarning