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 ad44520 commit 6ad6186
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 31 deletions.
7 changes: 3 additions & 4 deletions unnamed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@
B8C704A71A97065600243C3B /* DetailQuestionCell.h */,
B8C704A81A97065600243C3B /* DetailQuestionCell.m */,
B8C704A91A97065600243C3B /* DetailQuestionCell.xib */,
E253726F1A9F0CB20023C8C1 /* DetailCommentCell.h */,
E25372701A9F0CB20023C8C1 /* DetailCommentCell.m */,
E25372711A9F0CB20023C8C1 /* DetailCommentCell.xib */,
B862A8891A970E25008B2310 /* DetailAnswerCell.h */,
B862A88A1A970E25008B2310 /* DetailAnswerCell.m */,
B862A88B1A970E25008B2310 /* DetailAnswerCell.xib */,
Expand Down Expand Up @@ -363,9 +366,6 @@
3E3C84BE1A9DB7FD00A053CA /* DetailPhotoAnswerCell.h */,
3E3C84BF1A9DB7FD00A053CA /* DetailPhotoAnswerCell.m */,
3E3C84C01A9DB7FD00A053CA /* DetailPhotoAnswerCell.xib */,
E253726F1A9F0CB20023C8C1 /* DetailCommentCell.h */,
E25372701A9F0CB20023C8C1 /* DetailCommentCell.m */,
E25372711A9F0CB20023C8C1 /* DetailCommentCell.xib */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -602,7 +602,6 @@
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
7 changes: 7 additions & 0 deletions unnamed/CmtViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

#import <UIKit/UIKit.h>
#import "Survey.h"
@class CmtViewController;

@protocol CmtViewControllerDelegate <NSObject>
- (void)didPostComment:(CmtViewController *)vc;
@end

@interface CmtViewController : UIViewController
@property (nonatomic, strong) Survey *survey;
@property (nonatomic, weak) id<CmtViewControllerDelegate> delegate;

