Skip to content

Commit

Permalink
Partly restore use of CPCollectionView
Browse files Browse the repository at this point in the history
  • Loading branch information
hlship committed Sep 14, 2009
1 parent 989bcb7 commit c99ac9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
30 changes: 18 additions & 12 deletions src/main/webapp/app/TwitView.j
Expand Up @@ -3,31 +3,37 @@

@implementation TwitView : CPView
{
CPImageView _imageView;
CPTextField _label;
}

- (id)initWithFrame:(CGRect)frame forStatus:(JSONObject)obj
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];

[self setBackgroundColor:[CPColor colorWithHexString:"d2d2d2"]];

var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(2, 2, 55, 55)];
[imageView setHasShadow:YES];
[imageView setImage:[[CPImage alloc] initByReferencingFile:obj.user.profile_image_url size:CPSizeMake(55, 55)]];
_imageView = [[CPImageView alloc] initWithFrame:CGRectMake(2, 2, 55, 55)];
[_imageView setHasShadow:YES];

[self addSubview:imageView];
[self addSubview:_imageView];

var label = [[CPTextField alloc] initWithFrame:CPRectMake(57, 0, CPRectGetWidth(frame) - 57, CPRectGetHeight(frame))];
[label setFont:[CPFont systemFontOfSize:12]];
[label setTextColor:[CPColor blackColor]];
[label setAutoresizingMask:CPViewWidthSizable];
[label setLineBreakMode:CPLineBreakByWordWrapping];
_label = [[CPTextField alloc] initWithFrame:CPRectMake(57, 0, CPRectGetWidth(frame) - 57, CPRectGetHeight(frame))];
[_label setFont:[CPFont systemFontOfSize:12]];
[_label setTextColor:[CPColor blackColor]];
[_label setAutoresizingMask:CPViewWidthSizable];
[_label setLineBreakMode:CPLineBreakByWordWrapping];

[self addSubview:label];
[self addSubview:_label];

[label setStringValue:obj.text];

return self;
}

- (void)setRepresentedObject:(JSONObject)obj
{
[_imageView setImage:[[CPImage alloc] initByReferencingFile:obj.user.profile_image_url size:CPSizeMake(55, 55)]];
[_label setStringValue:obj.text];
}

@end
23 changes: 7 additions & 16 deletions src/main/webapp/app/TwitterController.j
Expand Up @@ -10,7 +10,7 @@
CPPanel _panel;
CPTextField _field;
CPScollView _scrollView;
CPView _timelineView;
CPCollectionView _timelineView;
}

- (id)init
Expand Down Expand Up @@ -43,8 +43,12 @@
[_scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[_scrollView setAutohidesScrollers:YES];

_timelineView = [[CPView alloc] init];
var itemPrototype = [[CPCollectionViewItem alloc] init];
[itemPrototype setView:[[TwitView alloc] initWithFrame:CGRectMake(0, 0, 200, 60)]];

_timelineView = [[CPCollectionView alloc] init];
[_timelineView setAutoresizingMask:CPViewWidthSizable];
[_timelineView setItemPrototype:itemPrototype];

[_scrollView setDocumentView:_timelineView];

Expand Down Expand Up @@ -81,20 +85,7 @@

- (void)updateTimeline:(CPArray) timeline
{
var width = CPRectGetWidth([_timelineView bounds]) - 4;

var count = [timeline count];

for (row = 0; row < count; row++)
{
var frame = CGRectMake(2, 64 * row + 2, width, 60);
var view = [[TwitView alloc] initWithFrame:frame forStatus:[timeline objectAtIndex:row]];
[view setAutoresizingMask:CPViewWidthSizable];

[_timelineView addSubview:view];
}

[_timelineView setFrameSize:CGSizeMake(width + 4, 64 * count + 2)];
[_timelineView setContent:timeline];
}


Expand Down

0 comments on commit c99ac9b

Please sign in to comment.