Permalink
Browse files

Partly restore use of CPCollectionView

  • Loading branch information...
1 parent 989bcb7 commit c99ac9bc00ec0b3806133f710a65827cc6df2a95 @hlship committed Sep 14, 2009
Showing with 25 additions and 28 deletions.
  1. +18 −12 src/main/webapp/app/TwitView.j
  2. +7 −16 src/main/webapp/app/TwitterController.j
View
30 src/main/webapp/app/TwitView.j
@@ -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
View
23 src/main/webapp/app/TwitterController.j
@@ -10,7 +10,7 @@
CPPanel _panel;
CPTextField _field;
CPScollView _scrollView;
- CPView _timelineView;
+ CPCollectionView _timelineView;
}
- (id)init
@@ -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];
@@ -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];
}

0 comments on commit c99ac9b

Please sign in to comment.