summaryrefslogtreecommitdiff
path: root/Juick/ViewControllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-08 23:17:47 +0300
committerGravatar Vitaly Takmazov2018-04-08 23:17:47 +0300
commitf6fed5b2374c7d847c68efccce363f9513aa2efb (patch)
tree74021a451bd5cfb1df1a7771a32dbc121a7163c6 /Juick/ViewControllers
parent6f8855ce3b83cc50583b62b4a1960c27fdf66bb3 (diff)
PM posts
Diffstat (limited to 'Juick/ViewControllers')
-rw-r--r--Juick/ViewControllers/ChatViewController.h4
-rw-r--r--Juick/ViewControllers/ChatViewController.m53
-rw-r--r--Juick/ViewControllers/DialogsViewController.m1
-rw-r--r--Juick/ViewControllers/DiscoverViewController.m2
4 files changed, 53 insertions, 7 deletions
diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h
index 7ea8030..3479942 100644
--- a/Juick/ViewControllers/ChatViewController.h
+++ b/Juick/ViewControllers/ChatViewController.h
@@ -9,7 +9,9 @@
#import <UIKit/UIKit.h>
#import "User.h"
-@interface ChatViewController : UITableViewController
+@import PHFComposeBarView;
+
+@interface ChatViewController : UITableViewController<PHFComposeBarViewDelegate>
@property(nonatomic, strong) NSMutableArray *messages;
@property(nonatomic, strong) NSString *uname;
@end
diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m
index e94bb40..489de66 100644
--- a/Juick/ViewControllers/ChatViewController.m
+++ b/Juick/ViewControllers/ChatViewController.m
@@ -12,6 +12,8 @@
@interface ChatViewController ()
+@property (nonatomic, readwrite, retain) UIView *inputAccessoryView;
+
@end
@implementation ChatViewController
@@ -23,7 +25,13 @@
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
self.tableView.allowsSelection = NO;
+ [self reloadChat];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
+}
+
+-(void) reloadChat {
self.messages = [NSMutableArray array];
+ [self.tableView reloadData];
[[APIClient sharedClient] fetchChatWithUser:self.uname callback:^(NSArray *messages, NSError *err) {
if (err == nil) {
[self.messages addObjectsFromArray:[[messages reverseObjectEnumerator] allObjects]];
@@ -39,11 +47,6 @@
}];
}
-- (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
-}
-
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
@@ -62,4 +65,44 @@
return cell;
}
+-(BOOL) canBecomeFirstResponder {
+ return YES;
+}
+
+- (UIView *) inputAccessoryView {
+ if (!_inputAccessoryView) {
+ PHFComposeBarView *composeView = [[PHFComposeBarView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - PHFComposeBarViewInitialHeight, self.view.bounds.size.width, PHFComposeBarViewInitialHeight)];
+ composeView.delegate = self;
+ [composeView.bottomAnchor constraintEqualToSystemSpacingBelowAnchor:self.view.safeAreaLayoutGuide.bottomAnchor multiplier:1.0f];
+ composeView.maxLinesCount = 4;
+ _inputAccessoryView = composeView;
+ }
+ return _inputAccessoryView;
+}
+
+-(void) keyboardWillChangeFrame:(NSNotification *)notification {
+ NSDictionary *userInfo = [notification userInfo];
+ if (userInfo) {
+ CGRect beginFrame = [userInfo [UIKeyboardFrameBeginUserInfoKey] CGRectValue];
+ CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
+ CGFloat delta = endFrame.origin.y - beginFrame.origin.y;
+ CGFloat duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
+ UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
+ [UIView animateWithDuration:duration delay:0 options:(animationCurve << 16) animations:^{
+ self.tableView.contentOffset = CGPointMake(0, self.tableView.contentOffset.y - delta);
+ } completion:nil];
+ }
+}
+
+-(void) composeBarViewDidPressButton:(PHFComposeBarView *)composeBarView {
+ [[APIClient sharedClient] postPMToUser:self.uname text:composeBarView.text result:^(NSError *err) {
+ if (!err) {
+ NSLog(@"Success!");
+ [composeBarView becomeFirstResponder];
+ [composeBarView setText:nil animated:NO];
+ [self reloadChat];
+ }
+ }];
+}
+
@end
diff --git a/Juick/ViewControllers/DialogsViewController.m b/Juick/ViewControllers/DialogsViewController.m
index a36acf3..d080176 100644
--- a/Juick/ViewControllers/DialogsViewController.m
+++ b/Juick/ViewControllers/DialogsViewController.m
@@ -59,7 +59,6 @@
if ([segue.identifier isEqualToString:@"chatSegue"]) {
NSString *uname;
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- NSLog(@"pushed name is %@", appDelegate.pushedUname);
if ([appDelegate.pushedUname length] > 0) {
uname = [appDelegate.pushedUname copy];
appDelegate.pushedThread = nil;
diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m
index 110d8c7..d57947e 100644
--- a/Juick/ViewControllers/DiscoverViewController.m
+++ b/Juick/ViewControllers/DiscoverViewController.m
@@ -11,6 +11,7 @@
#import "MessageCell.h"
#import "APIClient.h"
#import "AppDelegate.h"
+#import "ColorScheme.h"
@interface DiscoverViewController ()
@@ -107,6 +108,7 @@
[self.tableView reloadData];
[self refreshData:NO];
}]];
+ [filterAlert.view setTintColor:[ColorScheme linkColor]];
[self presentViewController:filterAlert animated:YES completion:nil];
}