Skip to content

Commit

Permalink
setting up comment frame
Browse files Browse the repository at this point in the history
  • Loading branch information
daneozxy committed Feb 26, 2015
1 parent 35f8883 commit ed486fa
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 0 deletions.
16 changes: 16 additions & 0 deletions unnamed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
B8C291CF1A930BDD000F2143 /* unnamedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8C291CE1A930BDD000F2143 /* unnamedTests.m */; };
B8C704AA1A97065600243C3B /* DetailQuestionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B8C704A81A97065600243C3B /* DetailQuestionCell.m */; };
B8C704AB1A97065600243C3B /* DetailQuestionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B8C704A91A97065600243C3B /* DetailQuestionCell.xib */; };
E22435FA1A9EE42E00DE9280 /* CmtViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E22435F81A9EE42E00DE9280 /* CmtViewController.m */; };
E22435FB1A9EE42E00DE9280 /* CmtViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E22435F91A9EE42E00DE9280 /* CmtViewController.xib */; };
E22435FE1A9EE69700DE9280 /* Comment.m in Sources */ = {isa = PBXBuildFile; fileRef = E22435FD1A9EE69700DE9280 /* Comment.m */; };
E25DBF0B1A948D870074D48B /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E25DBF091A948D870074D48B /* ProfileViewController.m */; };
E25DBF0C1A948D870074D48B /* ProfileViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E25DBF0A1A948D870074D48B /* ProfileViewController.xib */; };
E2C6FF1E1A96C178005AEDA9 /* ProfileCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E2C6FF1C1A96C178005AEDA9 /* ProfileCell.m */; };
Expand Down Expand Up @@ -163,6 +166,11 @@
B8C704A71A97065600243C3B /* DetailQuestionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailQuestionCell.h; sourceTree = "<group>"; };
B8C704A81A97065600243C3B /* DetailQuestionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailQuestionCell.m; sourceTree = "<group>"; };
B8C704A91A97065600243C3B /* DetailQuestionCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailQuestionCell.xib; sourceTree = "<group>"; };
E22435F71A9EE42E00DE9280 /* CmtViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CmtViewController.h; sourceTree = "<group>"; };
E22435F81A9EE42E00DE9280 /* CmtViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CmtViewController.m; sourceTree = "<group>"; };
E22435F91A9EE42E00DE9280 /* CmtViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CmtViewController.xib; sourceTree = "<group>"; };
E22435FC1A9EE69700DE9280 /* Comment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Comment.h; sourceTree = "<group>"; };
E22435FD1A9EE69700DE9280 /* Comment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Comment.m; sourceTree = "<group>"; };
E25DBF081A948D870074D48B /* ProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProfileViewController.h; sourceTree = "<group>"; };
E25DBF091A948D870074D48B /* ProfileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileViewController.m; sourceTree = "<group>"; };
E25DBF0A1A948D870074D48B /* ProfileViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ProfileViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -205,6 +213,8 @@
B8C0DBEE1A95C15B0023BC39 /* Parse */ = {
isa = PBXGroup;
children = (
E22435FC1A9EE69700DE9280 /* Comment.h */,
E22435FD1A9EE69700DE9280 /* Comment.m */,
B8C0DBF21A95C2D60023BC39 /* ParseClient.h */,
B8C0DBF31A95C2D60023BC39 /* ParseClient.m */,
B8BA93E91A9464C7003BD476 /* Question.h */,
Expand Down Expand Up @@ -365,6 +375,9 @@
B82956B91A9C553200D0ECFD /* CameraViewController.h */,
B82956BA1A9C553200D0ECFD /* CameraViewController.m */,
B82956BB1A9C553200D0ECFD /* CameraViewController.xib */,
E22435F71A9EE42E00DE9280 /* CmtViewController.h */,
E22435F81A9EE42E00DE9280 /* CmtViewController.m */,
E22435F91A9EE42E00DE9280 /* CmtViewController.xib */,
);
name = Control;
sourceTree = "<group>";
Expand Down Expand Up @@ -481,6 +494,7 @@
B895C4B01A9D6516001DF829 /* PhotoAnswerCell.xib in Resources */,
B87C15BD1A93113400191823 /* LoginViewController.xib in Resources */,
B8C0DBDD1A95138C0023BC39 /* ComposeAnswerCell.xib in Resources */,
E22435FB1A9EE42E00DE9280 /* CmtViewController.xib in Resources */,
B895C4A51A9CD9D4001DF829 /* PhotoAnswerView.xib in Resources */,
3E58B4CC1A98229200AA14D4 /* SurveyViewCell.xib in Resources */,
B8C0DBCE1A94F71A0023BC39 /* ComposeViewController.xib in Resources */,
Expand Down Expand Up @@ -541,8 +555,10 @@
B82956C61A9C5AA200D0ECFD /* ComposePhotoCell.m in Sources */,
B895C4A01A9C7709001DF829 /* QuestionPhotos.m in Sources */,
B8BA93E81A9459B5003BD476 /* User.m in Sources */,
E22435FA1A9EE42E00DE9280 /* CmtViewController.m in Sources */,
B8C0DBF11A95C1DA0023BC39 /* Survey.m in Sources */,
B895C4AB1A9D5BC9001DF829 /* UIImageView+Parse.m in Sources */,
E22435FE1A9EE69700DE9280 /* Comment.m in Sources */,
B81A2F161A9AC409001F2C6D /* GraphData.m in Sources */,
3E58B4D41A9832BF00AA14D4 /* AnswerView.m in Sources */,
3E58B4CB1A98229200AA14D4 /* SurveyViewCell.m in Sources */,
Expand Down
14 changes: 14 additions & 0 deletions unnamed/CmtViewController.h
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
106 changes: 106 additions & 0 deletions unnamed/CmtViewController.m
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
61 changes: 61 additions & 0 deletions unnamed/CmtViewController.xib
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>
22 changes: 22 additions & 0 deletions unnamed/Comment.h
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
25 changes: 25 additions & 0 deletions unnamed/Comment.m
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
4 changes: 4 additions & 0 deletions unnamed/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "Vote.h"
#import "Answer.h"
#import "User.h"
#import "Comment.h"

extern NSString * const UserDidPostNewSurveyNotification;
extern NSString * const UserDidPostUpdateSurveyNotification;
Expand All @@ -25,4 +26,7 @@ extern NSInteger const ResultCount;
+ (void)savePhotoSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded, NSError *error))completion;
+ (void)saveVoteOnSurvey:(Survey *)survey withAnswer:(Answer *)answer withCompletion:(void(^)(Survey *survey, NSError *error))completion;
+ (void)setImageView:(UIImageView *)iView fromAnswer:(Answer *)answer;

