Skip to content

Commit

Permalink
comment feature update
Browse files Browse the repository at this point in the history
  • Loading branch information
daneozxy committed Feb 26, 2015
1 parent 3a46b87 commit 2151ac4
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
10 changes: 10 additions & 0 deletions unnamed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
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 */; };
E22436071A9F01A800DE9280 /* CommentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E22436051A9F01A800DE9280 /* CommentCell.m */; };
E22436081A9F01A800DE9280 /* CommentCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E22436061A9F01A800DE9280 /* CommentCell.xib */; };
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 @@ -171,6 +173,9 @@
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>"; };
E22436041A9F01A800DE9280 /* CommentCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommentCell.h; sourceTree = "<group>"; };
E22436051A9F01A800DE9280 /* CommentCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentCell.m; sourceTree = "<group>"; };
E22436061A9F01A800DE9280 /* CommentCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CommentCell.xib; 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 @@ -350,6 +355,9 @@
B895C4AC1A9D6516001DF829 /* PhotoAnswerCell.h */,
B895C4AD1A9D6516001DF829 /* PhotoAnswerCell.m */,
B895C4AE1A9D6516001DF829 /* PhotoAnswerCell.xib */,
E22436041A9F01A800DE9280 /* CommentCell.h */,
E22436051A9F01A800DE9280 /* CommentCell.m */,
E22436061A9F01A800DE9280 /* CommentCell.xib */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -487,6 +495,7 @@
3E2BB7E11A94FF0000E78B3A /* AppNavigationController.xib in Resources */,
E2C6FF1F1A96C178005AEDA9 /* ProfileCell.xib in Resources */,
B8C291C31A930BDD000F2143 /* LaunchScreen.xib in Resources */,
E22436081A9F01A800DE9280 /* CommentCell.xib in Resources */,
3E58B4D61A984C3900AA14D4 /* AnswerView.xib in Resources */,
3E7C1D5A1A95AA520046FDE1 /* SurveyViewController.xib in Resources */,
B862A88D1A970E25008B2310 /* DetailAnswerCell.xib in Resources */,
Expand Down Expand Up @@ -583,6 +592,7 @@
B8C0DBDC1A95138C0023BC39 /* ComposeAnswerCell.m in Sources */,
B827A9E81A9815E100AB43CE /* ProfileImageView.m in Sources */,
B87C15BC1A93113400191823 /* LoginViewController.m in Sources */,
E22436071A9F01A800DE9280 /* CommentCell.m in Sources */,
B82956BC1A9C553200D0ECFD /* CameraViewController.m in Sources */,
B895C4AF1A9D6516001DF829 /* PhotoAnswerCell.m in Sources */,
B862A88C1A970E25008B2310 /* DetailAnswerCell.m in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions unnamed/CmtViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ - (void)onSubmitButton {
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) {
[ParseClient saveComment: comment withCompletion:^(NSError *error) {
if(error==nil){
NSLog(@"in CmtViewController: comment saved successfully!");
NSLog(@"CmtViewController: comment saved successfully!");
}else{
NSLog(@"Error happens while saving comment: %@", [error localizedDescription]);
NSLog(@"CmtViewController: comment saving failed - %@", [error localizedDescription]);
}
}];
}
Expand Down
4 changes: 2 additions & 2 deletions unnamed/CommentCell.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<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="6204"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand Down
2 changes: 2 additions & 0 deletions unnamed/CommentCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ - (void)setComments:(NSArray *)comments {
int count = 1;
for (int i=0;i<comments.count;i++) {
CommentView *view = [[CommentView alloc] init];
//fill in comment's content

count++;
[self.commentViews addObject:view];
[self addSubview:view];
Expand Down
4 changes: 4 additions & 0 deletions unnamed/CommentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
//

#import <UIKit/UIKit.h>
#import "Comment.h"


@interface CommentView : UIView

@property(nonatomic, strong) Comment *comment;

@end
15 changes: 6 additions & 9 deletions unnamed/CommentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "CommentView.h"
#import "User.h"

@interface CommentView ()
@property (strong, nonatomic) IBOutlet UIView *containerView;
Expand Down Expand Up @@ -55,15 +56,11 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
return self;
}

//- (void)setAnswer:(Answer *)answer {
// _answer = answer;
// self.answerLabel.text = [NSString stringWithFormat:@"%ld. %@", self.index, answer.text];
// CGFloat percentage = self.total <= 0 ? 0.0 : 1.0f * answer.count / self.total;
// self.percentLabel.text = [NSString stringWithFormat:@"%.1f%%", percentage * 100.0];
// self.barView.percent = percentage;
//
// [self setNeedsLayout];
//}
- (void)setComment:(Comment *)comment {
_comment = comment;
self.commentLabel.text = comment.text;
self.nameLabel.text = comment.user[@"profile"][@"name"];
}

- (void)layoutSubviews {
[super layoutSubviews];
Expand Down
2 changes: 1 addition & 1 deletion unnamed/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ extern NSInteger const ResultCount;
+ (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)saveComment:(Comment *)comment withCompletion:(void(^)(NSError *error))completion;
+ (void)getCommentsOnSurvey:(Survey *)survey withCompletion:(void(^)(NSArray *comments, NSError *error))completion;
@end
9 changes: 3 additions & 6 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,13 @@ + (void)saveVoteOnSurvey:(Survey *)survey withAnswer:(Answer *)answer withComple
}];
}

+ (void)saveCommentOnSurvey:(Survey *)survey withComment:(Comment *)comment withCompletion:(void(^)(Survey *survey, NSError *error))completion{
+ (void)saveComment:(Comment *)comment withCompletion:(void(^)(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);
completion(nil);
}else{
completion(nil, error);
completion(error);
}
}];
}
Expand All @@ -250,10 +249,8 @@ + (void)getCommentsOnSurvey:(Survey *)survey withCompletion:(void(^)(NSArray *co

[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);
}
}];
Expand Down
5 changes: 5 additions & 0 deletions unnamed/SurveyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#import "GrayBarButtonItem.h"
#import "UIColor+AppColor.h"
#import "CmtViewController.h"
#import "CommentCollectionView.h"


NSString * const AnswerCellNib = @"DetailAnswerCell";
NSString * const QuestionCellNib = @"DetailQuestionCell";
Expand All @@ -26,6 +28,7 @@ @interface SurveyViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, assign) NSInteger voteTotal;
@property (nonatomic, strong) DetailQuestionCell *prototypeQuestionCell;
@property (nonatomic, strong) DetailAnswerCell *prototypeAnswerCell;
@property (nonatomic, strong) NSArray * comments;

@end

Expand All @@ -48,7 +51,9 @@ - (void)viewDidLoad {

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

}

- (void)setSurvey:(Survey *)survey {
Expand Down

0 comments on commit 2151ac4

Please sign in to comment.