Skip to content

Commit

Permalink
Merge branch 'avoid-collection-view'
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/webapp/app/TwitView.j
	src/main/webapp/app/TwitterController.j
  • Loading branch information
hlship committed Sep 14, 2009
2 parents 8d9d934 + c99ac9b commit dcb6f21
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
29 changes: 23 additions & 6 deletions src/main/webapp/app/TwitView.j
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
@import <AppKit/CPView.j>
@import <AppKit/CPTextField.j>

var silver = [CPColor colorWithHexString:"d2d2d2"];

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

- (void) setRepresentedObject:(JSONObject)obj
- (void)setRepresentedObject:(JSONObject)obj
{
if (!_label)
{
// Not sure why it doesn't work when I set the bg color inside init, but it works
// here.
[self setBackgroundColor:silver];

var bounds = [self bounds];

_imageView = [[CPImageView alloc] initWithFrame:CGRectMake(2, 2, 55, 55)];
[_imageView setHasShadow:YES];

[self addSubview:_imageView];

var labelBounds = CPRectMake(57, 0, CPRectGetWidth(bounds) - 57, 60);

_label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[_label setFont:[CPFont systemFontOfSize:12]];
[_label setTextColor:[CPColor whiteColor]];
[_label setTextColor:[CPColor blackColor]];
[_label setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[_label setFrame:[self bounds]];
[_label setFrame:labelBounds];
[_label setLineBreakMode:CPLineBreakByWordWrapping];

[self addSubview:_label];
}

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

- (void)setSelected:(BOOL)isSelected
- (void)setSelected:(BOOL)selected
{
var color = isSelected ? [CPColor blueColor] :nil;

var color = selected ? [CPColor whiteColor] : silver;
[self setBackgroundColor:color];
}

Expand Down
14 changes: 9 additions & 5 deletions src/main/webapp/app/TwitterController.j
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
[itemPrototype setView:[[TwitView alloc] initWithFrame:CGRectMakeZero()]];

_timelineView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0,
CGRectGetWidth(scrollViewBounds), 0)];
CGRectGetWidth(scrollViewBounds) - 2, 0)];
[_timelineView setItemPrototype:itemPrototype];
[_timelineView setDelegate:self];
[_timelineView setMaxNumberOfColumns:1];
Expand All @@ -62,9 +62,8 @@
[content addSubview:_field];
[content addSubview:_scrollView];

[_timelineView setMinItemSize:CGSizeMake(200, 50)];
[_timelineView setMaxItemSize:CGSizeMake(100000, 50)];

[_timelineView setMinItemSize:CGSizeMake(200, 60)];
[_timelineView setMaxItemSize:CGSizeMake(100000, 60)];

return self;
}
Expand All @@ -80,7 +79,7 @@
// Simulate the call to twitter.com, using a cached copy of the response.
// Because of single-source policy, we'll need to implement a servlet at /twitter
// than can get the content from the real site and pass it to the browser.
var url = "twitter/statuses/user_timeline/" + [_field stringValue] + ".json";
var url = "twitter/statuses/friends_timeline/" + [_field stringValue] + ".json";

var request = [CPURLRequest requestWithURL:url];
[CPURLConnection connectionWithRequest:request delegate:self];
Expand All @@ -90,6 +89,11 @@
{
var timeline = JSON.parse(data);

[self updateTimeline:timeline];
}

- (void)updateTimeline:(CPArray) timeline
{
[_timelineView setContent:timeline];
}

Expand Down
Loading

0 comments on commit dcb6f21

Please sign in to comment.