Skip to content

Commit

Permalink
Changed UIActivityViewController to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
weiran committed Jan 14, 2013
1 parent 91abbb3 commit 5c1b3ee
Show file tree
Hide file tree
Showing 51 changed files with 1,189 additions and 104 deletions.
201 changes: 193 additions & 8 deletions Hackers.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,27 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Hackers/WZCommentsViewController.m"
timestampString = "374441529.426728"
timestampString = "379856428.14839"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "164"
endingLineNumber = "164"
landmarkName = "-selectedComment:atIndexPath:"
startingLineNumber = "158"
endingLineNumber = "158"
landmarkName = "-selectedCommentAtIndexPath:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Hackers/WZCommentsViewController.m"
timestampString = "374440726.945433"
timestampString = "379856108.692019"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "-tableView:cellForRowAtIndexPath:"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Libraries/SVWebViewController/SVWebViewController.m"
timestampString = "375964353.853633"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "119"
endingLineNumber = "119"
landmarkName = "-pageActivityViewController"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "No"
ignoreCount = "0"
Expand Down Expand Up @@ -107,6 +94,45 @@
landmarkName = "-perform"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Libraries/SVWebViewController/SVWebViewController.m"
timestampString = "379864151.643933"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "94"
endingLineNumber = "94"
landmarkName = "-pageActionSheet"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Libraries/SVWebViewController/SVWebViewController.m"
timestampString = "379864154.474029"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "120"
endingLineNumber = "120"
landmarkName = "-pageActivityViewController"
landmarkType = "5">
</FileBreakpoint>
<FileBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Libraries/SVWebViewController/SVWebViewController.m"
timestampString = "379864212.755039"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "340"
endingLineNumber = "340"
landmarkName = "-actionButtonClicked:"
landmarkType = "5">
</FileBreakpoint>
</FileBreakpoints>
<SymbolicBreakpoints>
<SymbolicBreakpoint
Expand Down
8 changes: 4 additions & 4 deletions Hackers/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" animating="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="t2X-yB-S8x"/>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="113" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="Smx-0F-YVN">
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.94901960780000005" alpha="1" colorSpace="calibratedRGB"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="CommentCell" rowHeight="113" id="8RA-zL-sDn" customClass="WZCommentCell">
<rect key="frame" x="0.0" y="22" width="320" height="113"/>
Expand All @@ -355,7 +355,7 @@
<color key="highlightedColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dgd-bJ-Mbb" customClass="RTLabel">
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QUV-CZ-R1S">
<constraints>
Expand All @@ -364,7 +364,7 @@
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
<color key="tintColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<size key="titleShadowOffset" width="1" height="1"/>
<state key="normal" title="Show replies">
<state key="normal" title="Show 2 replies">
<color key="titleColor" red="0.19607843137254902" green="0.30980392156862746" blue="0.52156862745098043" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
Expand Down Expand Up @@ -588,6 +588,6 @@
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
<inferredMetricsTieBreakers>
<segue reference="dWp-Os-Kwq"/>
<segue reference="LV5-XZ-Q4O"/>
</inferredMetricsTieBreakers>
</document>
15 changes: 6 additions & 9 deletions Hackers/WZCommentCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#import <UIKit/UIKit.h>

@class WZCommentModel, RTLabel;
@class RTLabel;

@protocol WZCommentShowRepliesDelegate <NSObject>
- (void)selectedComment:(WZCommentModel *)comment atIndexPath:(NSIndexPath *)indexPath;
- (void)selectedCommentAtIndexPath:(NSIndexPath *)indexPath;
@end

@interface WZCommentCell : UITableViewCell
Expand All @@ -23,13 +23,10 @@
- (IBAction)showReplies:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *showRepliesButton;

@property (copy, nonatomic) WZCommentModel *comment;
@property (nonatomic) NSUInteger contentIndent;
@property (nonatomic) BOOL expanded;
@property (nonatomic) NSUInteger repliesCount;

@property (weak, nonatomic) id <WZCommentShowRepliesDelegate> delegate;


//@property (weak, nonatomic) IBOutlet NSLayoutConstraint *repliesButtonLayoutConstraint;
//@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bodyLayoutConstraint;
//@property (weak, nonatomic) IBOutlet NSLayoutConstraint *userLayoutConstraint;

