use of com.soomla.store.exceptions.InsufficientFundsException in project android-store by soomla.
the class StorePacksActivity method onCreate.
/**
* Called when the activity starts.
*
* @param savedInstanceState if the activity should be re-initialized after previously being
* shut down then this <code>Bundle</code> will contain the most
* recent data, otherwise it will be null.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
LinearLayout getMore = (LinearLayout) findViewById(R.id.getMore);
TextView title = (TextView) findViewById(R.id.title);
getMore.setVisibility(View.INVISIBLE);
title.setText("Virtual Currency Packs");
mImages = generateImagesHash();
mStoreAdapter = new StoreAdapter();
/* configuring the list with an adapter */
final Activity activity = this;
ListView list = (ListView) findViewById(R.id.list);
list.setAdapter(mStoreAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
/*
* The user decided to make an actual purchase of virtual goods. We try to buy() the
* user's desired good and SoomlaStore tells us if the user has enough funds to
* make the purchase. If he/she doesn't have enough then an
* InsufficientFundsException will be thrown.
*/
PurchaseWithMarket pwm = null;
VirtualCurrencyPack pack = StoreInfo.getCurrencyPacks().get(i);
pwm = (PurchaseWithMarket) pack.getPurchaseType();
try {
pwm.buy("this is just a payload");
} catch (InsufficientFundsException e) {
AlertDialog ad = new AlertDialog.Builder(activity).create();
// This blocks the 'BACK' button
ad.setCancelable(false);
ad.setMessage("Can't continue with purchase (You don't have enough muffins !)");
ad.setButton(DialogInterface.BUTTON_NEGATIVE, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
}
/* fetching the currency balance and placing it in the balance label */
TextView muffinsBalance = (TextView) activity.findViewById(R.id.balance);
muffinsBalance.setText("" + StorageManager.getVirtualCurrencyStorage().getBalance(StoreInfo.getCurrencies().get(0).getItemId()));
}
});
}
use of com.soomla.store.exceptions.InsufficientFundsException in project android-store by soomla.
the class PurchaseWithVirtualItem method buy.
/**
* Buys the virtual item with other virtual items.
*
* @throws InsufficientFundsException
*/
@Override
public void buy(String payload) throws InsufficientFundsException {
SoomlaUtils.LogDebug(TAG, "Trying to buy a " + getAssociatedItem().getName() + " with " + mAmount + " pieces of " + mTargetItemId);
VirtualItem item = null;
try {
item = StoreInfo.getVirtualItem(mTargetItemId);
} catch (VirtualItemNotFoundException e) {
SoomlaUtils.LogError(TAG, "Target virtual item doesn't exist !");
return;
}
BusProvider.getInstance().post(new ItemPurchaseStartedEvent(getAssociatedItem().getItemId()));
VirtualItemStorage storage = StorageManager.getVirtualItemStorage(item);
assert storage != null;
int balance = storage.getBalance(item.getItemId());
if (balance < mAmount) {
throw new InsufficientFundsException(mTargetItemId);
}
storage.remove(item.getItemId(), mAmount);
getAssociatedItem().give(1);
BusProvider.getInstance().post(new ItemPurchasedEvent(getAssociatedItem().getItemId(), payload));
}
use of com.soomla.store.exceptions.InsufficientFundsException in project android-store by soomla.
the class StoreGoodsActivity method onCreate.
/**
* Called when the activity starts.
* Displays the list view of the game, where users can see the available goods for purchase.
*
* @param savedInstanceState if the activity should be re-initialized after previously being
* shut down then this <code>Bundle</code> will contain the most
* recent data, otherwise it will be null.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
SoomlaStore.getInstance().startIabServiceInBg();
TextView title = (TextView) findViewById(R.id.title);
title.setText("Virtual Goods");
mImages = generateImagesHash();
mStoreAdapter = new StoreAdapter();
/* configuring the list with an adapter */
final Activity activity = this;
ListView list = (ListView) findViewById(R.id.list);
list.setAdapter(mStoreAdapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
/*
The user decided to make an actual purchase of virtual goods. We try to buy() the
user's desired good and SoomlaStore tells us if the user has enough funds to
make the purchase. If he/she doesn't have enough then an InsufficientFundsException
will be thrown.
*/
VirtualGood good = StoreInfo.getGoods().get(i);
try {
good.buy("this is just a payload");
} catch (InsufficientFundsException e) {
AlertDialog ad = new AlertDialog.Builder(activity).create();
ad.setCancelable(false);
ad.setMessage("You don't have enough muffins.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
ad.show();
}
}
});
}
Aggregations