Skip to content

Instantly share code, notes, and snippets.

@jjthrash
Created February 17, 2010 16:32
Show Gist options
  • Save jjthrash/306777 to your computer and use it in GitHub Desktop.
Save jjthrash/306777 to your computer and use it in GitHub Desktop.
diff --git a/Airship/StoreFront/StoreFrontDelegate.h b/Airship/StoreFront/StoreFrontDelegate.h
index 98ceb74..5d6c06a 100644
--- a/Airship/StoreFront/StoreFrontDelegate.h
+++ b/Airship/StoreFront/StoreFrontDelegate.h
@@ -32,5 +32,6 @@
@optional
-(void)storeFrontDidHide;
-(void)storeFrontWillHide;
+-(BOOL)shouldDisplayProduct:(UAProduct*)product;
@end
diff --git a/Airship/StoreFront/UAInventory.m b/Airship/StoreFront/UAInventory.m
index 9088f85..2b60742 100644
--- a/Airship/StoreFront/UAInventory.m
+++ b/Airship/StoreFront/UAInventory.m
@@ -55,13 +55,29 @@
return productList;
}
-- (NSArray*)sortedKeys {
- return [[productList allKeys] sortedArrayUsingSelector:@selector(compare:)];
+- (NSArray*)displayKeys {
+ //get the list
+ NSArray *result = [productList allKeys];
+
+ //then filter it, if necessary
+ if ([[StoreFront shared].delegate respondsToSelector:@selector(shouldDisplayProduct:)]) {
+ NSMutableArray *filteredProducts = [NSMutableArray arrayWithCapacity:result.count];
+ for (NSString *productID in result) {
+ if ([[StoreFront shared].delegate shouldDisplayProduct:[productList objectForKey:productID]])
+ [filteredProducts addObject:productID];
+ }
+ result = filteredProducts;
+ }
+
+ //then sort it
+ result = [result sortedArrayUsingSelector:@selector(compare:)];
+
+ return result;
}
- (void)removeProduct:(NSString*)productId {
[productList removeObjectForKey: productId];
- [keys setArray: self.sortedKeys];
+ [keys setArray: self.displayKeys];
}
- (UAProduct*)productWithIdentifier:(NSString*)productId {
@@ -70,7 +86,7 @@
- (void)addProduct:(UAProduct*)product {
[productList setObject: product forKey: product.productIdentifier];
- [keys setArray: self.sortedKeys];
+ [keys setArray: self.displayKeys];
}
- (int)count {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment