-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
daneozxy
committed
Feb 26, 2015
1 parent
35f8883
commit ed486fa
Showing
9 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CmtViewController.h | ||
// unnamed | ||
// | ||
// Created by Xiangyu Zhang on 2/25/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "Survey.h" | ||
|
||
@interface CmtViewController : UIViewController | ||
@property (nonatomic, strong) Survey *survey; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// CmtViewController.m | ||
// unnamed | ||
// | ||
// Created by Xiangyu Zhang on 2/25/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import "CmtViewController.h" | ||
#import "UIColor+AppColor.h" | ||
#import "GrayBarButtonItem.h" | ||
#import "Comment.h" | ||
#import "ParseClient.h" | ||
|
||
NSInteger const maxCommentCount = 160; | ||
NSString * const WriteAComment = @"Leave a comment here . . ."; | ||
|
||
@interface CmtViewController ()<UITextViewDelegate> | ||
@property (weak, nonatomic) IBOutlet UILabel *instructionLabel; | ||
@property (weak, nonatomic) IBOutlet UITextView *commentTextView; | ||
@property (weak, nonatomic) IBOutlet UILabel *commentCountLabel; | ||
@property (nonatomic, assign) BOOL isUpdating; | ||
|
||
@end | ||
|
||
@implementation CmtViewController | ||
|
||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | ||
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | ||
if (self) { | ||
self.title = @"Comment"; | ||
} | ||
self.view.backgroundColor = [UIColor appBgColor]; | ||
return self; | ||
} | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Setup Comment Text Field | ||
self.commentTextView.layer.cornerRadius = 10; | ||
self.commentTextView.layer.masksToBounds = YES; | ||
// Button | ||
GrayBarButtonItem *submitButton = [[GrayBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStylePlain target:self action:@selector(onSubmitButton)]; | ||
self.navigationItem.rightBarButtonItem = submitButton; | ||
|
||
// Instruction | ||
self.instructionLabel.text = WriteAComment; | ||
self.commentCountLabel.text = [NSString stringWithFormat:@"%ld",(long)maxCommentCount]; | ||
|
||
// textview delegate | ||
self.commentTextView.delegate = self; | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
- (void)setSurvey:(Survey *)survey { | ||
_survey = survey; | ||
} | ||
|
||
- (void) textViewDidChange:(UITextView *)textView{ | ||
NSInteger count = maxCommentCount - [self.commentTextView.text length]; | ||
// SEt the counter to count; | ||
if (count <= 0) { | ||
//Stop text entry | ||
self.commentTextView.text = [self.commentTextView.text substringToIndex:maxCommentCount]; | ||
count = 0; | ||
} | ||
self.commentCountLabel.text = [NSString stringWithFormat:@"%ld",(long)count]; | ||
} | ||
/* | ||
#pragma mark - Navigation | ||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
// Get the new view controller using [segue destinationViewController]. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
- (void)onSubmitButton { | ||
if (!self.isUpdating) { | ||
self.isUpdating = YES; | ||
if ([self.commentTextView.text length] >= 8 ) { | ||
//Submit comment | ||
NSLog(@"task: save comment to Parse"); | ||
//construct a comment here... | ||
Comment * comment = [[Comment alloc] init]; | ||
comment.text = self.commentTextView.text; | ||
comment.user = [PFUser currentUser]; | ||
comment.questionId = _survey.question.objectId; | ||
NSLog(@"in CmtViewController: Comment.questionId is %@", comment.questionId); | ||
[ParseClient saveCommentOnSurvey:_survey withComment:comment withCompletion:^(Survey *survey, NSError *error) { | ||
if(error==nil){ | ||
NSLog(@"in CmtViewController: comment saved successfully!"); | ||
}else{ | ||
NSLog(@"Error happens while saving comment: %@", [error localizedDescription]); | ||
} | ||
}]; | ||
} | ||
} | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CmtViewController"> | ||
<connections> | ||
<outlet property="commentCountLabel" destination="TO5-NM-zW9" id="07g-qA-HAJ"/> | ||
<outlet property="commentTextView" destination="rKw-oT-20c" id="nYl-RN-G5I"/> | ||
<outlet property="instructionLabel" destination="A2P-xe-OQs" id="hJE-5o-gSc"/> | ||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | ||
</connections> | ||
</placeholder> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A2P-xe-OQs"> | ||
<rect key="frame" x="8" y="8" width="584" height="20.5"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rKw-oT-20c"> | ||
<rect key="frame" x="8" y="36.5" width="584" height="100"/> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstAttribute="height" constant="100" id="LkZ-BU-gat"/> | ||
</constraints> | ||
<fontDescription key="fontDescription" type="system" pointSize="14"/> | ||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> | ||
</textView> | ||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TO5-NM-zW9"> | ||
<rect key="frame" x="542" y="108" width="42" height="20.5"/> | ||
<fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/> | ||
<nil key="highlightedColor"/> | ||
</label> | ||
</subviews> | ||
<color key="backgroundColor" name="selectedControlColor" catalog="System" colorSpace="catalog"/> | ||
<constraints> | ||
<constraint firstAttribute="trailing" secondItem="A2P-xe-OQs" secondAttribute="trailing" constant="8" id="Bfh-zW-xp9"/> | ||
<constraint firstAttribute="trailing" secondItem="rKw-oT-20c" secondAttribute="trailing" constant="8" id="Dez-d4-7Sj"/> | ||
<constraint firstItem="rKw-oT-20c" firstAttribute="top" secondItem="A2P-xe-OQs" secondAttribute="bottom" constant="8" id="FHJ-Iw-iSB"/> | ||
<constraint firstItem="rKw-oT-20c" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="KIK-Hu-Nsg"/> | ||
<constraint firstItem="A2P-xe-OQs" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="8" id="aBi-DF-TOv"/> | ||
<constraint firstItem="rKw-oT-20c" firstAttribute="top" secondItem="A2P-xe-OQs" secondAttribute="bottom" constant="8" id="czk-PU-fCo"/> | ||
<constraint firstAttribute="trailing" secondItem="TO5-NM-zW9" secondAttribute="trailing" constant="16" id="k48-fa-h7U"/> | ||
<constraint firstItem="rKw-oT-20c" firstAttribute="bottom" secondItem="TO5-NM-zW9" secondAttribute="bottom" constant="8" id="smR-Hp-p1T"/> | ||
<constraint firstItem="A2P-xe-OQs" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="8" id="zoF-Oy-ktH"/> | ||
</constraints> | ||
<variation key="default"> | ||
<mask key="constraints"> | ||
<exclude reference="czk-PU-fCo"/> | ||
</mask> | ||
</variation> | ||
</view> | ||
</objects> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Comment.h | ||
// unnamed | ||
// | ||
// Created by Xiangyu Zhang on 2/25/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import <Parse/Parse.h> | ||
#import <Parse/PFObject+Subclass.h> | ||
#import "Question.h" | ||
|
||
|
||
@interface Comment : PFObject<PFSubclassing> | ||
|
||
+ (NSString *)parseClassName; | ||
@property (nonatomic, strong) PFUser *user; | ||
@property (nonatomic, strong) NSString *objectId; | ||
@property (nonatomic, strong) NSString *questionId; | ||
@property (nonatomic, strong) NSString *text; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Comment.m | ||
// unnamed | ||
// | ||
// Created by Xiangyu Zhang on 2/25/15. | ||
// Copyright (c) 2015 com.yahoo. All rights reserved. | ||
// | ||
|
||
#import "Comment.h" | ||
|
||
@implementation Comment | ||
@dynamic objectId; | ||
@dynamic user; | ||
@dynamic questionId; | ||
@dynamic text; | ||
|
||
+ (void)load { | ||
[self registerSubclass]; | ||
} | ||
|
||
+ (NSString *)parseClassName { | ||
return @"Comment"; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters