From a228ce07cc5413a6ba164c12042ab1e4028aa5b3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 5 Dec 2017 01:40:51 +0300 Subject: comment --- Juick/APIClient.h | 3 +- Juick/APIClient.m | 22 ++++++---- Juick/Main.storyboard | 63 +++++++++++++++++++++++++++- Juick/ViewControllers/LoginViewController.h | 6 +-- Juick/ViewControllers/LoginViewController.m | 35 +++++----------- Juick/ViewControllers/ThreadViewController.m | 12 +++--- Juick/Views/MessageInputView.xib | 10 ++--- 7 files changed, 102 insertions(+), 49 deletions(-) diff --git a/Juick/APIClient.h b/Juick/APIClient.h index ca511a5..9347da9 100644 --- a/Juick/APIClient.h +++ b/Juick/APIClient.h @@ -6,6 +6,7 @@ // Copyright © 2016 com.juick. All rights reserved. // #import +#import "Message.h" @import AFNetworking; @interface APIClient : NSObject @@ -14,7 +15,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; +-(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback; +(NSString *) messagesUrl; +(NSString *) threadUrl; diff --git a/Juick/APIClient.m b/Juick/APIClient.m index ca894d4..bcc4eec 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -52,18 +52,22 @@ }); } --(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text { +-(void) postReplyToThread:(NSNumber *)mid inReplyTo:(NSNumber *)rid text:(NSString *)text result:(void(^)(Message *, NSError *))callback { 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]); - }]; + [manager POST:@"/comment" parameters:nil constructingBodyWithBlock:^(id _Nonnull formData) { + [formData appendPartWithFormData:[[mid stringValue] dataUsingEncoding:NSUTF8StringEncoding] name:@"mid"]; + [formData appendPartWithFormData:[[rid stringValue] dataUsingEncoding:NSUTF8StringEncoding] name:@"rid"]; + [formData appendPartWithFormData:[text dataUsingEncoding:NSUTF8StringEncoding] name:@"body"]; + } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { + NSLog(@"Success!"); + Message *reply = [Message yy_modelWithJSON:responseObject]; + callback(reply, nil); + } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + NSLog(@"Error: %@", [error localizedDescription]); + callback(nil, error); + }]; }]; } diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index 20bd3eb..b9cde68 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -102,7 +102,7 @@ - + @@ -111,6 +111,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -227,6 +287,7 @@ + diff --git a/Juick/ViewControllers/LoginViewController.h b/Juick/ViewControllers/LoginViewController.h index 6a834a8..7a6af5e 100644 --- a/Juick/ViewControllers/LoginViewController.h +++ b/Juick/ViewControllers/LoginViewController.h @@ -7,9 +7,9 @@ // #import -#import "XLForm.h" #import "PDKeychainBindingsController.h" -@interface LoginViewController : XLFormViewController - +@interface LoginViewController : UIViewController +@property (weak, nonatomic) IBOutlet UITextField *usernameField; +@property (weak, nonatomic) IBOutlet UITextField *passwordField; @end diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m index 640cd10..a65d180 100644 --- a/Juick/ViewControllers/LoginViewController.m +++ b/Juick/ViewControllers/LoginViewController.m @@ -16,10 +16,6 @@ - (void) awakeFromNib { [super awakeFromNib]; - [self initializeForm]; -} - -- (void)initializeForm { self.title = @"Sign in"; [self.view setBackgroundColor:[ColorScheme mainBackground]]; @@ -27,22 +23,8 @@ target:self action:@selector(cancelSignIn)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(doneSignIn)]; - XLFormDescriptor *form = [XLFormDescriptor formDescriptorWithTitle:@"Sign in"]; - form.rowNavigationOptions = XLFormRowNavigationOptionEnabled; - XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSection]; - [form addFormSection:section]; - XLFormRowDescriptor * usernameRow = [XLFormRowDescriptor - formRowDescriptorWithTag:@"com.juick.username" - rowType:XLFormRowDescriptorTypeText title:@"Username"]; - usernameRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; - [section addFormRow:usernameRow]; - XLFormRowDescriptor * passwordRow = [XLFormRowDescriptor - formRowDescriptorWithTag:@"com.juick.password" - rowType:XLFormRowDescriptorTypePassword title:@"Password"]; - passwordRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; - [section addFormRow:passwordRow]; - - self.form = form; + self.usernameField.text = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; + self.passwordField.text = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; } @@ -76,12 +58,15 @@ }]; } - --(void) formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue { - [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue]; - if ([newValue isKindOfClass:[NSString class]]) { - [[PDKeychainBindings sharedKeychainBindings] setObject:newValue forKey:formRow.tag]; +- (IBAction)passwordChanged:(id)sender { + if ([self.passwordField.text isKindOfClass:[NSString class]]) { + [[PDKeychainBindings sharedKeychainBindings] setObject:self.passwordField.text forKey:@"com.juick.password"]; } } +- (IBAction)usernameChanged:(id)sender { + if ([self.usernameField.text isKindOfClass:[NSString class]]) { + [[PDKeychainBindings sharedKeychainBindings] setObject:self.usernameField.text forKey:@"com.juick.username"]; + } +} @end diff --git a/Juick/ViewControllers/ThreadViewController.m b/Juick/ViewControllers/ThreadViewController.m index 2b0d3c4..95c9839 100644 --- a/Juick/ViewControllers/ThreadViewController.m +++ b/Juick/ViewControllers/ThreadViewController.m @@ -53,15 +53,17 @@ -(void) updateQuoteText:(Message *)message { MessageInputView *inputView = (MessageInputView *)self.inputAccessoryView; inputView.quoteText.text = message.text; - [inputView.contentView setNeedsUpdateConstraints]; - [inputView.contentView updateConstraintsIfNeeded]; - [inputView.contentView setNeedsLayout]; - [inputView.contentView layoutIfNeeded]; + [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]; + [[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 endEditing:YES]; + [self refreshData]; + }]; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib index 8eae920..54ba547 100644 --- a/Juick/Views/MessageInputView.xib +++ b/Juick/Views/MessageInputView.xib @@ -23,22 +23,22 @@ - + - + @@ -50,7 +50,7 @@