summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-12-05 01:40:51 +0300
committerGravatar Vitaly Takmazov2017-12-05 01:40:51 +0300
commita228ce07cc5413a6ba164c12042ab1e4028aa5b3 (patch)
treef1e8eafe6ebcf9beebd9a0ebdd4a1f8d591f8698 /Juick
parent888cbddb1eaab4f4f343ffd6e0bf8d976b579794 (diff)
comment
Diffstat (limited to 'Juick')
-rw-r--r--Juick/APIClient.h3
-rw-r--r--Juick/APIClient.m22
-rw-r--r--Juick/Main.storyboard63
-rw-r--r--Juick/ViewControllers/LoginViewController.h6
-rw-r--r--Juick/ViewControllers/LoginViewController.m35
-rw-r--r--Juick/ViewControllers/ThreadViewController.m12
-rw-r--r--Juick/Views/MessageInputView.xib10
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 <Foundation/Foundation.h>
+#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<AFMultipartFormData> _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 @@
<navigationItem key="navigationItem" title="Discover" id="M2f-nV-K0C">
<barButtonItem key="leftBarButtonItem" image="profile_icon" id="Sd1-hN-fdS">
<connections>
- <segue destination="NJR-jw-Kd1" kind="push" id="LYE-GD-USd"/>
+ <segue destination="4g9-hM-bzq" kind="push" id="6ha-6h-L0E"/>
</connections>
</barButtonItem>
</navigationItem>
@@ -111,6 +111,66 @@
</objects>
<point key="canvasLocation" x="-671.5" y="-188.5"/>
</scene>
+ <!--Login View Controller-->
+ <scene sceneID="hlR-4j-yzx">
+ <objects>
+ <viewController id="4g9-hM-bzq" customClass="LoginViewController" sceneMemberID="viewController">
+ <view key="view" contentMode="scaleToFill" id="ak5-5Q-P4e">
+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <stackView opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" axis="vertical" spacing="24" translatesAutoresizingMaskIntoConstraints="NO" id="6Df-q8-WGI">
+ <rect key="frame" x="24" y="241.5" width="327" height="204"/>
+ <subviews>
+ <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Splash.png" translatesAutoresizingMaskIntoConstraints="NO" id="8jW-MS-8v7">
+ <rect key="frame" x="0.0" y="0.0" width="327" height="96"/>
+ </imageView>
+ <textField opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="251" verticalCompressionResistancePriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="BMn-5D-Cqa">
+ <rect key="frame" x="0.0" y="120" width="327" height="30"/>
+ <nil key="textColor"/>
+ <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
+ <textInputTraits key="textInputTraits" textContentType="username"/>
+ <userDefinedRuntimeAttributes>
+ <userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="Username..."/>
+ </userDefinedRuntimeAttributes>
+ <connections>
+ <action selector="usernameChanged:" destination="4g9-hM-bzq" eventType="editingChanged" id="qst-Yi-KZ6"/>
+ </connections>
+ </textField>
+ <textField opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="251" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" adjustsFontForContentSizeCategory="YES" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="xGs-fu-6K0">
+ <rect key="frame" x="0.0" y="174" width="327" height="30"/>
+ <nil key="textColor"/>
+ <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
+ <textInputTraits key="textInputTraits" secureTextEntry="YES" textContentType="password"/>
+ <userDefinedRuntimeAttributes>
+ <userDefinedRuntimeAttribute type="string" keyPath="placeholder" value="Password..."/>
+ </userDefinedRuntimeAttributes>
+ <connections>
+ <action selector="passwordChanged:" destination="4g9-hM-bzq" eventType="editingChanged" id="Td0-2L-Dgo"/>
+ </connections>
+ </textField>
+ </subviews>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+ </stackView>
+ </subviews>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+ <constraints>
+ <constraint firstItem="6Df-q8-WGI" firstAttribute="centerY" secondItem="fue-ZI-ech" secondAttribute="centerY" id="X8s-fD-pQO"/>
+ <constraint firstItem="fue-ZI-ech" firstAttribute="trailing" secondItem="6Df-q8-WGI" secondAttribute="trailing" constant="24" id="glk-2k-XYf"/>
+ <constraint firstItem="6Df-q8-WGI" firstAttribute="leading" secondItem="fue-ZI-ech" secondAttribute="leading" constant="24" id="pcb-PF-amx"/>
+ </constraints>
+ <viewLayoutGuide key="safeArea" id="fue-ZI-ech"/>
+ </view>
+ <navigationItem key="navigationItem" id="QaM-45-gms"/>
+ <connections>
+ <outlet property="passwordField" destination="xGs-fu-6K0" id="zY6-lx-9PQ"/>
+ <outlet property="usernameField" destination="BMn-5D-Cqa" id="DQU-Fb-Q4e"/>
+ </connections>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="3yb-xh-Hei" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="-1159.5" y="662.5"/>
+ </scene>
<!--Profile-->
<scene sceneID="pZT-hd-B6F">
<objects>
@@ -227,6 +287,7 @@
</scene>
</scenes>
<resources>
+ <image name="Splash.png" width="96" height="96"/>
<image name="chats_icon" width="20" height="22"/>
<image name="profile_icon" width="16" height="20"/>
</resources>
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 <UIKit/UIKit.h>
-#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 @@
<rect key="frame" x="6" y="6" width="592" height="75"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" verticalCompressionResistancePriority="248" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Swn-59-jWb">
- <rect key="frame" x="0.0" y="0.0" width="592" height="32.5"/>
+ <rect key="frame" x="0.0" y="0.0" width="592" height="31"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" verticalCompressionResistancePriority="749" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="e2q-59-qlo">
- <rect key="frame" x="0.0" y="38.5" width="592" height="36.5"/>
+ <rect key="frame" x="0.0" y="37" width="592" height="38"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="infoLight" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ZXm-ce-xjB">
- <rect key="frame" x="0.0" y="0.0" width="44" height="36.5"/>
+ <rect key="frame" x="0.0" y="0.0" width="44" height="38"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="chf-2p-LxF"/>
</constraints>
</button>
<textView multipleTouchEnabled="YES" contentMode="scaleToFill" horizontalHuggingPriority="252" horizontalCompressionResistancePriority="749" scrollEnabled="NO" keyboardDismissMode="interactive" textAlignment="natural" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="alc-Oi-DBv">
- <rect key="frame" x="56" y="0.0" width="480" height="36.5"/>
+ <rect key="frame" x="56" y="0.0" width="480" height="38"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
@@ -50,7 +50,7 @@
</userDefinedRuntimeAttributes>
</textView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="9h3-lP-1PC">
- <rect key="frame" x="548" y="0.0" width="44" height="36.5"/>
+ <rect key="frame" x="548" y="0.0" width="44" height="38"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="QvX-xP-ypC"/>
</constraints>