@end
@end
58 changes: 22 additions & 36 deletions Hackers/WZCommentCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@
//

#import "WZCommentCell.h"
#import "WZCommentModel.h"
#import <RTLabel.h>

@interface WZCommentCell ()
@interface WZCommentCell () {
NSUInteger _indentationPoints;
}
@property (nonatomic, strong) NSLayoutConstraint *userConstraint;
@property (nonatomic, strong) NSLayoutConstraint *bodyConstraint;
@property (nonatomic, strong) NSLayoutConstraint *repliesConstraint;
@end

@implementation WZCommentCell

- (void)setComment:(WZCommentModel *)comment {
_comment = comment;
[self updateLabels];
}

- (void)layoutSubviews {
[super layoutSubviews];
_commentLabel.text = _comment.content;

UIImage *buttonImage = [[UIImage imageNamed:@"greyButton"]
resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *buttonImageHighlight = [[UIImage imageNamed:@"greyButtonHighlight.png"]
Expand All @@ -36,14 +29,22 @@ - (void)layoutSubviews {
[_showRepliesButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
}

- (void)setContentIndent:(NSUInteger)contentIndent {
if (contentIndent != _indentationPoints) {
_indentationPoints = contentIndent;
[self setupConstraints];
}
}

- (NSUInteger)contentIndent {
return _indentationPoints;
}

- (void)setupConstraints {
NSInteger levelValue = _comment.level.integerValue + 1;
NSInteger constant = levelValue * 10;

if (_userConstraint) {
_userConstraint.constant = constant;
_userConstraint.constant = _indentationPoints;
} else {
NSString *userVisualFormat = [NSString stringWithFormat:@"|-%d-[_userLabel]", constant];
NSString *userVisualFormat = [NSString stringWithFormat:@"|-%d-[_userLabel]", _indentationPoints];

_userConstraint = [NSLayoutConstraint constraintsWithVisualFormat:userVisualFormat
options:0
Expand All @@ -53,9 +54,9 @@ - (void)setupConstraints {
}

if (_bodyConstraint) {
_bodyConstraint.constant = constant;
_bodyConstraint.constant = _indentationPoints;
} else {
NSString *bodyVisualFormat = [NSString stringWithFormat:@"|-%d-[_commentLabel]", constant];
NSString *bodyVisualFormat = [NSString stringWithFormat:@"|-%d-[_commentLabel]", _indentationPoints];

_bodyConstraint = [NSLayoutConstraint constraintsWithVisualFormat:bodyVisualFormat
options:0
Expand All @@ -65,9 +66,9 @@ - (void)setupConstraints {
}

if (_repliesConstraint) {
_repliesConstraint.constant = constant;
_repliesConstraint.constant = _indentationPoints;
} else {
NSString *repliesVisualFormat = [NSString stringWithFormat:@"|-%d-[_showRepliesButton]", levelValue * 10];
NSString *repliesVisualFormat = [NSString stringWithFormat:@"|-%d-[_showRepliesButton]", _indentationPoints];

_repliesConstraint = [NSLayoutConstraint constraintsWithVisualFormat:repliesVisualFormat
options:0
Expand All @@ -77,27 +78,12 @@ - (void)setupConstraints {
}
}

- (void)updateLabels {
_userLabel.text = _comment.user;
_dateLabel.text = _comment.timeAgo;
_commentLabel.text = _comment.content;
if (_comment.expanded) {
[_showRepliesButton setTitle:@"Hide replies" forState:UIControlStateNormal];
} else {
[_showRepliesButton setTitle:@"Show replies" forState:UIControlStateNormal];
}

[self setupConstraints];
}

- (IBAction)showReplies:(id)sender {
UITableView *tableView = (UITableView *)self.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:self];

if ([_delegate respondsToSelector:@selector(selectedComment:atIndexPath:)]) {
[_delegate selectedComment:_comment atIndexPath:indexPath];
if ([_delegate respondsToSelector:@selector(selectedCommentAtIndexPath:)]) {
[_delegate selectedCommentAtIndexPath:indexPath];
}

[self updateLabels];
}
@end
50 changes: 27 additions & 23 deletions Hackers/WZCommentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,27 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
WZCommentModel *comment = _comments[indexPath.row];
NSString *cellIdentifier = @"CommentCell";

// switch (comment.level.integerValue) {
// case 0:
// cellIdentifier = @"CommentCell";
// break;
// case 1:
// cellIdentifier = @"CommentCellLevel1";
// break;
// case 2:
// cellIdentifier = @"CommentCellLevel2";
// break;
// case 3:
// cellIdentifier = @"CommentCellLevel3";
// break;
// default:
// cellIdentifier = @"CommentCellLevel3";
// break;
// }

WZCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.comment = comment;
cell.commentLabel.delegate = self;
cell.commentLabel.delegate = self; // for opening links

cell.userLabel.text = comment.user;
cell.dateLabel.text = comment.timeAgo;
cell.commentLabel.text = comment.content;

if (comment.comments.count > 0) {
cell.delegate = self;
cell.showRepliesButton.hidden = NO;
cell.showRepliesButton.titleLabel.text = [self commentButtonLabelTextWithCount:comment.comments.count expanded:comment.expanded];
} else {
cell.delegate = nil;
cell.showRepliesButton.hidden = YES;
}

NSUInteger baseIndentation = 10;
NSUInteger indentStep = 15;
NSUInteger indentation = baseIndentation + (indentStep * comment.level.integerValue);
cell.contentIndent = indentation;

return cell;
}

Expand Down Expand Up @@ -137,7 +128,10 @@ - (void)rtLabel:(id)rtLabel didSelectLinkWithURL:(NSURL *)url {

#pragma mark - WZCommentShowRepliesDelegate

- (void)selectedComment:(WZCommentModel *)comment atIndexPath:(NSIndexPath *)indexPath {
- (void)selectedCommentAtIndexPath:(NSIndexPath *)indexPath {
WZCommentModel *comment = _comments[indexPath.row];
WZCommentCell *cell = (WZCommentCell *)[_tableView cellForRowAtIndexPath:indexPath];

if (comment.comments && !comment.expanded) {
comment.expanded = YES;

Expand All @@ -151,7 +145,7 @@ - (void)selectedComment:(WZCommentModel *)comment atIndexPath:(NSIndexPath *)ind
[newIndexPaths addObject:newIndexPath];
}

[_tableView insertRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationBottom];
[_tableView insertRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationMiddle];
} else if (comment.comments && comment.expanded) {
comment.expanded = NO;

Expand All @@ -173,7 +167,17 @@ - (void)selectedComment:(WZCommentModel *)comment atIndexPath:(NSIndexPath *)ind

[_comments removeObjectsInArray:commentsToRemove];

[_tableView deleteRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationTop];
[_tableView deleteRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationMiddle];
}

cell.showRepliesButton.titleLabel.text = [self commentButtonLabelTextWithCount:comment.comments.count expanded:comment.expanded];
}

- (NSString *)commentButtonLabelTextWithCount:(NSUInteger)count expanded:(BOOL)expanded {
if (count > 1) {
return [NSString stringWithFormat:@"%@ %d replies", expanded ? @"Hide" : @"Show", count];
} else {
return [NSString stringWithFormat:@"%@ 1 reply", expanded ? @"Hide" : @"Show"];
}
}

Expand Down
11 changes: 7 additions & 4 deletions Hackers/WZMainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2012 Weiran Zhang. All rights reserved.
//

#import <SVWebViewController.h>
#import <TSMiniWebBrowser.h>
#import <SWRevealViewController/SWRevealViewController.h>

#import "WZMainViewController.h"
Expand Down Expand Up @@ -220,9 +220,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
WZPostCell *cell = (WZPostCell *)[self.tableView cellForRowAtIndexPath:indexPath];
cell.titleLabel.textColor = [UIColor lightGrayColor];

SVWebViewController *webViewController = [[SVWebViewController alloc] initWithAddress:post.url];
webViewController.itemTitle = post.title;
[self.navigationController pushViewController:webViewController animated:YES];
// SVWebViewController *webViewController = [[SVWebViewController alloc] initWithAddress:post.url];
// webViewController.itemTitle = post.title;
// [self.navigationController pushViewController:webViewController animated:YES];

TSMiniWebBrowser *webBrowser = [[TSMiniWebBrowser alloc] initWithUrl:[NSURL URLWithString:post.url]];
[self.navigationController pushViewController:webBrowser animated:YES];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5c1b3ee

Please sign in to comment.