mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge pull request #1530 from hannahmbanana/500pxgram
[ASDKgram example update] Use -fetchData in PhotoCellNode to load Comments & addressed PR comments
This commit is contained in:
@@ -22,14 +22,15 @@
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
_window = [[WindowWithStatusBarUnderlay alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
_window.backgroundColor = [UIColor whiteColor];
|
||||
// this UIWindow subclass is neccessary to make the status bar opaque
|
||||
_window = [[WindowWithStatusBarUnderlay alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
_window.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
// UIKit Home Feed viewController & navController
|
||||
PhotoFeedNodeController *asdkHomeFeedVC = [[PhotoFeedNodeController alloc] init];
|
||||
UINavigationController *asdkHomeFeedNavCtrl = [[UINavigationController alloc] initWithRootViewController:asdkHomeFeedVC];
|
||||
asdkHomeFeedNavCtrl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"ASDK" image:[UIImage imageNamed:@"home"] tag:0];
|
||||
asdkHomeFeedNavCtrl.hidesBarsOnSwipe = YES;
|
||||
PhotoFeedNodeController *asdkHomeFeedVC = [[PhotoFeedNodeController alloc] init];
|
||||
UINavigationController *asdkHomeFeedNavCtrl = [[UINavigationController alloc] initWithRootViewController:asdkHomeFeedVC];
|
||||
asdkHomeFeedNavCtrl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"ASDK" image:[UIImage imageNamed:@"home"] tag:0];
|
||||
asdkHomeFeedNavCtrl.hidesBarsOnSwipe = YES;
|
||||
|
||||
// ASDK Home Feed viewController & navController
|
||||
PhotoFeedViewController *uikitHomeFeedVC = [[PhotoFeedViewController alloc] init];
|
||||
@@ -38,25 +39,21 @@
|
||||
uikitHomeFeedNavCtrl.hidesBarsOnSwipe = YES;
|
||||
|
||||
// UITabBarController
|
||||
UITabBarController *tabBarController = [[UITabBarController alloc] init];
|
||||
tabBarController.viewControllers = @[uikitHomeFeedNavCtrl, asdkHomeFeedNavCtrl];
|
||||
tabBarController.selectedViewController = asdkHomeFeedNavCtrl;
|
||||
tabBarController.delegate = self;
|
||||
|
||||
// Nav Bar appearance
|
||||
[[UINavigationBar appearance] setBarTintColor:[UIColor darkBlueColor]];
|
||||
[[UINavigationBar appearance] setTranslucent:NO];
|
||||
NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
|
||||
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
|
||||
// make the status bar have white text (changes after scrolling, but not on initial app startup)
|
||||
// UINavigationController does not forward on preferredStatusBarStyle calls to its child view controllers.
|
||||
// Instead it manages its own state...http://stackoverflow.com/questions/19022210/preferredstatusbarstyle-isnt-called/19513714#19513714
|
||||
uikitHomeFeedNavCtrl.navigationBar.barStyle = UIBarStyleBlack;
|
||||
asdkHomeFeedNavCtrl.navigationBar.barStyle = UIBarStyleBlack;
|
||||
UITabBarController *tabBarController = [[UITabBarController alloc] init];
|
||||
tabBarController.viewControllers = @[uikitHomeFeedNavCtrl, asdkHomeFeedNavCtrl];
|
||||
tabBarController.selectedViewController = asdkHomeFeedNavCtrl;
|
||||
tabBarController.delegate = self;
|
||||
[[UITabBar appearance] setTintColor:[UIColor darkBlueColor]];
|
||||
|
||||
_window.rootViewController = tabBarController;
|
||||
[_window makeKeyAndVisible];
|
||||
|
||||
// Nav Bar appearance
|
||||
NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
|
||||
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
|
||||
[[UINavigationBar appearance] setBarTintColor:[UIColor darkBlueColor]];
|
||||
[[UINavigationBar appearance] setTranslucent:NO];
|
||||
|
||||
// iOS8 hides the status bar in landscape orientation, this forces the status bar hidden status to NO
|
||||
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
|
||||
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#import "Utilities.h"
|
||||
|
||||
#define INTER_COMMENT_SPACING 5
|
||||
#define NUM_COMMENTS_TO_SHOW 3
|
||||
#define NUM_COMMENTS_TO_SHOW 3
|
||||
|
||||
@implementation CommentView
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#import "CommentsNode.h"
|
||||
|
||||
#define INTER_COMMENT_SPACING 5
|
||||
#define NUM_COMMENTS_TO_SHOW 3
|
||||
#define NUM_COMMENTS_TO_SHOW 3
|
||||
|
||||
@implementation CommentsNode
|
||||
{
|
||||
@@ -52,7 +52,7 @@
|
||||
int labelsIndex = 0;
|
||||
|
||||
if (addViewAllCommentsLabel) {
|
||||
commentLabelString = [_commentFeed viewAllCommentsAttributedString];
|
||||
commentLabelString = [_commentFeed viewAllCommentsAttributedString];
|
||||
[[_commentNodes objectAtIndex:labelsIndex] setAttributedString:commentLabelString];
|
||||
labelsIndex++;
|
||||
}
|
||||
@@ -90,7 +90,7 @@
|
||||
|
||||
for (NSUInteger i = 0; i < numLabelsToAdd; i++) {
|
||||
|
||||
ASTextNode *commentLabel = [[ASTextNode alloc] init];
|
||||
ASTextNode *commentLabel = [[ASTextNode alloc] init];
|
||||
commentLabel.maximumNumberOfLines = 3;
|
||||
|
||||
[_commentNodes addObject:commentLabel];
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
@@ -32,6 +30,8 @@
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UIStatusBarStyle</key>
|
||||
<string>UIStatusBarStyleLightContent</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
@@ -45,5 +45,7 @@
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -15,6 +15,5 @@
|
||||
@interface PhotoCellNode : ASCellNode
|
||||
|
||||
- (instancetype)initWithPhotoObject:(PhotoModel *)photo;
|
||||
- (void)loadCommentsForPhoto:(PhotoModel *)photo;
|
||||
|
||||
@end
|
||||
|
||||
@@ -74,17 +74,9 @@
|
||||
}
|
||||
}];
|
||||
|
||||
_photoTimeIntervalSincePostLabel = [[ASTextNode alloc] init];
|
||||
_photoTimeIntervalSincePostLabel.layerBacked = YES;
|
||||
_photoTimeIntervalSincePostLabel.attributedString = [photo uploadDateAttributedStringWithFontSize:FONT_SIZE];
|
||||
|
||||
_photoLikesLabel = [[ASTextNode alloc] init];
|
||||
_photoLikesLabel.layerBacked = YES;
|
||||
_photoLikesLabel.attributedString = [photo likesAttributedStringWithFontSize:FONT_SIZE];
|
||||
|
||||
_photoDescriptionLabel = [[ASTextNode alloc] init];
|
||||
_photoDescriptionLabel.layerBacked = YES;
|
||||
_photoDescriptionLabel.attributedString = [photo descriptionAttributedStringWithFontSize:FONT_SIZE];
|
||||
_photoTimeIntervalSincePostLabel = [self createLayerBackedTextNodeWithString:[photo uploadDateAttributedStringWithFontSize:FONT_SIZE]];
|
||||
_photoLikesLabel = [self createLayerBackedTextNodeWithString:[photo likesAttributedStringWithFontSize:FONT_SIZE]];
|
||||
_photoDescriptionLabel = [self createLayerBackedTextNodeWithString:[photo descriptionAttributedStringWithFontSize:FONT_SIZE]];
|
||||
_photoDescriptionLabel.maximumNumberOfLines = 3;
|
||||
|
||||
_photoCommentsView = [[CommentsNode alloc] init];
|
||||
@@ -110,12 +102,11 @@
|
||||
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
// username / photo location header vertical stack
|
||||
_photoLocationLabel.flexShrink = YES;
|
||||
_userNameLabel.flexShrink = YES;
|
||||
_photoLocationLabel.flexShrink = YES;
|
||||
_userNameLabel.flexShrink = YES;
|
||||
|
||||
ASStackLayoutSpec *headerSubStack = [ASStackLayoutSpec verticalStackLayoutSpec];
|
||||
headerSubStack.flexShrink = YES;
|
||||
|
||||
headerSubStack.flexShrink = YES;
|
||||
if (_photoLocationLabel.attributedString) {
|
||||
[headerSubStack setChildren:@[_userNameLabel, _photoLocationLabel]];
|
||||
} else {
|
||||
@@ -125,56 +116,65 @@
|
||||
// header stack
|
||||
|
||||
_userAvatarImageView.preferredFrameSize = CGSizeMake(USER_IMAGE_HEIGHT, USER_IMAGE_HEIGHT); // constrain avatar image frame size
|
||||
_photoTimeIntervalSincePostLabel.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer
|
||||
_photoTimeIntervalSincePostLabel.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer
|
||||
|
||||
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size?
|
||||
spacer.flexGrow = YES;
|
||||
spacer.flexShrink = YES;
|
||||
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size?
|
||||
spacer.flexGrow = YES;
|
||||
|
||||
UIEdgeInsets avatarInsets = UIEdgeInsetsMake(HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER, HORIZONTAL_BUFFER);
|
||||
ASInsetLayoutSpec *avatarInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:avatarInsets child:_userAvatarImageView];
|
||||
|
||||
ASStackLayoutSpec *headerStack = [ASStackLayoutSpec horizontalStackLayoutSpec];
|
||||
headerStack.alignItems = ASStackLayoutAlignItemsCenter; // center items vertically in horizontal stack
|
||||
headerStack.justifyContent = ASStackLayoutJustifyContentStart; // justify content to the left side of the header stack
|
||||
|
||||
UIEdgeInsets avatarInsets = UIEdgeInsetsMake(HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER, HORIZONTAL_BUFFER);
|
||||
ASInsetLayoutSpec *avatarInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:avatarInsets child:_userAvatarImageView];
|
||||
|
||||
headerStack.flexShrink = YES;
|
||||
|
||||
[headerStack setChildren:@[avatarInset, headerSubStack, spacer, _photoTimeIntervalSincePostLabel]];
|
||||
|
||||
// header inset stack
|
||||
|
||||
UIEdgeInsets insets = UIEdgeInsetsMake(0, HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER);
|
||||
ASInsetLayoutSpec *headerWithInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:headerStack];
|
||||
headerWithInset.flexShrink = YES;
|
||||
|
||||
// footer stack
|
||||
|
||||
ASStackLayoutSpec *footerStack = [ASStackLayoutSpec verticalStackLayoutSpec];
|
||||
footerStack.spacing = VERTICAL_BUFFER;
|
||||
|
||||
[footerStack setChildren:@[_photoLikesLabel, _photoDescriptionLabel, _photoCommentsView]];
|
||||
|
||||
// footer inset stack
|
||||
|
||||
UIEdgeInsets footerInsets = UIEdgeInsetsMake(VERTICAL_BUFFER, HORIZONTAL_BUFFER, VERTICAL_BUFFER, HORIZONTAL_BUFFER);
|
||||
ASInsetLayoutSpec *footerWithInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:footerInsets child:footerStack];
|
||||
|
||||
// vertical stack
|
||||
|
||||
CGFloat cellWidth = constrainedSize.max.width;
|
||||
_photoImageView.preferredFrameSize = CGSizeMake(cellWidth, cellWidth); // constrain photo frame size
|
||||
|
||||
ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec];
|
||||
verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space
|
||||
[verticalStack setChildren:@[headerWithInset, _photoImageView, footerWithInset]];
|
||||
verticalStack.flexShrink = YES;
|
||||
|
||||
return verticalStack;
|
||||
}
|
||||
|
||||
#pragma mark - Instance Methods
|
||||
|
||||
- (void)fetchData
|
||||
{
|
||||
[super fetchData];
|
||||
|
||||
[_photoModel.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) {
|
||||
[self loadCommentsForPhoto:_photoModel];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Helper Methods
|
||||
|
||||
- (ASTextNode *)createLayerBackedTextNodeWithString:(NSAttributedString *)attributedString
|
||||
{
|
||||
ASTextNode *textNode = [[ASTextNode alloc] init];
|
||||
textNode.layerBacked = YES;
|
||||
textNode.attributedString = attributedString;
|
||||
|
||||
return textNode;
|
||||
}
|
||||
|
||||
- (void)loadCommentsForPhoto:(PhotoModel *)photo
|
||||
{
|
||||
if (photo.commentFeed.numberOfItemsInFeed > 0) {
|
||||
@@ -184,5 +184,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
[_activityIndicatorView stopAnimating];
|
||||
|
||||
[self insertNewRowsInTableView:newPhotos];
|
||||
[self requestCommentsForPhotos:newPhotos];
|
||||
// [self requestCommentsForPhotos:newPhotos];
|
||||
|
||||
// immediately start second larger fetch
|
||||
[self loadPageWithContext:nil];
|
||||
@@ -93,30 +93,30 @@
|
||||
[_photoFeed requestPageWithCompletionBlock:^(NSArray *newPhotos){
|
||||
|
||||
[self insertNewRowsInTableView:newPhotos];
|
||||
[self requestCommentsForPhotos:newPhotos];
|
||||
// [self requestCommentsForPhotos:newPhotos];
|
||||
if (context) {
|
||||
[context completeBatchFetching:YES];
|
||||
}
|
||||
} numResultsToReturn:20];
|
||||
}
|
||||
|
||||
- (void)requestCommentsForPhotos:(NSArray *)newPhotos
|
||||
{
|
||||
for (PhotoModel *photo in newPhotos) {
|
||||
[photo.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) {
|
||||
|
||||
NSInteger rowNum = [_photoFeed indexOfPhotoModel:photo];
|
||||
NSIndexPath *cellPath = [NSIndexPath indexPathForRow:rowNum inSection:0];
|
||||
PhotoCellNode *cell = (PhotoCellNode *)[_tableNode.view nodeForRowAtIndexPath:cellPath];
|
||||
|
||||
if (cell) {
|
||||
[cell loadCommentsForPhoto:photo];
|
||||
[_tableNode.view beginUpdates];
|
||||
[_tableNode.view endUpdates];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
//- (void)requestCommentsForPhotos:(NSArray *)newPhotos
|
||||
//{
|
||||
// for (PhotoModel *photo in newPhotos) {
|
||||
// [photo.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) {
|
||||
//
|
||||
// NSInteger rowNum = [_photoFeed indexOfPhotoModel:photo];
|
||||
// NSIndexPath *cellPath = [NSIndexPath indexPathForRow:rowNum inSection:0];
|
||||
// PhotoCellNode *cell = (PhotoCellNode *)[_tableNode.view nodeForRowAtIndexPath:cellPath];
|
||||
//
|
||||
// if (cell) {
|
||||
// [cell loadCommentsForPhoto:photo];
|
||||
// [_tableNode.view beginUpdates];
|
||||
// [_tableNode.view endUpdates];
|
||||
// }
|
||||
// }];
|
||||
// }
|
||||
//}
|
||||
|
||||
- (void)insertNewRowsInTableView:(NSArray *)newPhotos
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
@interface UserModel : NSObject
|
||||
|
||||
@property (nonatomic, assign, readonly) NSDictionary *dictionaryRepresentation;
|
||||
@property (nonatomic, strong, readonly) NSDictionary *dictionaryRepresentation;
|
||||
@property (nonatomic, assign, readonly) NSUInteger userID;
|
||||
@property (nonatomic, strong, readonly) NSString *username;
|
||||
@property (nonatomic, strong, readonly) NSString *firstName;
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
|
||||
+ (UIColor *)darkBlueColor
|
||||
{
|
||||
return [UIColor colorWithRed:18.0/255.0 green:86.0/255.0 blue:136.0/255.0 alpha:1.0];
|
||||
return [UIColor colorWithRed:70.0/255.0 green:102.0/255.0 blue:118.0/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
+ (UIColor *)lightBlueColor
|
||||
{
|
||||
return [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
|
||||
return [UIColor colorWithRed:70.0/255.0 green:165.0/255.0 blue:196.0/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2016 Facebook. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
// this subclass is neccessary to make the status bar have an opaque, colored background
|
||||
@interface WindowWithStatusBarUnderlay : UIWindow
|
||||
|
||||
@end
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
|
||||
[self bringSubviewToFront:_statusBarOpaqueUnderlayView];
|
||||
|
||||
_statusBarOpaqueUnderlayView.frame = CGRectMake(0,
|
||||
0,
|
||||
[[UIScreen mainScreen] bounds].size.width,
|
||||
[[UIApplication sharedApplication] statusBarFrame].size.height);
|
||||
CGRect statusBarFrame = CGRectZero;
|
||||
statusBarFrame.size.width = [[UIScreen mainScreen] bounds].size.width;
|
||||
statusBarFrame.size.height = [[UIApplication sharedApplication] statusBarFrame].size.height;
|
||||
_statusBarOpaqueUnderlayView.frame = statusBarFrame;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// main.m
|
||||
// ASDKgram
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user