Skip to content

Commit

Permalink
Fix compile errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRiverInteractive committed Apr 29, 2015
1 parent e1d25fe commit a2b7e60
Show file tree
Hide file tree
Showing 15 changed files with 539 additions and 335 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class InAppPurchases extends UIApplicationDelegateAdapter {
private ParentViewController parentViewController;

@Override
public boolean didFinishLaunching (UIApplication application, UIApplicationLaunchOptions launchOptions) {
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
// Set up the view controller.
parentViewController = new ParentViewController();
rootNavigationController = new UINavigationController(parentViewController);
Expand All @@ -51,21 +51,21 @@ public boolean didFinishLaunching (UIApplication application, UIApplicationLaunc
SKPaymentQueue.getDefaultQueue().addTransactionObserver(StoreObserver.getInstance());

/*
* Retains the window object until the application is deallocated. Prevents Java GC from collecting the window object too
* early.
* Retains the window object until the application is deallocated.
* Prevents Java GC from collecting the window object too early.
*/
addStrongRef(window);

return true;
}

@Override
public void willTerminate (UIApplication application) {
public void willTerminate(UIApplication application) {
// Remove the observer
SKPaymentQueue.getDefaultQueue().removeTransactionObserver(StoreObserver.getInstance());
}

public static void main (String[] args) {
public static void main(String[] args) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(args, null, InAppPurchases.class);
pool.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ public class MyModel {
// List of products/purchases
private final List<Object> elements = new ArrayList<>();

public MyModel (String name, Object... elements) {
public MyModel(String name, Object... elements) {
this.name = name;
if (elements != null) {
Collections.addAll(this.elements, elements);
}
}

// Check whether there are products/purchases
public boolean isEmpty () {
public boolean isEmpty() {
return elements.size() == 0;
}

public String getName () {
public String getName() {
return name;
}

public List<?> getElements () {
public List<?> getElements() {
return elements;
}

public void setElements (List<?> elements) {
public void setElements(List<?> elements) {
this.elements.clear();
this.elements.addAll(elements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum IAPProductRequestStatus {
// Provide the status of the product request
private IAPProductRequestStatus status;

// Keep track of all valid products. These products are available for sale in the App Store
// Keep track of all valid products. These products are available for sale
// in the App Store
private final List<SKProduct> availableProducts = new ArrayList<>();

// Keep track of all invalid product identifiers
Expand All @@ -63,28 +64,34 @@ public enum IAPProductRequestStatus {
// Indicate the cause of the product request failure
private String errorMessage;

private StoreManager () {
}
private StoreManager() {}

public static StoreManager getInstance () {
public static StoreManager getInstance() {
return instance;
}

/** Query the App Store about the given product identifiers
* @param productIds */
public void fetchProductInformationForIds (List<String> productIds) {
// Create a product request object and initialize it with our product identifiers
/**
* Query the App Store about the given product identifiers
*
* @param productIds
*/
public void fetchProductInformationForIds(List<String> productIds) {
// Create a product request object and initialize it with our product
// identifiers
SKProductsRequest request = new SKProductsRequest(new HashSet<String>(productIds));
request.setDelegate(this);

// Send the request to the App Store
request.start();
}

/** @param identifier
* @return the product's title matching a given product identifier */
public String getTitleForId (String identifier) {
// Iterate through availableProducts to find the product whose productIdentifier
/**
* @param identifier
* @return the product's title matching a given product identifier
*/
public String getTitleForId(String identifier) {
// Iterate through availableProducts to find the product whose
// productIdentifier
// property matches identifier, return its localized title when found
for (SKProduct product : availableProducts) {
if (product.getProductIdentifier().equals(identifier)) {
Expand All @@ -96,18 +103,24 @@ public String getTitleForId (String identifier) {

// SKProductsRequestDelegate

/** Used to get the App Store's response to your request and notifies your observer */
/**
* Used to get the App Store's response to your request and notifies your
* observer
*/
@Override
public void didReceiveResponse (SKProductsRequest request, SKProductsResponse response) {
// The products array contains products whose identifiers have been recognized by the App Store.
// As such, they can be purchased. Add them to the availableProducts array.
public void didReceiveResponse(SKProductsRequest request, SKProductsResponse response) {
// The products array contains products whose identifiers have been
// recognized by the App Store.
// As such, they can be purchased. Add them to the availableProducts
// array.
if (response.getProducts().size() > 0) {
availableProducts.addAll(response.getProducts());
status = IAPProductRequestStatus.ProductsFound;
NSNotificationCenter.getDefaultCenter().postNotification(IAPProductRequestNotification, this);
}

// The invalidProductIdentifiers array contains all product identifiers not recognized by the App Store.
// The invalidProductIdentifiers array contains all product identifiers
// not recognized by the App Store.
// Add them to the invalidProducts array.
if (response.getInvalidProductIdentifiers().size() > 0) {
invalidProductIds.addAll(response.getInvalidProductIdentifiers());
Expand All @@ -119,30 +132,30 @@ public void didReceiveResponse (SKProductsRequest request, SKProductsResponse re
// SKRequestDelegate

@Override
public void didFinish (SKRequest request) {
public void didFinish(SKRequest request) {
// ignore
}

/** Called when the product request failed. */
@Override
public void didFail (SKRequest request, NSError error) {
public void didFail(SKRequest request, NSError error) {
// Prints the cause of the product request failure
System.out.println("Product Request Status: " + error.getLocalizedDescription());
}

public List<SKProduct> getAvailableProducts () {
public List<SKProduct> getAvailableProducts() {
return availableProducts;
}

public List<String> getInvalidProductIds () {
public List<String> getInvalidProductIds() {
return invalidProductIds;
}

public IAPProductRequestStatus getStatus () {
public IAPProductRequestStatus getStatus() {
return status;
}

public String getErrorMessage () {
public String getErrorMessage() {
return errorMessage;
}
}
Loading

0 comments on commit a2b7e60

Please sign in to comment.