@end
13 changes: 9 additions & 4 deletions unnamed/CmtViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,28 @@ - (void)onSubmitButton {
self.isUpdating = YES;
if ([self.commentTextView.text length] >= 8 ) {
//Submit comment
NSLog(@"task: save comment to Parse");
//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);
NSLog(@"in CmtViewController: Comment.questionId is %@, comment user name is %@", comment.questionId, comment.user[@"profile"][@"name"]);
[ParseClient saveComment: comment withCompletion:^(NSError *error) {
if(error==nil){
NSLog(@"CmtViewController: comment saved successfully!");
NSLog(@"CmtViewController: comment saved successfully!");
[self.delegate didPostComment:self];
NSLog(@"CmtViewController: just posted a comment!");
[self.navigationController popViewControllerAnimated:YES];
}else{
NSLog(@"CmtViewController: comment saving failed - %@", [error localizedDescription]);
[[[UIAlertView alloc] initWithTitle:@"Comment Post Failed" message:@"Unable to post comment at this time. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
}];
}else{
self.isUpdating = NO;
}
}
}


@end
12 changes: 6 additions & 6 deletions unnamed/DetailAnswerCell.xib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" 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="6247"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
Expand All @@ -15,13 +15,13 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1." lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1Xh-Ul-rC5">
<rect key="frame" x="8" y="26" width="11" height="15"/>
<rect key="frame" x="8" y="26" width="10.5" height="14.5"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Some answer" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mLX-L2-SWI">
<rect key="frame" x="27" y="25" width="209" height="15"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" misplaced="YES" text="Some answer" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mLX-L2-SWI">
<rect key="frame" x="26" y="25" width="209.5" height="14.5"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand All @@ -35,14 +35,14 @@
</constraints>
</imageView>
<view alpha="0.29999999999999999" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="4ZA-wD-E7p" customClass="GRKBarGraphView">
<rect key="frame" x="23" y="17" width="249" height="33"/>
<rect key="frame" x="22" y="17" width="249.5" height="33"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="33" id="0c6-Wz-Dor"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="32%" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="diZ-94-6g0">
<rect key="frame" x="244" y="26" width="26" height="15"/>
<rect key="frame" x="244" y="26" width="26" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand Down
3 changes: 3 additions & 0 deletions unnamed/DetailCommentCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

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

@interface DetailCommentCell : UITableViewCell

- (void) initWithComment:(Comment *)comment;

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

#import "DetailCommentCell.h"
#import "ParseClient.h"
#import "User.h"

@interface DetailCommentCell()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *commentLabel;

@end

@implementation DetailCommentCell

Expand All @@ -20,4 +29,10 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
// Configure the view for the selected state
}

- (void)initWithComment:(Comment *)comment{
User *user = [[User alloc] initWithPFUser:comment.user];
self.nameLabel.text = user.name;
self.commentLabel.text = comment.text;
}

@end
44 changes: 40 additions & 4 deletions unnamed/DetailCommentCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,54 @@
<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"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="DetailCommentCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="69" id="KGk-i7-Jjw" customClass="DetailCommentCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="69"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<tableViewCellContentView key="contentView" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" red="0.80000001190000003" green="1" blue="0.40000000600000002" alpha="1" colorSpace="calibratedRGB"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="751" text="User Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="1JO-SV-o2s">
<rect key="frame" x="8" y="8" width="304" height="14.5"/>
<constraints>
<constraint firstAttribute="height" constant="14.5" id="2hB-cA-AVf"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
<exclude reference="2hB-cA-AVf"/>
</mask>
</variation>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalCompressionResistancePriority="751" text="Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Eze-v5-J5w">
<rect key="frame" x="8" y="30" width="304" height="22.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="bottomMargin" secondItem="Eze-v5-J5w" secondAttribute="bottom" constant="8" id="1ky-N2-TBs"/>
<constraint firstItem="1JO-SV-o2s" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="22e-fn-1Y7"/>
<constraint firstItem="1JO-SV-o2s" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="8" id="6jm-pr-OeC"/>
<constraint firstItem="Eze-v5-J5w" firstAttribute="top" secondItem="1JO-SV-o2s" secondAttribute="bottom" constant="8" id="97c-DH-yvG"/>
<constraint firstAttribute="trailing" secondItem="Eze-v5-J5w" secondAttribute="trailing" constant="8" id="MoB-aK-gW6"/>
<constraint firstAttribute="trailing" secondItem="1JO-SV-o2s" secondAttribute="trailing" constant="8" id="Wxy-b3-F6n"/>
<constraint firstItem="Eze-v5-J5w" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="u39-Po-FpV"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="commentLabel" destination="Eze-v5-J5w" id="pE3-p0-ypE"/>
<outlet property="nameLabel" destination="1JO-SV-o2s" id="oyS-Mt-Vbi"/>
</connections>
<point key="canvasLocation" x="59" y="124.5"/>
</tableViewCell>
</objects>
</document>
1 change: 1 addition & 0 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ + (void)getCommentsOnSurvey:(Survey *)survey withCompletion:(void(^)(NSArray *co

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

Expand Down
50 changes: 37 additions & 13 deletions unnamed/SurveyViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
NSString * const PhotoAnswerCellNib = @"DetailPhotoAnswerCell";
NSString * const CommentCellNib = @"DetailCommentCell";

@interface SurveyViewController () <UITableViewDataSource, UITableViewDelegate>
@interface SurveyViewController () <UITableViewDataSource, UITableViewDelegate, CmtViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *surveyContents;
@property (nonatomic, assign) NSInteger voteTotal;
@property (nonatomic, strong) DetailQuestionCell *prototypeQuestionCell;
@property (nonatomic, strong) DetailAnswerCell *prototypeAnswerCell;
@property (nonatomic, strong) DetailCommentCell *prototypeCommentCell;
@property (nonatomic, strong) NSMutableArray * comments;
@property (nonatomic, strong) DetailPhotoAnswerCell *prototypePhotoAnswerCell;
@property (nonatomic, strong) CmtViewController * cmtVC;

@end

Expand All @@ -54,19 +56,28 @@ - (void)viewDidLoad {
[self.tableView registerNib:[UINib nibWithNibName:PhotoAnswerCellNib bundle:nil] forCellReuseIdentifier:PhotoAnswerCellNib];
[self.tableView registerNib:[UINib nibWithNibName:CommentCellNib bundle:nil] forCellReuseIdentifier:CommentCellNib];
[self.tableView reloadData];

[self pullComments];
}

- (void)didPostComment:(CmtViewController *)vc{
NSLog(@"SurveyViewController: CmtViewController just posted a comment!");
[self pullComments];
}

- (void)pullComments{
[ParseClient getCommentsOnSurvey:_survey withCompletion:^(NSArray *comments, NSError *error) {
NSLog(@"pull comments from parse.");
if(comments!=nil){
self.comments = [NSMutableArray array];
[self.comments removeAllObjects];
[self.comments addObjectsFromArray:comments];
NSLog(@"Comments retrieval succeed! Get back %ld comments for current survey!", self.comments.count);
//NSLog(@"Comments retrieval succeed! Get back %ld comments for current survey!", self.comments.count);
[self.tableView reloadData];
}
else{
NSLog(@"Comments retrieval failed! Error is %@", [error localizedDescription]);
}
}];

}

- (void)setSurvey:(Survey *)survey {
Expand Down Expand Up @@ -107,21 +118,29 @@ - (DetailPhotoAnswerCell *)prototypePhotoAnswerCell {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0) return self.surveyContents.count;
else{
NSLog(@"section = 1 now!");
//NSLog(@"section = 1 now!");
return self.comments.count;
}
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if(self.comments.count!=0){
NSLog(@"table has 2 sections now");
//NSLog(@"table has 2 sections now");
return 2;
}
NSLog(@"table has 1 section now");
//NSLog(@"table has 1 section now");
return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 1){
[self configureCell:self.prototypeCommentCell forRowAtIndexPath:indexPath];
[self.prototypeCommentCell layoutIfNeeded];
CGSize size = [self.prototypeCommentCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
//NSLog(@"for comment, cell height is %f", size.height);
return 60;
//return size.height+1;
}
if ([self.surveyContents[indexPath.row] isKindOfClass:[Question class]]) {
[self configureCell:self.prototypeQuestionCell forRowAtIndexPath:indexPath];
[self.prototypeQuestionCell layoutIfNeeded];
Expand All @@ -145,6 +164,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 1){
DetailCommentCell * cell = [self.tableView dequeueReusableCellWithIdentifier:CommentCellNib];
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;
}
if ([self.surveyContents[indexPath.row] isKindOfClass:[Question class]]) {
Expand Down Expand Up @@ -178,12 +198,17 @@ - (void)configureCell:(UITableViewCell *)pCell forRowAtIndexPath:(NSIndexPath *)
Answer *answer = (Answer *)self.surveyContents[indexPath.row];
[cell initWithAnswer:answer totalVotes:self.survey.totalVotes];
cell.isCurrentVote = [self.survey isCurrentVoteAnswer:answer];
} else if ([pCell isKindOfClass:[DetailCommentCell class]]) {
DetailCommentCell *cell = (DetailCommentCell *)pCell;
Comment * comment =self.comments[indexPath.row];
[cell initWithComment:comment];
}
pCell.backgroundColor = [UIColor appBgColor];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.section == 1) return;

Answer *newAnswer = self.surveyContents[indexPath.row];
if (!self.survey.voted || self.survey.vote.answerIndex != newAnswer.index) {
Expand All @@ -205,11 +230,10 @@ - (UIImageView *)getMainProfileImageView {
}

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

self.cmtVC = [[CmtViewController alloc] init];
self.cmtVC.delegate =self;
self.cmtVC.view.frame = self.view.frame;
self.cmtVC.survey = _survey;
[self.navigationController pushViewController:self.cmtVC animated:YES];
}

@end

0 comments on commit 6ad6186

Please sign in to comment.