diff --git a/Classes/InAppProductsCell.h b/Classes/InAppProductsCell.h index 5073f93fa..871c090f5 100644 --- a/Classes/InAppProductsCell.h +++ b/Classes/InAppProductsCell.h @@ -8,19 +8,17 @@ #import -#import "UITransparentTVCell.h" - - -@interface InAppProductsCell : UITransparentTVCell { +@interface InAppProductsCell : UITableViewCell { } @property (retain, nonatomic) IBOutlet UILabel *ptitle; @property (retain, nonatomic) IBOutlet UILabel *pdescription; @property (retain, nonatomic) IBOutlet UILabel *pprice; @property (retain, nonatomic) IBOutlet UISwitch *ppurchased; @property (nonatomic) BOOL isMaximized; +@property (retain, nonatomic) NSString *productID; -- (id)initWithIdentifier:(NSString*)identifier; +- (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized; + (CGFloat)getHeight:(BOOL)maximized; diff --git a/Classes/InAppProductsCell.m b/Classes/InAppProductsCell.m index e075e932b..fe9edc42d 100644 --- a/Classes/InAppProductsCell.m +++ b/Classes/InAppProductsCell.m @@ -7,6 +7,7 @@ // #import "InAppProductsCell.h" +#import "LinphoneManager.h" @implementation InAppProductsCell @@ -14,6 +15,7 @@ _isMaximized = isMaximized; //show the BUY button only when not maximized +// _buyButton.hidden = !isMaximized; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, @@ -21,7 +23,7 @@ [InAppProductsCell getHeight:isMaximized]); } -- (id)initWithIdentifier:(NSString*)identifier { +- (id)initWithIdentifier:(NSString*)identifier maximized:(bool)maximized { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"InAppProductsCell" owner:self @@ -29,6 +31,7 @@ if ([arrayOfViews count] >= 1) { [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; } + _isMaximized = maximized; } return self; } @@ -42,11 +45,11 @@ } - (NSString *)description { - return [NSString stringWithFormat:@"%@ (%@): %@", _ptitle.text, _pprice.text, _pdescription.text]; + return [NSString stringWithFormat:@"%@ (%@): %@ (%@)", _ptitle.text, _pprice.text, _pdescription.text, _isMaximized ? @"maximized":@"minimized"]; } + (CGFloat)getHeight:(BOOL)maximized { - return maximized ? 120 : 44; + return maximized ? 40 : 40; } @end diff --git a/Classes/InAppProductsCell.xib b/Classes/InAppProductsCell.xib index ad9ca60b8..135e74bb1 100644 --- a/Classes/InAppProductsCell.xib +++ b/Classes/InAppProductsCell.xib @@ -1,7 +1,8 @@ - + + @@ -14,42 +15,39 @@ - - - + + + - - - - - + diff --git a/Classes/InAppProductsManager.h b/Classes/InAppProductsManager.h index b7f35fa32..03927caf1 100644 --- a/Classes/InAppProductsManager.h +++ b/Classes/InAppProductsManager.h @@ -30,5 +30,5 @@ extern NSString *const kInAppProductsReady; - (void)loadProducts; - (BOOL)isPurchased:(SKProduct*)product; - +- (void)purchaseWithID:(NSString*)productId; @end diff --git a/Classes/InAppProductsManager.m b/Classes/InAppProductsManager.m index 66034a0c1..3a0faa3a3 100644 --- a/Classes/InAppProductsManager.m +++ b/Classes/InAppProductsManager.m @@ -80,4 +80,8 @@ NSString *const kInAppProductsReady = @"InAppProductsReady"; return false; } +- (void)purchaseWithID:(NSString *)productId { + +} + @end \ No newline at end of file diff --git a/Classes/InAppProductsTableViewController.m b/Classes/InAppProductsTableViewController.m index fa86d45b6..0101ab94f 100644 --- a/Classes/InAppProductsTableViewController.m +++ b/Classes/InAppProductsTableViewController.m @@ -10,6 +10,7 @@ #import "InAppProductsCell.h" #import "InAppProductsManager.h" #import "LinphoneManager.h" +#import "DTAlertView.h" @implementation InAppProductsTableViewController { InAppProductsManager *iapm; @@ -18,7 +19,7 @@ - (void)viewWillAppear:(BOOL)animated { iapm = [[LinphoneManager instance] iapManager]; - + currentExpanded = -1; [iapm loadProducts]; } @@ -36,31 +37,46 @@ static NSString *kCellId = @"InAppProductsCell"; InAppProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; if (cell == nil) { - cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId] autorelease]; + cell = [[[InAppProductsCell alloc] initWithIdentifier:kCellId maximized:(currentExpanded == indexPath.row)] autorelease]; } SKProduct *prod = [[[[LinphoneManager instance] iapManager] inAppProducts] objectAtIndex:indexPath.row]; [cell.ptitle setText: [prod localizedTitle]]; [cell.pdescription setText: [prod localizedDescription]]; [cell.pprice setText: [NSString stringWithFormat:@"%@", [prod price]]]; - [cell.ppurchased setEnabled: [iapm isPurchased:prod]]; + [cell.ppurchased setOn: [iapm isPurchased:prod]]; cell.isMaximized = (currentExpanded == indexPath.row); - + cell.productID = prod.productIdentifier; + LOGI(@"One more: %@", cell); return cell; } +//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { +// if(currentExpanded == indexPath.row) { +// currentExpanded = -1; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; +// return; +// } else if(currentExpanded >= 0) { +// NSIndexPath *previousPath = [NSIndexPath indexPathForRow:currentExpanded inSection:0]; +// currentExpanded = indexPath.row; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; +// } +// currentExpanded = indexPath.row; +// [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; +//} + - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if(currentExpanded == indexPath.row) { - currentExpanded = -1; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; - return; - } else if(currentExpanded >= 0) { - NSIndexPath *previousPath = [NSIndexPath indexPathForRow:currentExpanded inSection:0]; - currentExpanded = indexPath.row; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; + InAppProductsCell *cell = (InAppProductsCell*)[tableView cellForRowAtIndexPath:indexPath]; + if (cell.ppurchased.isOn) { + DTAlertView* alert = [[DTAlertView alloc] initWithTitle:NSLocalizedString(@"Already purchased", nil) message: [NSString stringWithFormat:NSLocalizedString(@"You already bought %@.",nil), cell.ptitle.text]]; + + [alert addCancelButtonWithTitle:NSLocalizedString(@"OK", nil) block:nil]; + [alert show]; + [alert release]; + } else { + //try to purchase item, and if successfull change the switch + [[[LinphoneManager instance] iapManager] purchaseWithID: cell.productID]; } - currentExpanded = indexPath.row; - [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Classes/InAppProductsViewController.xib b/Classes/InAppProductsViewController.xib index 3d871c635..d6893f211 100644 --- a/Classes/InAppProductsViewController.xib +++ b/Classes/InAppProductsViewController.xib @@ -16,10 +16,10 @@ - + - +