use of net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseInitCallback in project Osmand by osmandapp.
the class OsmandInAppPurchaseActivity method initInAppPurchaseHelper.
private void initInAppPurchaseHelper() {
deinitInAppPurchaseHelper();
OsmandApplication app = getMyApplication();
OsmandSettings settings = app.getSettings();
if (purchaseHelper == null) {
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (settings.isInternetConnectionAvailable() && isInAppPurchaseAllowed() && Version.isInAppPurchaseSupported()) {
this.purchaseHelper = purchaseHelper;
}
}
if (purchaseHelper != null) {
final WeakReference<OsmandInAppPurchaseActivity> activityRef = new WeakReference<>(this);
purchaseHelper.isInAppPurchaseSupported(this, new InAppPurchaseInitCallback() {
@Override
public void onSuccess() {
OsmandInAppPurchaseActivity activity = activityRef.get();
if (!activityDestroyed && AndroidUtils.isActivityNotDestroyed(activity)) {
purchaseHelper.setUiActivity(activity);
if (purchaseHelper.needRequestInventory()) {
purchaseHelper.requestInventory(false);
}
}
}
@Override
public void onFail() {
}
});
} else if (isInAppPurchaseAllowed() && settings.isInternetConnectionAvailable()) {
InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper();
if (purchaseHelper != null && purchaseHelper.needRequestPromo()) {
purchaseHelper.checkPromoAsync(null);
}
}
}
Aggregations