mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Fixing interactions/activities sizing on ipad.
This commit is contained in:
parent
0ca5bd36fb
commit
3dd75dd8c8
7 changed files with 101 additions and 41 deletions
|
@ -59,10 +59,11 @@
|
|||
labelRect.size.width = contentRect.size.width - leftMargin - avatarSize - leftMargin - rightMargin;
|
||||
labelRect.size.height = contentRect.size.height - topMargin - bottomMargin;
|
||||
self.activityLabel.frame = labelRect;
|
||||
[self.activityLabel sizeToFit];
|
||||
}
|
||||
|
||||
- (int)setActivity:(NSDictionary *)activity withUserProfile:(NSDictionary *)userProfile withWidth:(int)width {
|
||||
// must set the height again for dynamic height in heightForRowAtIndexPath in
|
||||
// must set the height again for dynamic height in heightForRowAtIndexPath in
|
||||
CGRect activityLabelRect = self.activityLabel.bounds;
|
||||
activityLabelRect.size.width = width - leftMargin - avatarSize - leftMargin - rightMargin;
|
||||
self.activityLabel.frame = activityLabelRect;
|
||||
|
@ -119,15 +120,15 @@
|
|||
txt = [NSString stringWithFormat:@"%@ followed %@.", username, withUserUsername];
|
||||
} else if ([category isEqualToString:@"comment_reply"]) {
|
||||
withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
||||
txt = [NSString stringWithFormat:@"%@ replied to %@: \n%@", username, withUserUsername, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ replied to %@: \n \n%@", username, withUserUsername, comment];
|
||||
} else if ([category isEqualToString:@"comment_like"]) {
|
||||
withUserUsername = [[activity objectForKey:@"with_user"] objectForKey:@"username"];
|
||||
txt = [NSString stringWithFormat:@"%@ favorited %@'s comment on %@:\n%@", username, withUserUsername, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ favorited %@'s comment on %@:\n \n%@", username, withUserUsername, title, comment];
|
||||
} else if ([category isEqualToString:@"sharedstory"]) {
|
||||
if ([content class] == [NSNull class] || [content isEqualToString:@""] || content == nil) {
|
||||
txt = [NSString stringWithFormat:@"%@ shared %@.", username, title];
|
||||
} else {
|
||||
txt = [NSString stringWithFormat:@"%@ shared %@:\n%@", username, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ shared %@:\n \n%@", username, title, comment];
|
||||
}
|
||||
|
||||
} else if ([category isEqualToString:@"star"]) {
|
||||
|
@ -138,7 +139,7 @@
|
|||
txt = [NSString stringWithFormat:@"You signed up for NewsBlur."];
|
||||
}
|
||||
|
||||
NSString *txtWithTime = [NSString stringWithFormat:@"%@\n%@", txt, time];
|
||||
NSString *txtWithTime = [NSString stringWithFormat:@"%@\n \n%@", txt, time];
|
||||
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:txtWithTime];
|
||||
|
||||
[attrStr setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:13]} range:NSMakeRange(0, [txtWithTime length])];
|
||||
|
@ -165,13 +166,27 @@
|
|||
style.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
[attrStr addAttributes:@{NSParagraphStyleAttributeName: style} range:NSMakeRange(0, [txtWithTime length])];
|
||||
|
||||
NSRange commentRange = [txtWithTime rangeOfString:comment];
|
||||
if (commentRange.location != NSNotFound) {
|
||||
commentRange.location -= 2;
|
||||
commentRange.length = 1;
|
||||
[attrStr addAttribute:NSFontAttributeName
|
||||
value:[UIFont systemFontOfSize:4.0f]
|
||||
range:commentRange];
|
||||
}
|
||||
|
||||
NSRange dateRange = [txtWithTime rangeOfString:time];
|
||||
if (dateRange.location != NSNotFound) {
|
||||
dateRange.location -= 2;
|
||||
dateRange.length = 1;
|
||||
[attrStr addAttribute:NSFontAttributeName
|
||||
value:[UIFont systemFontOfSize:4.0f]
|
||||
range:dateRange];
|
||||
}
|
||||
|
||||
self.activityLabel.attributedText = attrStr;
|
||||
|
||||
CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(self.activityLabel.frame.size.width, 0.0f)
|
||||
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
|
||||
context:nil];
|
||||
self.activityLabel.frame = rect;
|
||||
|
||||
[self.activityLabel sizeToFit];
|
||||
|
||||
int height = self.activityLabel.frame.size.height;
|
||||
|
||||
return MAX(height, self.faviconView.frame.size.height);
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
@synthesize pageFinished;
|
||||
@synthesize activitiesPage;
|
||||
|
||||
#define MINIMUM_ACTIVITY_HEIGHT 48 + 30
|
||||
#define MINIMUM_ACTIVITY_HEIGHT_IPAD 78
|
||||
#define MINIMUM_ACTIVITY_HEIGHT_IPHONE 48
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
|
@ -173,7 +174,11 @@
|
|||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
int activitiesCount = [appDelegate.userActivitiesArray count];
|
||||
if (indexPath.row >= activitiesCount) {
|
||||
return MINIMUM_ACTIVITY_HEIGHT;
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
return MINIMUM_ACTIVITY_HEIGHT_IPAD;
|
||||
} else {
|
||||
return MINIMUM_ACTIVITY_HEIGHT_IPHONE;
|
||||
}
|
||||
}
|
||||
|
||||
id activityCell;
|
||||
|
@ -310,7 +315,12 @@
|
|||
if (self.pageFinished) {
|
||||
UIImage *img = [UIImage imageNamed:@"fleuron.png"];
|
||||
UIImageView *fleuron = [[UIImageView alloc] initWithImage:img];
|
||||
int height = MINIMUM_ACTIVITY_HEIGHT;
|
||||
int height;
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
height = MINIMUM_ACTIVITY_HEIGHT_IPAD;
|
||||
} else {
|
||||
height = MINIMUM_ACTIVITY_HEIGHT_IPHONE;
|
||||
}
|
||||
|
||||
fleuron.frame = CGRectMake(0, 0, self.frame.size.width, height);
|
||||
fleuron.contentMode = UIViewContentModeCenter;
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
myBackView.backgroundColor = UIColorFromRGB(NEWSBLUR_HIGHLIGHT_COLOR);
|
||||
self.selectedBackgroundView = myBackView;
|
||||
|
||||
topMargin = 0;
|
||||
bottomMargin = 0;
|
||||
topMargin = 15;
|
||||
bottomMargin = 15;
|
||||
leftMargin = 20;
|
||||
rightMargin = 20;
|
||||
avatarSize = 48;
|
||||
|
@ -64,6 +64,7 @@
|
|||
labelRect.size.width = contentRect.size.width - leftMargin - avatarSize - leftMargin - rightMargin;
|
||||
labelRect.size.height = contentRect.size.height - topMargin - bottomMargin;
|
||||
self.interactionLabel.frame = labelRect;
|
||||
[self.interactionLabel sizeToFit];
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,7 +73,7 @@
|
|||
CGRect interactionLabelRect = self.interactionLabel.bounds;
|
||||
interactionLabelRect.size.width = width - leftMargin - avatarSize - leftMargin - rightMargin;
|
||||
interactionLabelRect.size.height = 300;
|
||||
NSLog(@"Interaction frame: %@", NSStringFromCGRect(interactionLabelRect));
|
||||
|
||||
self.interactionLabel.frame = interactionLabelRect;
|
||||
self.avatarView.frame = CGRectMake(leftMargin, topMargin, avatarSize, avatarSize);
|
||||
self.interactionLabel.numberOfLines = 0;
|
||||
|
@ -97,23 +98,29 @@
|
|||
if ([category isEqualToString:@"follow"]) {
|
||||
txt = [NSString stringWithFormat:@"%@ is now following you.", username];
|
||||
} else if ([category isEqualToString:@"comment_reply"]) {
|
||||
txt = [NSString stringWithFormat:@"%@ replied to your comment on %@:\n%@", username, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ replied to your comment on %@:\n \n%@", username, title, comment];
|
||||
} else if ([category isEqualToString:@"reply_reply"]) {
|
||||
txt = [NSString stringWithFormat:@"%@ replied to your reply on %@:\n%@", username, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ replied to your reply on %@:\n \n%@", username, title, comment];
|
||||
} else if ([category isEqualToString:@"story_reshare"]) {
|
||||
if ([content isEqualToString:@""] || content == nil) {
|
||||
txt = [NSString stringWithFormat:@"%@ re-shared %@.", username, title];
|
||||
} else {
|
||||
txt = [NSString stringWithFormat:@"%@ re-shared %@:\n%@", username, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ re-shared %@:\n \n%@", username, title, comment];
|
||||
}
|
||||
} else if ([category isEqualToString:@"comment_like"]) {
|
||||
txt = [NSString stringWithFormat:@"%@ favorited your comments on %@:\n%@", username, title, comment];
|
||||
txt = [NSString stringWithFormat:@"%@ favorited your comments on %@:\n \n%@", username, title, comment];
|
||||
}
|
||||
|
||||
NSString *txtWithTime = [NSString stringWithFormat:@"%@\n%@", txt, time];
|
||||
NSString *txtWithTime = [NSString stringWithFormat:@"%@\n \n%@", txt, time];
|
||||
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:txtWithTime];
|
||||
|
||||
[attrStr setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:13]} range:NSMakeRange(0, [txtWithTime length])];
|
||||
NSMutableParagraphStyle* style = [NSMutableParagraphStyle new];
|
||||
style.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
style.alignment = NSTextAlignmentLeft;
|
||||
style.lineSpacing = 1.0f;
|
||||
[attrStr setAttributes:@{NSParagraphStyleAttributeName: style} range:NSMakeRange(0, [txtWithTime length])];
|
||||
|
||||
[attrStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:13]} range:NSMakeRange(0, [txtWithTime length])];
|
||||
if (self.highlighted) {
|
||||
[attrStr addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xffffff)} range:NSMakeRange(0, [txtWithTime length])];
|
||||
} else {
|
||||
|
@ -131,18 +138,28 @@
|
|||
|
||||
[attrStr addAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:11]} range:[txtWithTime rangeOfString:time]];
|
||||
|
||||
NSMutableParagraphStyle* style= [NSMutableParagraphStyle new];
|
||||
style.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
style.alignment = NSTextAlignmentLeft;
|
||||
style.lineHeightMultiple = 1.1f;
|
||||
[attrStr addAttributes:@{NSParagraphStyleAttributeName: style} range:NSMakeRange(0, [txtWithTime length])];
|
||||
|
||||
self.interactionLabel.attributedText = attrStr;
|
||||
NSRange commentRange = [txtWithTime rangeOfString:comment];
|
||||
if (commentRange.location != NSNotFound) {
|
||||
commentRange.location -= 2;
|
||||
commentRange.length = 1;
|
||||
[attrStr addAttribute:NSFontAttributeName
|
||||
value:[UIFont systemFontOfSize:4.0f]
|
||||
range:commentRange];
|
||||
}
|
||||
|
||||
CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(self.interactionLabel.frame.size.width, 0.0f)
|
||||
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
|
||||
context:nil];
|
||||
self.interactionLabel.frame = rect;
|
||||
NSRange dateRange = [txtWithTime rangeOfString:time];
|
||||
if (dateRange.location != NSNotFound) {
|
||||
dateRange.location -= 2;
|
||||
dateRange.length = 1;
|
||||
[attrStr addAttribute:NSFontAttributeName
|
||||
value:[UIFont systemFontOfSize:4.0f]
|
||||
range:dateRange];
|
||||
}
|
||||
|
||||
self.interactionLabel.attributedText = attrStr;
|
||||
NSLog(@"Frame: %@", NSStringFromCGRect(self.interactionLabel.frame));
|
||||
[self.interactionLabel sizeToFit];
|
||||
NSLog(@"Frame after: %@", NSStringFromCGRect(self.interactionLabel.frame));
|
||||
|
||||
int height = self.interactionLabel.frame.size.height;
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
#import "ASIHTTPRequest.h"
|
||||
#import "UserProfileViewController.h"
|
||||
|
||||
#define MINIMUM_INTERACTION_HEIGHT 78
|
||||
#define MINIMUM_INTERACTION_HEIGHT_IPAD 78
|
||||
#define MINIMUM_INTERACTION_HEIGHT_IPHONE 48
|
||||
|
||||
@implementation InteractionsModule
|
||||
|
||||
|
@ -175,8 +176,15 @@
|
|||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
int userInteractions = [appDelegate.userInteractionsArray count];
|
||||
int minimumHeight;
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
minimumHeight = MINIMUM_INTERACTION_HEIGHT_IPAD;
|
||||
} else {
|
||||
minimumHeight = MINIMUM_INTERACTION_HEIGHT_IPHONE;
|
||||
}
|
||||
|
||||
if (indexPath.row >= userInteractions) {
|
||||
return MINIMUM_INTERACTION_HEIGHT;
|
||||
return minimumHeight;
|
||||
}
|
||||
|
||||
InteractionCell *interactionCell;
|
||||
|
@ -186,8 +194,8 @@
|
|||
interactionCell = [[SmallInteractionCell alloc] init];
|
||||
}
|
||||
int height = [interactionCell setInteraction:[appDelegate.userInteractionsArray objectAtIndex:(indexPath.row)] withWidth:self.frame.size.width - 20] + 30;
|
||||
if (height < MINIMUM_INTERACTION_HEIGHT) {
|
||||
return MINIMUM_INTERACTION_HEIGHT;
|
||||
if (height < minimumHeight) {
|
||||
return minimumHeight;
|
||||
} else {
|
||||
return height;
|
||||
}
|
||||
|
@ -230,6 +238,7 @@
|
|||
|
||||
// update the cell information
|
||||
[cell setInteraction:interaction withWidth: self.frame.size.width - 20];
|
||||
[cell layoutSubviews];
|
||||
}
|
||||
|
||||
return cell;
|
||||
|
@ -289,7 +298,13 @@
|
|||
if (self.pageFinished) {
|
||||
UIImage *img = [UIImage imageNamed:@"fleuron.png"];
|
||||
UIImageView *fleuron = [[UIImageView alloc] initWithImage:img];
|
||||
int height = MINIMUM_INTERACTION_HEIGHT;
|
||||
|
||||
int height;
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
height = MINIMUM_INTERACTION_HEIGHT_IPAD;
|
||||
} else {
|
||||
height = MINIMUM_INTERACTION_HEIGHT_IPHONE;
|
||||
}
|
||||
|
||||
fleuron.frame = CGRectMake(0, 0, self.frame.size.width, height);
|
||||
fleuron.contentMode = UIViewContentModeCenter;
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
self.activityLabel.backgroundColor = UIColorFromRGB(0xf6f6f6);
|
||||
}
|
||||
self.activityLabel.backgroundColor = [UIColor clearColor];
|
||||
[self.activityLabel sizeToFit];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
[self.contentView addSubview:interaction];
|
||||
|
||||
topMargin = 10;
|
||||
bottomMargin = 10;
|
||||
bottomMargin = 0;
|
||||
leftMargin = 10;
|
||||
rightMargin = 10;
|
||||
avatarSize = 32;
|
||||
|
@ -48,6 +48,7 @@
|
|||
self.avatarView.frame = CGRectMake(leftMargin, topMargin, avatarSize, avatarSize);
|
||||
|
||||
// position label to bounds
|
||||
NSLog(@"Frame of cell: %@ / %@", NSStringFromCGRect(contentRect), NSStringFromCGRect(self.interactionLabel.frame));
|
||||
CGRect labelRect = contentRect;
|
||||
labelRect.origin.x = labelRect.origin.x + leftMargin + avatarSize + leftMargin;
|
||||
labelRect.origin.y = labelRect.origin.y + topMargin - 1;
|
||||
|
@ -60,6 +61,7 @@
|
|||
self.interactionLabel.backgroundColor = UIColorFromRGB(0xf6f6f6);
|
||||
}
|
||||
self.interactionLabel.backgroundColor = [UIColor clearColor];
|
||||
[self.interactionLabel sizeToFit];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "Underscore.h"
|
||||
|
||||
#define DEBUG 1
|
||||
//#define DEBUG 1
|
||||
|
||||
#ifdef DEBUG
|
||||
#define BACKGROUND_REFRESH_SECONDS -5
|
||||
|
|
Loading…
Add table
Reference in a new issue