summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/MessagesViewController.h3
-rw-r--r--Juick/ViewControllers/MessagesViewController.m16
-rw-r--r--Juick/ViewControllers/NewPostViewController.h6
-rw-r--r--Juick/ViewControllers/NewPostViewController.m45
-rw-r--r--Juick/ViewControllers/ThreadViewController.m63
5 files changed, 72 insertions, 61 deletions
diff --git a/Juick/ViewControllers/MessagesViewController.h b/Juick/ViewControllers/MessagesViewController.h
index 7f5f274..548f8ec 100644
--- a/Juick/ViewControllers/MessagesViewController.h
+++ b/Juick/ViewControllers/MessagesViewController.h
@@ -11,7 +11,8 @@
@interface MessagesViewController : UITableViewController
@property(nonatomic, strong) NSString *path;
@property(nonatomic, strong) NSMutableDictionary *params;
-- (void) refreshData;
+-(void) refreshData;
+-(void) refreshData:(BOOL)scrollToBottom;
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, assign) Boolean dataLoading;
diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m
index 80e8c73..823d838 100644
--- a/Juick/ViewControllers/MessagesViewController.m
+++ b/Juick/ViewControllers/MessagesViewController.m
@@ -23,7 +23,11 @@
@implementation MessagesViewController
-- (void) refreshData {
+-(void) refreshData {
+ [self refreshData:NO];
+}
+
+-(void) refreshData:(BOOL)scrollToBottom {
self.dataLoading = YES;
[[APIClient sharedClient] pullNextFromPath:self.path params:self.params callback:^(NSArray *next, NSError *err) {
NSArray *newMsgs = next;
@@ -49,6 +53,10 @@
[self.tableView endUpdates];
[self.refreshControl endRefreshing];
self.dataLoading = NO;
+ if (scrollToBottom) {
+ NSIndexPath *lastRow = [NSIndexPath indexPathForRow:self.messages.count - 1 inSection:0];
+ [self.tableView scrollToRowAtIndexPath:lastRow atScrollPosition:UITableViewScrollPositionBottom animated:YES];
+ }
}];
}
@@ -75,7 +83,7 @@
if ([self.path length] == 0) {
self.path = [APIClient feedUrl];
}
- [self refreshData];
+ [self refreshData:NO];
} else {
[User throwUnableToLogin:self];
}
@@ -85,7 +93,7 @@
if ([self.path length] == 0) {
self.path = [APIClient messagesUrl];
}
- [self refreshData];
+ [self refreshData:NO];
}
}
@@ -119,7 +127,7 @@
if (![self.path isEqualToString:[APIClient threadUrl]]) {
self.params = [@{@"before_mid":lastMid} mutableCopy];
}
- [self refreshData];
+ [self refreshData:NO];
}
}
}
diff --git a/Juick/ViewControllers/NewPostViewController.h b/Juick/ViewControllers/NewPostViewController.h
index 3d4ba88..7a1dfac 100644
--- a/Juick/ViewControllers/NewPostViewController.h
+++ b/Juick/ViewControllers/NewPostViewController.h
@@ -7,8 +7,14 @@
//
#import <UIKit/UIKit.h>
+#import "Message.h"
@interface NewPostViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
+
+@property (strong, nonatomic) NSString *draft;
+
+@property (strong, nonatomic) Message *replyTo;
+
@end
diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m
index 9643b78..8a9bc0e 100644
--- a/Juick/ViewControllers/NewPostViewController.m
+++ b/Juick/ViewControllers/NewPostViewController.m
@@ -7,13 +7,18 @@
//
#import "NewPostViewController.h"
+#import "MessagesViewController.h"
#import "ColorScheme.h"
+#import "MessageInputView.h"
+#import "APIClient.h"
@interface NewPostViewController ()
@property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic, assign) int paddingValue;
+@property (nonatomic, readwrite, retain) UIView *inputAccessoryView;
+
@end
@implementation NewPostViewController
@@ -21,8 +26,14 @@
- (void)viewDidLoad
{
[super viewDidLoad];
- self.navigationController.visibleViewController.title = @"Post";
- self.navigationController.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
+ if (_replyTo != nil) {
+ MessageInputView *inputView = (MessageInputView *) self.inputAccessoryView;
+ inputView.quoteText.text = _replyTo.text;
+ self.navigationController.visibleViewController.title = [NSString stringWithFormat:@"Reply to %@", _replyTo.user.uname];
+ } else {
+ self.navigationController.visibleViewController.title = @"Post";
+ }
+ self.navigationController.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelCompose)];
self.navigationController.visibleViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(doneCompose)];
@@ -37,7 +48,19 @@
}
- (void) doneCompose {
- [self.navigationController.visibleViewController.navigationController popToRootViewControllerAnimated:YES];
+ if (_replyTo == nil) {
+ [[APIClient sharedClient] postMessage:self.textView.text result:^(Message *msg, NSError *err) {
+ [self.navigationController.visibleViewController.navigationController popViewControllerAnimated:YES];
+ MessagesViewController *target = (MessagesViewController *)self.navigationController.visibleViewController;
+ [target refreshData:YES];
+ }];
+ } else {
+ [[APIClient sharedClient] postReplyToThread:_replyTo.mid inReplyTo:_replyTo.rid text:self.textView.text result:^(Message *msg, NSError *err) {
+ [self.navigationController.visibleViewController.navigationController popViewControllerAnimated:YES];
+ MessagesViewController *target = (MessagesViewController *)self.navigationController.visibleViewController;
+ [target refreshData:YES];
+ }];
+ }
}
-(void) keyboardDidShow:(NSNotification *)sender {
@@ -53,4 +76,20 @@
self.bottomConstraint.constant = self.paddingValue;
[self.view layoutIfNeeded];
}
+
+-(BOOL) canBecomeFirstResponder {
+ return YES;
+}
+
+- (UIView *) inputAccessoryView {
+ if (!_inputAccessoryView) {
+ MessageInputView *inputView = (MessageInputView *)[[[NSBundle mainBundle] loadNibNamed:@"MessageInputView" owner:self options:nil] firstObject];
+ inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
+ inputView.quoteText.text = self.replyTo.text;
+ _inputAccessoryView = inputView;
+ }
+ return _inputAccessoryView;
+}
+
+
@end
diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m
index 06cbf9a..8cb2cb5 100644
--- a/Juick/ViewControllers/ThreadViewController.m
+++ b/Juick/ViewControllers/ThreadViewController.m
@@ -7,70 +7,27 @@
//
#import "ThreadViewController.h"
-#import "ColorScheme.h"
+#import "NewPostViewController.h"
#import "MessageCell.h"
-#import "MessageInputView.h"
-#import "APIClient.h"
@interface ThreadViewController ()
-@property (nonatomic, readwrite, retain) UIView *inputAccessoryView;
-
--(void) updateQuoteText:(Message *)message;
-@property NSNumber *replyTo;
-
@end
@implementation ThreadViewController
-- (void)viewDidLoad {
- [super viewDidLoad];
- self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
-
- _replyTo = @(0);
-}
-
-
-- (BOOL) canBecomeFirstResponder {
- return YES;
+-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSString * cellIdentifier = @"messageCell";
+ MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
+ [self performSegueWithIdentifier:@"replySegue" sender:cell];
}
-- (UIView *)inputAccessoryView {
- if (!_inputAccessoryView) {
- MessageInputView *inputView = (MessageInputView *)[[[NSBundle mainBundle] loadNibNamed:@"MessageInputView" owner:self options:nil] firstObject];
- /*inputView.backgroundColor = [UIColor whiteColor];
- inputView.buttonTintColor = [ColorScheme linkColor];
- inputView.maxLinesCount = 4;
- inputView.utilityButtonImage = [UIImage imageNamed:@"Camera"];
- inputView.delegate = self;*/
- inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
- [inputView.sendButton addTarget:self action:@selector(sendReply) forControlEvents:UIControlEventTouchUpInside];
- _inputAccessoryView = inputView;
+-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ if ([segue.identifier isEqual: @"replySegue"]) {
+ Message *msg = [self.messages objectAtIndex:[self.tableView indexPathForSelectedRow].row];
+ NewPostViewController *postVC = (NewPostViewController *)segue.destinationViewController;
+ [postVC setReplyTo:msg];
}
- return _inputAccessoryView;
-}
-
--(void) updateQuoteText:(Message *)message {
- MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView;
- inputView.quoteText.text = message.text;
- [inputView.textContent becomeFirstResponder];
-}
--(void) sendReply {
- MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView;
- Message *msg = [self.messages firstObject];
- [[APIClient sharedClient] postReplyToThread:msg.mid inReplyTo:self.replyTo text:inputView.textContent.text result:^(Message *msg, NSError *err) {
- MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView;
- inputView.quoteText.text = @"";
- inputView.textContent.text = @"";
- [inputView.textContent endEditing:YES];
- [self refreshData];
- }];
-}
-
--(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- Message * selectedMessage = [self.messages objectAtIndex:indexPath.row];
- _replyTo = selectedMessage.rid;
- [self updateQuoteText:selectedMessage];
}
@end