diff --git a/Classes/LinphoneUI/UIShopTableCell.h b/Classes/LinphoneUI/UIShopTableCell.h new file mode 100644 index 000000000..538564151 --- /dev/null +++ b/Classes/LinphoneUI/UIShopTableCell.h @@ -0,0 +1,31 @@ +/* UIShopTableCell.h + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import + +@interface UIShopTableCell : UITableViewCell + +@property(nonatomic, strong) IBOutlet UILabel *nameLabel; +@property(nonatomic, strong) IBOutlet UILabel *descriptionLabel; +@property(weak, nonatomic) IBOutlet UIImageView *linphoneImage; +@property(weak, nonatomic) IBOutlet UIImageView *infoImage; + +- (id)initWithIdentifier:(NSString *)identifier; + +@end diff --git a/Classes/LinphoneUI/UIShopTableCell.m b/Classes/LinphoneUI/UIShopTableCell.m new file mode 100644 index 000000000..70a26d49a --- /dev/null +++ b/Classes/LinphoneUI/UIShopTableCell.m @@ -0,0 +1,83 @@ +/* UIShopTableCell.m + * + * Copyright (C) 2012 Belledonne Comunications, Grenoble, France + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "UIShopTableCell.h" +#import "Utils.h" +#import "UILabel+Boldify.h" + +@implementation UIShopTableCell + +UILabel *nameLabel; +UILabel *descriptionLabel; +UIImageView *linphoneImage; +UIImageView *infoImage; + +#pragma mark - Lifecycle Functions + +- (id)initWithIdentifier:(NSString *)identifier { + if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { + NSArray *arrayOfViews = + [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil]; + + // resize cell to match .nib size. It is needed when resized the cell to + // correctly adapt its height too + UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:0]); + [self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)]; + [self addSubview:sub]; + + // Sections are wider on iPad and overlap linphone image - let's move it a bit + if (IPAD) { + CGRect frame = _linphoneImage.frame; + frame.origin.x -= frame.size.width / 2; + _linphoneImage.frame = frame; + } + } + return self; +} + +#pragma mark - + +- (void)touchUp:(id)sender { + [self setHighlighted:true animated:true]; +} + +- (void)touchDown:(id)sender { + [self setHighlighted:false animated:true]; +} + +- (NSString *)accessibilityLabel { + return _nameLabel.text; +} + +- (void)setEditing:(BOOL)editing { + [self setEditing:editing animated:FALSE]; +} + +- (void)setEditing:(BOOL)editing animated:(BOOL)animated { + if (animated) { + [UIView beginAnimations:nil context:nil]; + [UIView setAnimationDuration:0.3]; + } + _linphoneImage.alpha = editing ? 0 : 1; + if (animated) { + [UIView commitAnimations]; + } +} + +@end diff --git a/Classes/LinphoneUI/UIShopTableCell.xib b/Classes/LinphoneUI/UIShopTableCell.xib new file mode 100644 index 000000000..0ccd72b80 --- /dev/null +++ b/Classes/LinphoneUI/UIShopTableCell.xib @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/ShopTableView.m b/Classes/ShopTableView.m index 8c06a5aba..ea14c5bb1 100644 --- a/Classes/ShopTableView.m +++ b/Classes/ShopTableView.m @@ -9,6 +9,7 @@ #import "ShopTableView.h" #import "ShopView.h" #import "PhoneMainView.h" +#import "LinphoneUI/UIShopTableCell.h" @implementation ShopTableView @@ -16,7 +17,6 @@ [super viewDidLoad]; // remove separators between empty items, cf - // http://stackoverflow.com/questions/1633966/can-i-force-a-uitableview-to-hide-the-separator-between-empty-cells self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; } @@ -31,11 +31,13 @@ } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class)]; - if (!cell) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle - reuseIdentifier:NSStringFromClass(self.class)]; + + static NSString *kCellId = @"UIShopTableCell"; + UIShopTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + if (cell == nil) { + cell = [[UIShopTableCell alloc] initWithIdentifier:kCellId]; } + SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row]; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; @@ -44,13 +46,14 @@ [numberFormatter setLocale:product.priceLocale]; NSString *price = [numberFormatter stringFromNumber:product.price]; - cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price]; - cell.detailTextLabel.text = product.localizedDescription; - cell.detailTextLabel.numberOfLines = 2; - cell.detailTextLabel.minimumScaleFactor = .5; - cell.detailTextLabel.adjustsFontSizeToFitWidth = cell.detailTextLabel.adjustsLetterSpacingToFitWidth = YES; - cell.accessoryType = UITableViewCellAccessoryDetailButton; - [cell setImage:[UIImage imageNamed:@"linphone_logo"]]; + cell.nameLabel.text = [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price]; + cell.descriptionLabel.numberOfLines = 2; + cell.descriptionLabel.minimumScaleFactor = .5; + cell.descriptionLabel.adjustsFontSizeToFitWidth = cell.detailTextLabel.adjustsLetterSpacingToFitWidth = YES; + cell.descriptionLabel.text = [NSString stringWithFormat:@"%@", product.localizedDescription]; + LOGE(@"ShopTableView : name = %@ - descr = %@", + [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price], product.localizedDescription); + [cell.linphoneImage setImage:[UIImage imageNamed:@"linphone_logo"]]; return cell; } @@ -60,13 +63,6 @@ SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row]; [LinphoneManager.instance.iapManager purchaseWithID:product.productIdentifier]; - - /* UIWindow *window = [[UIApplication sharedApplication] keyWindow]; - UIView *topView = window.rootViewController.view; - UIView *waitview = (UIView*)[topView viewWithTag:288]; - - [waitview setHidden:FALSE]; - */ } @end