Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dynamically loading assets from StoreInfo

  • Loading branch information...
commit d15f89b3518290fc29176a8527891ec5834aeeb4 1 parent effb372
@refaelos refaelos authored
View
2  SoomlaiOSStoreExample/SoomlaiOSStoreExample.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
C0242E8616C4081600803FE4 /* KeyValDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = C0242E8516C4081600803FE4 /* KeyValDatabase.m */; };
+ C061088016E8E4D5000E5739 /* KeyValueStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = C0586A2A16E20A7E00EB8FEA /* KeyValueStorage.m */; };
C08CF20C1641C68D007603E8 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C08CF20B1641C68D007603E8 /* UIKit.framework */; };
C08CF20E1641C68D007603E8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C08CF20D1641C68D007603E8 /* Foundation.framework */; };
C08CF2101641C68D007603E8 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C08CF20F1641C68D007603E8 /* CoreGraphics.framework */; };
@@ -570,6 +571,7 @@
C08CF2AD1641CF9F007603E8 /* StoreEncryptor.m in Sources */,
C08CF2AE1641CF9F007603E8 /* StorefrontInfo.m in Sources */,
C08CF2AF1641CF9F007603E8 /* StoreInfo.m in Sources */,
+ C061088016E8E4D5000E5739 /* KeyValueStorage.m in Sources */,
C08CF2B01641CF9F007603E8 /* VirtualCurrencyStorage.m in Sources */,
C08CF2B11641CF9F007603E8 /* VirtualGoodStorage.m in Sources */,
C08CF2B21641CF9F007603E8 /* AppStoreItem.m in Sources */,
View
2  SoomlaiOSStoreExample/SoomlaiOSStoreExample/MuffinRushAssets.m
@@ -57,7 +57,7 @@ + (void)initialize{
/** Virtual Goods **/
NSDictionary* FRUIT_CAKE_PRICE = [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithInt:225], MUFFINS_CURRENCY_ITEM_ID,
+ [NSNumber numberWithInt:220], MUFFINS_CURRENCY_ITEM_ID,
nil];
NSArray* prices = [NSArray arrayWithObjects:FRUIT_CAKE_PRICE, nil];
FRUIT_CAKE_GOOD = [[VirtualGood alloc] initWithName:@"Fruit Cake" andDescription:@"Customers buy a double portion on each purchase of this cake" andItemId:FRUIT_CAKE_GOOD_ITEM_ID andPriceModel:[[BalanceDrivenPriceModel alloc]
View
39 SoomlaiOSStoreExample/SoomlaiOSStoreExample/VirtualCurrencyPacksViewController.m
@@ -17,11 +17,8 @@
#import "VirtualItemNotFoundException.h"
#import "VirtualCurrencyPackCell.h"
-#define KEY_PACK @"PACK"
-#define KEY_THUMB @"THUMB"
-
@interface VirtualCurrencyPacksViewController () {
- NSArray* packs;
+ NSDictionary* images;
}
@end
@@ -32,24 +29,12 @@ @implementation VirtualCurrencyPacksViewController
- (void)viewDidLoad
{
- packs = [NSArray arrayWithObjects:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] currencyPackWithProductId:_10_MUFFINS_PACK_PRODUCT_ID], KEY_PACK,
- @"muffins01.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] currencyPackWithProductId:_50_MUFFINS_PACK_PRODUCT_ID], KEY_PACK,
- @"muffins02.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] currencyPackWithProductId:_400_MUFFINS_PACK_PRODUCT_ID], KEY_PACK,
- @"muffins03.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] currencyPackWithProductId:_1000_MUFFINS_PACK_PRODUCT_ID], KEY_PACK,
- @"muffins04.png", KEY_THUMB,
- nil],
- nil];
+ images = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"muffins01.png", _10_MUFFINS_PACK_PRODUCT_ID,
+ @"muffins02.png", _50_MUFFINS_PACK_PRODUCT_ID,
+ @"muffins03.png", _400_MUFFINS_PACK_PRODUCT_ID,
+ @"muffins04.png", _1000_MUFFINS_PACK_PRODUCT_ID,
+ nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(curBalanceChanged:) name:EVENT_CHANGED_CURRENCY_BALANCE object:nil];
@@ -77,14 +62,13 @@ - (void)curBalanceChanged:(NSNotification*)notification{
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
- NSDictionary *item = [packs objectAtIndex:indexPath.row];
- VirtualCurrencyPack* pack = [item objectForKey:KEY_PACK];
+ VirtualCurrencyPack* pack = [[[StoreInfo getInstance] virtualCurrencyPacks] objectAtIndex:indexPath.row];
[[StoreController getInstance] buyAppStoreItemWithProcuctId:pack.appstoreItem.productId];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [packs count];
+ return [[[StoreInfo getInstance] virtualCurrencyPacks] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
@@ -93,12 +77,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if (cell == nil) {
cell = [[VirtualCurrencyPackCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
- NSDictionary *item = [packs objectAtIndex:indexPath.row];
- VirtualCurrencyPack* pack = [item objectForKey:KEY_PACK];
+ VirtualCurrencyPack* pack = [[[StoreInfo getInstance] virtualCurrencyPacks] objectAtIndex:indexPath.row];
cell.title.text = pack.name;
cell.description.text = pack.description;
cell.price.text = [NSString stringWithFormat:@"%.02f", pack.appstoreItem.price];
- cell.icon.image = [UIImage imageNamed:[item objectForKey:KEY_THUMB]];
+ cell.icon.image = [UIImage imageNamed:[images objectForKey:pack.appstoreItem.productId]];
return cell;
}
View
39 SoomlaiOSStoreExample/SoomlaiOSStoreExample/VirtualGoodsViewController.m
@@ -16,11 +16,8 @@
#import "StoreInventory.h"
#import "InsufficientFundsException.h"
-#define KEY_GOOD @"GOOD"
-#define KEY_THUMB @"THUMB"
-
@interface VirtualGoodsViewController () {
- NSArray* goods;
+ NSDictionary* images;
}
@end
@@ -33,24 +30,12 @@ - (void)viewDidLoad
{
[[StoreController getInstance] storeOpening];
- goods = [NSArray arrayWithObjects:
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] goodWithItemId:CHOCO_CAKE_GOOD_ITEM_ID], KEY_GOOD,
- @"chocolate_cake.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] goodWithItemId:PAVLOVA_GOOD_ITEM_ID], KEY_GOOD,
- @"pavlova.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] goodWithItemId:CREAM_CUP_GOOD_ITEM_ID], KEY_GOOD,
- @"cream_cup.png", KEY_THUMB,
- nil],
- [NSDictionary dictionaryWithObjectsAndKeys:
- [[StoreInfo getInstance] goodWithItemId:FRUIT_CAKE_GOOD_ITEM_ID], KEY_GOOD,
- @"fruit_cake.png", KEY_THUMB,
- nil],
- nil];
+ images = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"chocolate_cake.png", CHOCO_CAKE_GOOD_ITEM_ID,
+ @"pavlova.png", PAVLOVA_GOOD_ITEM_ID,
+ @"cream_cup.png", CREAM_CUP_GOOD_ITEM_ID,
+ @"fruit_cake.png", FRUIT_CAKE_GOOD_ITEM_ID,
+ nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goodBalanceChanged:) name:EVENT_CHANGED_GOOD_BALANCE object:nil];
@@ -84,8 +69,7 @@ - (void)goodBalanceChanged:(NSNotification*)notification{
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
- NSDictionary *item = [goods objectAtIndex:indexPath.row];
- VirtualGood* good = [item objectForKey:KEY_GOOD];
+ VirtualGood* good = [[[StoreInfo getInstance] virtualGoods] objectAtIndex:indexPath.row];
@try {
[[StoreController getInstance] buyVirtualGood:good.itemId];
@@ -103,7 +87,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [goods count];
+ return [[[StoreInfo getInstance] virtualGoods] count];
}
@@ -113,13 +97,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if (cell == nil) {
cell = [[VirtualGoodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
- NSDictionary *item = [goods objectAtIndex:indexPath.row];
- VirtualGood* good = [item objectForKey:KEY_GOOD];
+ VirtualGood* good = [[[StoreInfo getInstance] virtualGoods] objectAtIndex:indexPath.row];
cell.title.text = good.name;
cell.description.text = good.description;
NSDictionary* currencyValues = good.currencyValues;
cell.price.text = [(NSNumber*)[currencyValues objectForKey:MUFFINS_CURRENCY_ITEM_ID] stringValue];
- cell.icon.image = [UIImage imageNamed:[item objectForKey:KEY_THUMB]];
+ cell.icon.image = [UIImage imageNamed:[images objectForKey:good.itemId]];
int balance = [StoreInventory getGoodBalance:good.itemId];
cell.balance.text = [NSString stringWithFormat:@"%d", balance];
Please sign in to comment.
Something went wrong with that request. Please try again.