Search in sources :

Example 1 with PurchaseWithVirtualItem

use of com.soomla.store.purchaseTypes.PurchaseWithVirtualItem in project android-store by soomla.

the class StoreGoodsActivity method onGoodBalanceChanged.

/**
 * Receives the given <code>goodBalanceChangedEvent</code>. Upon notification, fetches the
 * good associated with the given <code>goodBalanceChangedEvent</code> and displays its price
 * and the balance.
 *
 * @param goodBalanceChangedEvent the event received
 */
@Subscribe
public void onGoodBalanceChanged(GoodBalanceChangedEvent goodBalanceChangedEvent) {
    VirtualGood good = null;
    try {
        good = (VirtualGood) StoreInfo.getVirtualItem(goodBalanceChangedEvent.getGoodItemId());
        int id = 0;
        for (int i = 0; i < StoreInfo.getGoods().size(); i++) {
            if (StoreInfo.getGoods().get(i).getItemId().equals(good.getItemId())) {
                id = i;
                break;
            }
        }
        ListView list = (ListView) findViewById(R.id.list);
        TextView info = (TextView) list.getChildAt(id).findViewById(R.id.item_info);
        PurchaseType purchaseType = good.getPurchaseType();
        if (purchaseType instanceof PurchaseWithVirtualItem) {
            info.setText("price: " + ((PurchaseWithVirtualItem) purchaseType).getAmount() + " balance: " + goodBalanceChangedEvent.getBalance());
        }
    } catch (VirtualItemNotFoundException e) {
        SoomlaUtils.LogDebug("StoreGoodsActivity", e.getMessage());
    }
}
Also used : VirtualGood(com.soomla.store.domain.virtualGoods.VirtualGood) PurchaseWithVirtualItem(com.soomla.store.purchaseTypes.PurchaseWithVirtualItem) VirtualItemNotFoundException(com.soomla.store.exceptions.VirtualItemNotFoundException) ListView(android.widget.ListView) PurchaseType(com.soomla.store.purchaseTypes.PurchaseType) TextView(android.widget.TextView) Subscribe(com.squareup.otto.Subscribe)

Example 2 with PurchaseWithVirtualItem

use of com.soomla.store.purchaseTypes.PurchaseWithVirtualItem in project android-store by soomla.

the class PurchasableVirtualItem method toJSONObject.

/**
 * @{inheritDoc}
 */
@Override
public JSONObject toJSONObject() {
    JSONObject parentJsonObject = super.toJSONObject();
    JSONObject jsonObject = new JSONObject();
    try {
        Iterator<?> keys = parentJsonObject.keys();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            jsonObject.put(key, parentJsonObject.get(key));
        }
        JSONObject purchasableObj = new JSONObject();
        if (mPurchaseType instanceof PurchaseWithMarket) {
            purchasableObj.put(StoreJSONConsts.PURCHASE_TYPE, StoreJSONConsts.PURCHASE_TYPE_MARKET);
            MarketItem mi = ((PurchaseWithMarket) mPurchaseType).getMarketItem();
            purchasableObj.put(StoreJSONConsts.PURCHASE_MARKET_ITEM, mi.toJSONObject());
        } else if (mPurchaseType instanceof PurchaseWithVirtualItem) {
            purchasableObj.put(StoreJSONConsts.PURCHASE_TYPE, StoreJSONConsts.PURCHASE_TYPE_VI);
            purchasableObj.put(StoreJSONConsts.PURCHASE_VI_ITEMID, ((PurchaseWithVirtualItem) mPurchaseType).getTargetItemId());
            purchasableObj.put(StoreJSONConsts.PURCHASE_VI_AMOUNT, ((PurchaseWithVirtualItem) mPurchaseType).getAmount());
        }
        jsonObject.put(StoreJSONConsts.PURCHASABLE_ITEM, purchasableObj);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "An error occurred while generating JSON object.");
    }
    return jsonObject;
}
Also used : PurchaseWithVirtualItem(com.soomla.store.purchaseTypes.PurchaseWithVirtualItem) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) PurchaseWithMarket(com.soomla.store.purchaseTypes.PurchaseWithMarket)

Aggregations

PurchaseWithVirtualItem (com.soomla.store.purchaseTypes.PurchaseWithVirtualItem)2 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 VirtualGood (com.soomla.store.domain.virtualGoods.VirtualGood)1 VirtualItemNotFoundException (com.soomla.store.exceptions.VirtualItemNotFoundException)1 PurchaseType (com.soomla.store.purchaseTypes.PurchaseType)1 PurchaseWithMarket (com.soomla.store.purchaseTypes.PurchaseWithMarket)1 Subscribe (com.squareup.otto.Subscribe)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1