/*
     Get purchased items from local storage
  */
  public static ArrayList<StoreItem> readPurchasedItems(ArrayList<StoreItem> items, Context c) {
    SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0);
    String storedItems = settings.getString(PURCHASED_ITEMS_KEYS, "");

    String[] pItems = TextUtils.split(storedItems, "");

    for (int i = 0, j = pItems.length; i < j; i++) {
      for (StoreItem item : items) {
        if (item.googleSKU != null && item.googleSKU.compareTo(pItems[i]) == 0) {
          item.isPurchased = true;
        }
      }
    }

    return items;
  }
        public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

          mHelper.flagEndAsync();

          if (result.isFailure()) {
            updateListener.updateFailed();
            return;
          }

          for (StoreItem item : getAllStoreItems(c)) {
            if (item.googleSKU != null) {
              item.isPurchased = inventory.hasPurchase(item.googleSKU);
            }
          }

          writePurchasedItems(c);

          updateListener.updateSuccess();
        }
  public static ArrayList<StoreItem> getAllStoreItems(Context c, boolean updateFromLocal) {

    if (allStoreItems == null) {
      allStoreItems = new ArrayList<StoreItem>();

      StoreItem item = new StoreItem();
      item.id = ID_GAMES;
      item.title = "No Games";
      item.isPurchased = false;
      item.showOnStore = true;
      item.googleSKU = "no_games";

      allStoreItems.add(item);
    }

    if (updateFromLocal) {
      // update with purchased
      allStoreItems = readPurchasedItems(allStoreItems, c);
    }

    return allStoreItems;
  }
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
          StoreItem purchasedItem = null;
          int index = 0;

          mHelper.flagEndAsync();

          if (purchase == null) {
            Toast.makeText(
                    c,
                    "We can't find the requested item. Please try again soon!",
                    Toast.LENGTH_SHORT)
                .show();
            return;
          }

          for (StoreItem item : getAllStoreItems(c)) {
            if (item.googleSKU.compareTo(purchase.getSku()) == 0) {
              purchasedItem = item;
              break;
            }

            index++;
          }

          if (result.isFailure() || purchasedItem == null) {
            Log.d("FF PURCHASE", "Error purchasing: " + result);
            purchaseListener.purchaseFailed(purchasedItem, purchase);
            return;
          } else {
            purchasedItem.isPurchased = true;
            getAllStoreItems(c).get(index).isPurchased = true;
            purchaseListener.purchaseSuccess(purchasedItem, purchase);
          }

          writePurchasedItems(c);
        }