Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. @interface BBTradeItemNode ()
  3.  
  4. @property (strong, nonatomic) ASDisplayNode *tradeTyprDisplayNode;
  5.  
  6. @property (strong, nonatomic) ASTextNode *tradeTitleNode;
  7. @property (strong, nonatomic) ASTextNode *tradeAmountNode;
  8. @property (strong, nonatomic) ASTextNode *tradeCloseDateNode;
  9. @property (strong, nonatomic) ASNetworkImageNode *thumbnailImageNode;
  10. @property (strong, nonatomic) ASImageNode *hotIconImageNode;
  11.  
  12. @property (strong, nonatomic) BBItem *tradeItem;
  13.  
  14. @end
  15.  
  16. @implementation BBTradeItemNode
  17.  
  18. - (instancetype)initWithTrade:(BBItem*)trade {
  19.    
  20.     self = [super init];
  21.     if (self) {
  22.        
  23.         _tradeItem = trade;
  24.        
  25.         self.backgroundColor = [UIColor whiteColor];
  26.         self.clipsToBounds = YES;
  27.        
  28.        
  29.         _watchButtonNode = [[ASButtonNode alloc]init];
  30.         _watchButtonNode.style.preferredSize = CGSizeMake(30, 30);
  31.        
  32.         _tradeTyprDisplayNode = [[ASDisplayNode alloc] init];
  33.         _tradeTyprDisplayNode.style.preferredSize = CGSizeMake(4, 80);
  34.        
  35.         _thumbnailImageNode = [[ASNetworkImageNode alloc] init];
  36.         _thumbnailImageNode.placeholderEnabled = YES;
  37.         _thumbnailImageNode.placeholderColor = [UIColor colorWithHex:BACKGROUNDCOLOR_GREY];
  38.         _thumbnailImageNode.defaultImage = [UIImage imageNamed:@"Temp Image"];
  39.         _thumbnailImageNode.URL = [NSURL imageURLforRawURLString:_tradeItem.thumbnailUrl size:Small];
  40.         _thumbnailImageNode.style.preferredSize = CGSizeMake(80, 80);
  41.        
  42.         _tradeTitleNode = [[ASTextNode alloc] init];
  43.         _tradeTitleNode.style.maxWidth = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad  ? 182 : [UIScreen mainScreen].bounds.size.width - 138);
  44.        
  45.         _tradeTitleNode.attributedText = [NSAttributedString attributedStringForTitleText:_tradeItem.tradeTitle];
  46.         _tradeAmountNode.maximumNumberOfLines = 2;
  47.        
  48.         _tradeCloseDateNode = [[ASTextNode alloc] init];
  49.         _tradeCloseDateNode.attributedText = [NSAttributedString attributedStringForDateText:[NSString stringWithFormat:@"Ends: %@", _tradeItem.twentFourHourCloseDate]];
  50.        
  51.         _tradeAmountNode = [[ASTextNode alloc] init];
  52.         _tradeAmountNode.attributedText = [NSAttributedString attributedStringForAmountText:[BBUtils getDisplayAmountStringWithValue:_tradeItem.bidAmount Currency:_tradeItem.tradeCurrency]];
  53.         _tradeAmountNode.placeholderEnabled = YES;
  54.         _tradeAmountNode.placeholderFadeDuration = 0.15;
  55.         _tradeAmountNode.placeholderColor = [UIColor colorWithWhite:0.777 alpha:1.0];
  56.        
  57.         [self addSubnode:self.thumbnailImageNode];
  58.         [self addSubnode:self.tradeTyprDisplayNode];
  59.         [self addSubnode:self.tradeTitleNode];
  60.         [self addSubnode:self.tradeCloseDateNode];
  61.         [self addSubnode:self.tradeAmountNode];
  62.         [self addSubnode:self.watchButtonNode];
  63.        
  64.         switch (_tradeItem.type){
  65.             case AUCTION_ID:
  66.             case BUY_NOW_AUCTION:
  67.                 _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_AUCTION];
  68.                 break;
  69.             case CLASSIFIED_ID:
  70.                 _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_CLASSIFIED];
  71.                 break;
  72.             default:
  73.                 _tradeTyprDisplayNode.view.backgroundColor = [UIColor colorWithHex:LISTING_TYPE_COLOR_BUY_NOW];
  74.                 break;
  75.         }
  76.     }
  77.    
  78.     if(_tradeItem.hotSelling){
  79.        
  80.         _hotIconImageNode = [[ASImageNode alloc] init];
  81.         _hotIconImageNode.style.preferredSize = CGSizeMake(40, 40);
  82.         _hotIconImageNode.image = [UIImage imageNamed:@"Hot Selling Item"];
  83.         [self addSubnode:_hotIconImageNode];
  84.     }  
  85.     return self;
  86. }
  87.  
  88. #pragma mark - Node Layout
  89.  
  90. - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
  91.    
  92.     ASStackLayoutSpec *horizontalTitleAndButtonSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
  93.                                                                                               spacing:0
  94.                                                                                        justifyContent:ASStackLayoutJustifyContentSpaceBetween
  95.                                                                                            alignItems:ASStackLayoutAlignItemsStart
  96.                                                                                              children:@[_tradeTitleNode, _watchButtonNode]];
  97.    
  98.     horizontalTitleAndButtonSpec.style.width = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad ? 219 : [UIScreen mainScreen].bounds.size.width - 100);
  99.     horizontalTitleAndButtonSpec.style.flexGrow = 1.0;
  100.     horizontalTitleAndButtonSpec.style.flexShrink = 1.0;
  101.    
  102.     ASStackLayoutSpec *horizontalCloseDateeAndAmountSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
  103.                                                                                                    spacing:0
  104.                                                                                             justifyContent:ASStackLayoutJustifyContentSpaceBetween
  105.                                                                                                 alignItems:ASStackLayoutAlignItemsStart
  106.                                                                                                   children:@[_tradeCloseDateNode, _tradeAmountNode]];
  107.    
  108.     horizontalCloseDateeAndAmountSpec.style.width = ASDimensionMake([DeviceHardware platformType] == DeviceHardwarePlatformType_iPad ? 219 : [UIScreen mainScreen].bounds.size.width - 100);
  109.    
  110.     ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
  111.                                                                                spacing:0
  112.                                                                         justifyContent:ASStackLayoutJustifyContentSpaceBetween
  113.                                                                             alignItems:ASStackLayoutAlignItemsStart
  114.                                                                               children:@[horizontalTitleAndButtonSpec, horizontalCloseDateeAndAmountSpec]];
  115.    
  116.     verticalStack.style.height = ASDimensionMake(80);
  117.    
  118.    
  119.    
  120.     ASInsetLayoutSpec *insrtSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(8, 8, 8, 8) child:verticalStack];
  121.    
  122.     ASStackLayoutSpec *headerHorizontalStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal
  123.                                                                                        spacing:0
  124.                                                                                 justifyContent:ASStackLayoutJustifyContentStart
  125.                                                                                     alignItems:ASStackLayoutAlignItemsStart
  126.                                                                                       children:@[_tradeTyprDisplayNode, _thumbnailImageNode, insrtSpec]];
  127.    
  128.     headerHorizontalStack.style.height = ASDimensionMake(80);
  129.    
  130.     ASOverlayLayoutSpec *hotSellingoverlaySpec;
  131.    
  132.     if(_hotIconImageNode){
  133.         ASStackLayoutSpec *hotSellingSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical
  134.                                                                                     spacing:0
  135.                                                                              justifyContent:ASStackLayoutJustifyContentStart
  136.                                                                                  alignItems:ASStackLayoutAlignItemsStart
  137.                                                                                    children:@[_hotIconImageNode]];
  138.        
  139.         ASInsetLayoutSpec *overlayInsetSpec = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0, 4, 0, 0) child:hotSellingSpec];
  140.  
  141.         hotSellingoverlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:headerHorizontalStack overlay:overlayInsetSpec];
  142.     }
  143.    
  144.    
  145.     return _hotIconImageNode ? hotSellingoverlaySpec : headerHorizontalStack;
  146. }
  147.  
  148. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement