From 3c680cfe8c1e6cfbce16f787fbf01fdb3f7c40ae Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 4 Dec 2017 00:20:02 +0300 Subject: WIP --- Juick/APIClient.h | 1 + Juick/APIClient.m | 15 +++++ Juick/ViewControllers/MessagesViewController.m | 2 +- Juick/ViewControllers/ThreadViewController.h | 3 +- Juick/ViewControllers/ThreadViewController.m | 31 +++++++--- Juick/Views/MessageInputView.h | 15 +++++ Juick/Views/MessageInputView.m | 13 ++++ Juick/Views/MessageInputView.xib | 82 ++++++++++++++++++++++++++ 8 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 Juick/Views/MessageInputView.h create mode 100644 Juick/Views/MessageInputView.m create mode 100644 Juick/Views/MessageInputView.xib (limited to 'Juick') diff --git a/Juick/APIClient.h b/Juick/APIClient.h index 8c6e024..ca511a5 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -14,6 +14,7 @@ +(APIClient *) sharedClient; -(void) pullNextFromPath:(NSString *)path params:(NSDictionary *)params callback:(void(^)(NSArray *, NSError *))callback; +-(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text; +(NSString *) messagesUrl; +(NSString *) threadUrl; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index beace7c..ca894d4 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -52,6 +52,21 @@ }); } +-(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text { + AFHTTPSessionManager *manager = [APIClient sharedClient].manager; + NSOperationQueue *operationQueue = [NSOperationQueue new]; + [operationQueue addOperationWithBlock:^{ + [manager POST:@"/post" parameters: + @{ + @"mid": mid, + @"rid": rid, + @"body": text + } progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Errrorrr: %@", [error localizedDescription]); + }]; + }]; +} + +(NSString *) messagesUrl { return @"/messages"; diff --git a/Juick/ViewControllers/MessagesViewController.m b/Juick/ViewControllers/MessagesViewController.m index 5a5a794..71f4271 100644 --- a/Juick/ViewControllers/MessagesViewController.m +++ b/Juick/ViewControllers/MessagesViewController.m @@ -117,7 +117,7 @@ if (lastMsg != nil) { NSNumber *lastMid = lastMsg.mid; if (![self.path isEqualToString:[APIClient threadUrl]]) { - [self.params setObject:lastMid forKey:@"before_mid"]; + self.params = [@{@"before_mid":lastMid} mutableCopy]; } [self refreshData]; } diff --git a/Juick/ViewControllers/ThreadViewController.h b/Juick/ViewControllers/ThreadViewController.h index 484e2fb..a9c5259 100644 --- a/Juick/ViewControllers/ThreadViewController.h +++ b/Juick/ViewControllers/ThreadViewController.h @@ -8,7 +8,6 @@ #import #include "MessagesViewController.h" -@import PHFComposeBarView; -@interface ThreadViewController : MessagesViewController +@interface ThreadViewController : MessagesViewController @end diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m index 4de0cab..2b0d3c4 100644 --- a/Juick/ViewControllers/ThreadViewController.m +++ b/Juick/ViewControllers/ThreadViewController.m @@ -9,13 +9,15 @@ #import "ThreadViewController.h" #import "ColorScheme.h" #import "MessageCell.h" -@import PHFComposeBarView; +#import "MessageInputView.h" +#import "APIClient.h" @interface ThreadViewController () @property (nonatomic, readwrite, retain) UIView *inputAccessoryView; -(void) updateQuoteText:(Message *)message; +@property NSNumber *replyTo; @end @@ -23,6 +25,9 @@ - (void)viewDidLoad { [super viewDidLoad]; + self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; + + _replyTo = @(0); } @@ -32,26 +37,36 @@ - (UIView *)inputAccessoryView { if (!_inputAccessoryView) { - CGRect viewBounds = self.view.bounds; - CGRect frame = CGRectMake(0, viewBounds.size.height - PHFComposeBarViewInitialHeight - self.view.safeAreaInsets.top + self.view.safeAreaInsets.bottom, viewBounds.size.width, PHFComposeBarViewInitialHeight); - PHFComposeBarView *inputView = [[PHFComposeBarView alloc] initWithFrame:frame]; - inputView.backgroundColor = [UIColor whiteColor]; + 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.delegate = self;*/ + inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight; + [inputView.sendButton addTarget:self action:@selector(sendReply) forControlEvents:UIControlEventTouchUpInside]; _inputAccessoryView = inputView; } return _inputAccessoryView; } -(void) updateQuoteText:(Message *)message { - /*MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; - inputView.quoteText.text = message.text;*/ + MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; + inputView.quoteText.text = message.text; + [inputView.contentView setNeedsUpdateConstraints]; + [inputView.contentView updateConstraintsIfNeeded]; + [inputView.contentView setNeedsLayout]; + [inputView.contentView layoutIfNeeded]; +} +-(void) sendReply { + MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; + Message *msg = [self.messages firstObject]; + [[APIClient sharedClient] postReplyToThread:msg.mid inReplyTo:self.replyTo text:inputView.textContent.text]; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Message * selectedMessage = [self.messages objectAtIndex:indexPath.row]; + _replyTo = selectedMessage.rid; [self updateQuoteText:selectedMessage]; } diff --git a/Juick/Views/MessageInputView.h b/Juick/Views/MessageInputView.h new file mode 100644 index 0000000..46919b4 --- /dev/null +++ b/Juick/Views/MessageInputView.h @@ -0,0 +1,15 @@ +// +// MessageInputView.h +// Juick +// +// Created by Vitaly Takmazov on 03/12/2017. +// Copyright © 2017 com.juick. All rights reserved. +// + +#import + +@interface MessageInputView : UIVisualEffectView +@property (weak, nonatomic) IBOutlet UILabel *quoteText; +@property (weak, nonatomic) IBOutlet UIButton *sendButton; +@property (weak, nonatomic) IBOutlet UITextView *textContent; +@end diff --git a/Juick/Views/MessageInputView.m b/Juick/Views/MessageInputView.m new file mode 100644 index 0000000..147a508 --- /dev/null +++ b/Juick/Views/MessageInputView.m @@ -0,0 +1,13 @@ +// +// MessageInputView.m +// Juick +// +// Created by Vitaly Takmazov on 03/12/2017. +// Copyright © 2017 com.juick. All rights reserved. +// + +#import "MessageInputView.h" +@implementation MessageInputView + + +@end diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib new file mode 100644 index 0000000..54ba547 --- /dev/null +++ b/Juick/Views/MessageInputView.xib @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3