Skip to content

Commit

Permalink
Add Comment View to SurveyViewCell
Browse files Browse the repository at this point in the history
  • Loading branch information
casing committed Feb 24, 2015
1 parent 830082a commit c88b2ba
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 11 deletions.
16 changes: 16 additions & 0 deletions unnamed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
3E2BB7E01A94FF0000E78B3A /* AppNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2BB7DE1A94FF0000E78B3A /* AppNavigationController.m */; };
3E2BB7E11A94FF0000E78B3A /* AppNavigationController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E2BB7DF1A94FF0000E78B3A /* AppNavigationController.xib */; };
3E4B809D1A9C41CF004F5D78 /* CommentCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E4B809C1A9C41CF004F5D78 /* CommentCollectionView.m */; };
3E4B80A01A9C42FB004F5D78 /* CommentView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E4B809F1A9C42FB004F5D78 /* CommentView.m */; };
3E4B80A21A9C4345004F5D78 /* CommentView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E4B80A11A9C4345004F5D78 /* CommentView.xib */; };
3E58B4CB1A98229200AA14D4 /* SurveyViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E58B4C91A98229200AA14D4 /* SurveyViewCell.m */; };
3E58B4CC1A98229200AA14D4 /* SurveyViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3E58B4CA1A98229200AA14D4 /* SurveyViewCell.xib */; };
3E58B4CF1A98300C00AA14D4 /* AnswerCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E58B4CE1A98300C00AA14D4 /* AnswerCollectionView.m */; };
Expand Down Expand Up @@ -67,6 +70,11 @@
3E2BB7DD1A94FF0000E78B3A /* AppNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppNavigationController.h; sourceTree = "<group>"; };
3E2BB7DE1A94FF0000E78B3A /* AppNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppNavigationController.m; sourceTree = "<group>"; };
3E2BB7DF1A94FF0000E78B3A /* AppNavigationController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AppNavigationController.xib; sourceTree = "<group>"; };
3E4B809B1A9C41CF004F5D78 /* CommentCollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommentCollectionView.h; sourceTree = "<group>"; };
3E4B809C1A9C41CF004F5D78 /* CommentCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentCollectionView.m; sourceTree = "<group>"; };
3E4B809E1A9C42FB004F5D78 /* CommentView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommentView.h; sourceTree = "<group>"; };
3E4B809F1A9C42FB004F5D78 /* CommentView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommentView.m; sourceTree = "<group>"; };
3E4B80A11A9C4345004F5D78 /* CommentView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CommentView.xib; sourceTree = "<group>"; };
3E58B4C81A98229200AA14D4 /* SurveyViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SurveyViewCell.h; sourceTree = "<group>"; };
3E58B4C91A98229200AA14D4 /* SurveyViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SurveyViewCell.m; sourceTree = "<group>"; };
3E58B4CA1A98229200AA14D4 /* SurveyViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SurveyViewCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -288,6 +296,11 @@
3E58B4D21A9832BF00AA14D4 /* AnswerView.h */,
3E58B4D31A9832BF00AA14D4 /* AnswerView.m */,
3E58B4D51A984C3900AA14D4 /* AnswerView.xib */,
3E4B809B1A9C41CF004F5D78 /* CommentCollectionView.h */,
3E4B809C1A9C41CF004F5D78 /* CommentCollectionView.m */,
3E4B809E1A9C42FB004F5D78 /* CommentView.h */,
3E4B809F1A9C42FB004F5D78 /* CommentView.m */,
3E4B80A11A9C4345004F5D78 /* CommentView.xib */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -430,6 +443,7 @@
B8C0DBDD1A95138C0023BC39 /* ComposeAnswerCell.xib in Resources */,
3E58B4CC1A98229200AA14D4 /* SurveyViewCell.xib in Resources */,
B8C0DBCE1A94F71A0023BC39 /* ComposeViewController.xib in Resources */,
3E4B80A21A9C4345004F5D78 /* CommentView.xib in Resources */,
3E7C1D501A958BC10046FDE1 /* HomeViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -487,6 +501,7 @@
B81A2F161A9AC409001F2C6D /* GraphData.m in Sources */,
3E58B4D41A9832BF00AA14D4 /* AnswerView.m in Sources */,
3E58B4CB1A98229200AA14D4 /* SurveyViewCell.m in Sources */,
3E4B809D1A9C41CF004F5D78 /* CommentCollectionView.m in Sources */,
B8C704AA1A97065600243C3B /* DetailQuestionCell.m in Sources */,
3E2BB7E01A94FF0000E78B3A /* AppNavigationController.m in Sources */,
B8BA93F41A947718003BD476 /* Answer.m in Sources */,
Expand All @@ -502,6 +517,7 @@
3EC3AEE11A9AB22100E0DCCB /* UIColor+AppColor.m in Sources */,
E25DBF061A9489530074D48B /* TabBarMenuViewController.m in Sources */,
B827A9EE1A98287B00AB43CE /* GrayBarButtonItem.m in Sources */,
3E4B80A01A9C42FB004F5D78 /* CommentView.m in Sources */,
B8C0DBDC1A95138C0023BC39 /* ComposeAnswerCell.m in Sources */,
B827A9E81A9815E100AB43CE /* ProfileImageView.m in Sources */,
B87C15BC1A93113400191823 /* LoginViewController.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion unnamed/AnswerView.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">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
Expand Down
13 changes: 13 additions & 0 deletions unnamed/CommentCollectionView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CommentCollectionView.h
// unnamed
//
// Created by Casing Chu on 2/23/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CommentCollectionView : UIView
- (void)setComments:(NSArray *)comments;
@end
90 changes: 90 additions & 0 deletions unnamed/CommentCollectionView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// CommentCollectionView.m
// unnamed
//
// Created by Casing Chu on 2/23/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import "CommentCollectionView.h"
#import "CommentView.h"

@interface CommentCollectionView ()

@property (nonatomic, strong) NSArray *comments;
@property (nonatomic, strong) NSMutableArray *commentViews;
@property (nonatomic, assign) CGFloat commentHeight;

@end

@implementation CommentCollectionView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

- (void)setup {
self.commentViews = [[NSMutableArray alloc] init];
self.commentHeight = 20.0;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self setup];
}
return self;
}

- (void)setComments:(NSArray *)comments {
_comments = comments;

for (CommentView *view in self.commentViews) {
[view removeFromSuperview];
}
[self.commentViews removeAllObjects];

int count = 1;
for (int i=0;i<comments.count;i++) {
CommentView *view = [[CommentView alloc] init];
count++;
[self.commentViews addObject:view];
[self addSubview:view];
}

[self setNeedsLayout];
}

- (void)layoutSubviews {
[super layoutSubviews];

int verticalOffset = 16;
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width,
self.commentHeight * self.commentViews.count +
(self.commentViews.count > 0 ? verticalOffset * 2 : 0));
for (int i=0;i<self.commentViews.count;i++) {
CommentView *view = self.commentViews[i];
// NSLog(@"Height: %f, Width: %f", view.frame.size.height, view.frame.size.width);
// NSLog(@"Height: %f, Width: %f", self.frame.size.height, self.frame.size.width);
CGFloat y = self.commentHeight * i + verticalOffset;
// NSLog(@"y pos: %f", y);
CGRect imageFrame = CGRectMake(0, y, self.frame.size.width, self.commentHeight);
view.frame = imageFrame;
}

}


@end
13 changes: 13 additions & 0 deletions unnamed/CommentView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CommentView.h
// unnamed
//
// Created by Casing Chu on 2/23/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CommentView : UIView

@end
75 changes: 75 additions & 0 deletions unnamed/CommentView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// CommentView.m
// unnamed
//
// Created by Casing Chu on 2/23/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//

#import "CommentView.h"

@interface CommentView ()
@property (strong, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *commentLabel;

@end

@implementation CommentView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

- (void)setup {
UINib *nib = [UINib nibWithNibName:@"CommentView" bundle:nil];
NSArray *objects = [nib instantiateWithOwner:self options:nil];
// NSLog(@"Nib Objects Count: %ld", objects.count);
// NSLog(@"Height: %f, Width: %f", self.containerView.frame.size.height, self.containerView.frame.size.width);

// Setup ContainerView
self.containerView.frame = self.bounds;
[self.containerView setTranslatesAutoresizingMaskIntoConstraints:YES];
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:self.containerView];
[self setNeedsLayout];
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self setup];
}
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)layoutSubviews {
[super layoutSubviews];

self.containerView.frame = self.bounds;

}

@end
49 changes: 49 additions & 0 deletions unnamed/CommentView.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CommentView">
<connections>
<outlet property="commentLabel" destination="rbV-9S-w5h" id="piN-Ka-LB5"/>
<outlet property="containerView" destination="iN0-l3-epB" id="91h-hV-zKQ"/>
<outlet property="nameLabel" destination="2Wv-f4-URV" id="NrW-R7-iQn"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="499" height="20"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Casing Chu" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Wv-f4-URV">
<rect key="frame" x="7" y="3" width="66" height="15"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="What is up with this question?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rbV-9S-w5h">
<rect key="frame" x="81" y="3" width="168" height="15"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerY" secondItem="2Wv-f4-URV" secondAttribute="centerY" id="APH-J2-chS"/>
<constraint firstItem="2Wv-f4-URV" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="8" id="Vh9-hV-VgE"/>
<constraint firstAttribute="centerY" secondItem="rbV-9S-w5h" secondAttribute="centerY" id="mju-4i-VYO"/>
<constraint firstItem="rbV-9S-w5h" firstAttribute="leading" secondItem="2Wv-f4-URV" secondAttribute="trailing" constant="8" id="mvF-xE-wrp"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="rbV-9S-w5h" secondAttribute="trailing" constant="8" id="qeT-Se-FsS"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="403.5" y="157"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
6 changes: 6 additions & 0 deletions unnamed/ComposeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ - (ComposeAnswerCell *)prototypeCell {
- (void)viewDidLoad {
[super viewDidLoad];
self.isUpdating = NO;
// Setup Question Text Field
self.questionText.layer.cornerRadius = 10;
self.questionText.layer.masksToBounds = YES;

// Button
GrayBarButtonItem *cancelButton = [[GrayBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(onCancelButton)];
self.navigationItem.leftBarButtonItem = cancelButton;
Expand Down Expand Up @@ -109,6 +113,8 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UILabel *footer = [[UILabel alloc] init];
footer.layer.cornerRadius = 10;
footer.layer.masksToBounds = YES;
footer.contentMode = UIViewContentModeCenter;
footer.textAlignment = NSTextAlignmentCenter;
footer.textColor = [UIColor lightGrayColor];
Expand Down
3 changes: 3 additions & 0 deletions unnamed/SurveyViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SurveyViewCell.h"
#import "ProfileImageView.h"
#import "AnswerCollectionView.h"
#import "CommentCollectionView.h"
#import "UIColor+AppColor.h"
#import "NSDate+MinimalTimeAgo.h"

Expand All @@ -19,6 +20,7 @@ @interface SurveyViewCell () <ProfileImageViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) IBOutlet AnswerCollectionView *answerCollectionView;
@property (weak, nonatomic) IBOutlet CommentCollectionView *commentCollectionView;

@end

Expand Down Expand Up @@ -52,6 +54,7 @@ - (void)setSurvey:(Survey *)survey {
self.createdByLabel.text = [survey.question.createdAt timeAgo];
self.questionLabel.text = survey.question.text;
[self.answerCollectionView setAnswers:survey.answers andTotal:survey.totalVotes];
[self.commentCollectionView setComments:[NSArray arrayWithObjects:nil]];
}

- (void)profileImageView:(ProfileImageView *)view tappedUser:(User *)user {
Expand Down
Loading

0 comments on commit c88b2ba

Please sign in to comment.