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());
}
}
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;
}
Aggregations