linphone-iphone/Classes/InAppProductsCell.m
Guillaume BIENKOWSKI b6d8afe22e Migrate to ARC \o/
2015-06-02 11:54:48 +02:00

60 lines
1.8 KiB
Objective-C

//
// InAppProductsCell.m
// linphone
//
// Created by Gautier Pelloux-Prayer on 15/04/15.
//
//
#import "InAppProductsCell.h"
#import "LinphoneManager.h"
@implementation InAppProductsCell
- (void)setIsMaximized:(BOOL)isMaximized {
_isMaximized = isMaximized;
//show the BUY button only when not maximized
// _buyButton.hidden = !isMaximized;
self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width,
[InAppProductsCell getHeight:isMaximized]);
}
- (void)fillFromProduct:(SKProduct *)prod {
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setLocale:prod.priceLocale];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString * formattedPrice = [formatter stringFromNumber:prod.price];
[_ptitle setText: [prod localizedTitle]];
[_pdescription setText: [prod localizedDescription]];
[_pprice setText: formattedPrice];
[_ppurchased setOn: [[[LinphoneManager instance] iapManager] isPurchasedWithID:prod.productIdentifier]];
_productID = prod.productIdentifier;
}
- (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized {
if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) {
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"InAppProductsCell"
owner:self
options:nil];
if ([arrayOfViews count] >= 1) {
[self.contentView addSubview:[arrayOfViews objectAtIndex:0]];
}
_isMaximized = maximized;
}
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:@"%@ (%@): %@ (%@)", _ptitle.text, _pprice.text, _pdescription.text, _isMaximized ? @"maximized":@"minimized"];
}
+ (CGFloat)getHeight:(BOOL)maximized {
return maximized ? 40 : 40;
}
@end