This commit is contained in:
Gautier Pelloux-Prayer 2015-04-16 14:38:31 +02:00
parent 0e9eafb0af
commit 182e39f66d
7 changed files with 58 additions and 39 deletions

View file

@ -8,19 +8,17 @@
#import <UIKit/UIKit.h>
#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;

View file

@ -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

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" variant="6xAndEarlier" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
</dependencies>
<objects>
@ -14,42 +15,39 @@
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="Jvg-Ga-qnD">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<view contentMode="scaleToFill" id="Jvg-Ga-qnD" userLabel="view">
<rect key="frame" x="0.0" y="0.0" width="340" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="title" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" id="Np2-5N-fTR" userLabel="ptitle">
<rect key="frame" x="0.0" y="0.0" width="55" height="44"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="title" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="6" id="Np2-5N-fTR" userLabel="ptitle">
<rect key="frame" x="0.0" y="6" width="55" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="description..." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" id="4s8-UV-skT" userLabel="pdescription">
<rect key="frame" x="119" y="0.0" width="136" height="44"/>
<rect key="frame" x="119" y="6" width="136" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" tag="2" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="$0" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" id="jzs-nJ-jrK" userLabel="pprice">
<rect key="frame" x="63" y="0.0" width="48" height="44"/>
<rect key="frame" x="63" y="6" width="48" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="Bcv-Vz-Tq1" userLabel="ppurchased">
<rect key="frame" x="263" y="6" width="51" height="31"/>
<switch opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="Bcv-Vz-Tq1" userLabel="ppurchased">
<rect key="frame" x="263" y="6" width="79" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="148" y="589"/>
<point key="canvasLocation" x="14" y="539"/>
</view>
</objects>
<simulatedMetricsContainer key="defaultSimulatedMetrics">

View file

@ -30,5 +30,5 @@ extern NSString *const kInAppProductsReady;
- (void)loadProducts;
- (BOOL)isPurchased:(SKProduct*)product;
- (void)purchaseWithID:(NSString*)productId;
@end

View file

@ -80,4 +80,8 @@ NSString *const kInAppProductsReady = @"InAppProductsReady";
return false;
}
- (void)purchaseWithID:(NSString *)productId {
}
@end

View file

@ -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 {

View file

@ -16,10 +16,10 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="fwu-cz-Gse" userLabel="productsTable">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="fwu-cz-Gse" userLabel="productsTable">
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<connections>
<outlet property="dataSource" destination="FRQ-Fw-iZ8" id="uQQ-fT-hHp"/>
<outlet property="delegate" destination="FRQ-Fw-iZ8" id="2Dx-aQ-XVB"/>