+ (void)saveCommentOnSurvey:(Survey *)survey withComment:(Comment *)comment withCompletion:(void(^)(Survey *survey, NSError *error))completion;
+ (void)getCommentsOnSurvey:(Survey *)survey withCompletion:(void(^)(NSArray *comments, NSError *error))completion;
@end
32 changes: 32 additions & 0 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ + (void)saveVoteOnSurvey:(Survey *)survey withAnswer:(Answer *)answer withComple
}];
}

+ (void)saveCommentOnSurvey:(Survey *)survey withComment:(Comment *)comment withCompletion:(void(^)(Survey *survey, NSError *error))completion{
//comment already set up
[comment saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error){
NSLog(@"Comment saved successfully! Comment.questionId is %@", comment.questionId);
completion(survey, nil);
}else{
completion(nil, error);
}
}];
}

+ (void)getCommentsOnSurvey:(Survey *)survey withCompletion:(void(^)(NSArray *comments, NSError *error))completion{

PFQuery *query = [Comment query];
[query orderByDescending:@"createdAt"];
[query whereKey:@"questionId" equalTo:survey.question.objectId];
//adding to code to select pages to load results from...

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"get comments succeed! totally %ld comments retrieved.", objects.count);
completion(objects, nil);
} else {
NSLog(@"comments retrieving failed! error is %@", [error localizedDescription]);
completion(nil, error);
}
}];


}

+ (void)updateVoteCountOnSurvey:(Survey *)survey oldAnswerIndex:(NSInteger)oldIndex newVote:(Vote *)vote withCompletion:(void(^)(Survey *survey, NSError *error))completion{
NSMutableArray *newCounts = [NSMutableArray arrayWithArray:survey.question.answerVoteCounts];

Expand Down
17 changes: 17 additions & 0 deletions unnamed/SurveyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#import "DetailQuestionCell.h"
#import "DetailAnswerCell.h"
#import "ParseClient.h"
#import "GrayBarButtonItem.h"
#import "UIColor+AppColor.h"
#import "CmtViewController.h"

NSString * const AnswerCellNib = @"DetailAnswerCell";
NSString * const QuestionCellNib = @"DetailQuestionCell";
Expand All @@ -31,6 +33,10 @@ @implementation SurveyViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor appBgColor];

//comment button
GrayBarButtonItem *commentButton = [[GrayBarButtonItem alloc] initWithTitle:@"Comment" style:UIBarButtonItemStylePlain target:self action:@selector(onCommentButton)];
self.navigationItem.rightBarButtonItem = commentButton;

// Do any additional setup after loading the view from its nib.
self.tableView.dataSource = self;
Expand All @@ -39,6 +45,10 @@ - (void)viewDidLoad {
[self.tableView registerNib:[UINib nibWithNibName:QuestionCellNib bundle:nil] forCellReuseIdentifier:QuestionCellNib];

[self.tableView reloadData];

[ParseClient getCommentsOnSurvey:_survey withCompletion:^(NSArray *comments, NSError *error) {
NSLog(@"just tried to get comments for this survey!");
}];
}

- (void)setSurvey:(Survey *)survey {
Expand Down Expand Up @@ -134,5 +144,12 @@ - (UIImageView *)getMainProfileImageView {
return cell.profileImageView;
}

- (void) onCommentButton{
CmtViewController *vc = [[CmtViewController alloc] init];
vc.view.frame = self.view.frame;
vc.survey = _survey;
[self.navigationController pushViewController:vc animated:YES];

}

@end

0 comments on commit ed486fa

Please sign in to comment.