Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
089b3d5d23
5 changed files with 148 additions and 86 deletions
|
@ -1629,34 +1629,38 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if (inAppHelper != null) {
|
||||
inAppHelper.stop();
|
||||
}
|
||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||
inAppHelper.addListener(new InAppHelper.InAppListener() {
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
inAppHelper = null;
|
||||
}
|
||||
if (Version.isGooglePlayEnabled(app)) {
|
||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||
inAppHelper.addListener(new InAppHelper.InAppListener() {
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
inAppHelper = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetItems() {
|
||||
inAppHelper = null;
|
||||
}
|
||||
@Override
|
||||
public void onGetItems() {
|
||||
inAppHelper = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemPurchased(String sku) {
|
||||
inAppHelper = null;
|
||||
}
|
||||
@Override
|
||||
public void onItemPurchased(String sku) {
|
||||
inAppHelper = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showProgress() {
|
||||
@Override
|
||||
public void showProgress() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissProgress() {
|
||||
@Override
|
||||
public void dismissProgress() {
|
||||
|
||||
}
|
||||
});
|
||||
inAppHelper.exec(runnable);
|
||||
return inAppHelper;
|
||||
}
|
||||
});
|
||||
inAppHelper.exec(runnable);
|
||||
return inAppHelper;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,9 +223,11 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
|||
public void startInAppHelper() {
|
||||
stopInAppHelper();
|
||||
|
||||
inAppHelper = new InAppHelper(getMyApplication(), true);
|
||||
inAppHelper.addListener(this);
|
||||
inAppHelper.start(false);
|
||||
if (Version.isGooglePlayEnabled(getMyApplication())) {
|
||||
inAppHelper = new InAppHelper(getMyApplication(), true);
|
||||
inAppHelper.addListener(this);
|
||||
inAppHelper.start(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopInAppHelper() {
|
||||
|
|
|
@ -198,26 +198,33 @@ public class InAppHelper {
|
|||
// Start setup. This is asynchronous and the specified listener
|
||||
// will be called once setup completes.
|
||||
logDebug("Starting setup.");
|
||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||
public void onIabSetupFinished(IabResult result) {
|
||||
logDebug("Setup finished.");
|
||||
try {
|
||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||
public void onIabSetupFinished(IabResult result) {
|
||||
logDebug("Setup finished.");
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
// Oh noes, there was a problem.
|
||||
complain("Problem setting up in-app billing: " + result);
|
||||
notifyError(result.getMessage());
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
if (!result.isSuccess()) {
|
||||
// Oh noes, there was a problem.
|
||||
//complain("Problem setting up in-app billing: " + result);
|
||||
notifyError(result.getMessage());
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (mHelper == null) return;
|
||||
|
||||
runnable.run(InAppHelper.this);
|
||||
}
|
||||
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (mHelper == null) return;
|
||||
|
||||
runnable.run(InAppHelper.this);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logError("exec Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void start(final boolean stopAfterResult) {
|
||||
|
@ -233,43 +240,58 @@ public class InAppHelper {
|
|||
// Start setup. This is asynchronous and the specified listener
|
||||
// will be called once setup completes.
|
||||
logDebug("Starting setup.");
|
||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||
public void onIabSetupFinished(IabResult result) {
|
||||
logDebug("Setup finished.");
|
||||
try {
|
||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||
public void onIabSetupFinished(IabResult result) {
|
||||
logDebug("Setup finished.");
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
// Oh noes, there was a problem.
|
||||
complain("Problem setting up in-app billing: " + result);
|
||||
notifyError(result.getMessage());
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
if (!result.isSuccess()) {
|
||||
// Oh noes, there was a problem.
|
||||
//complain("Problem setting up in-app billing: " + result);
|
||||
notifyError(result.getMessage());
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (mHelper == null) return;
|
||||
// Have we been disposed of in the meantime? If so, quit.
|
||||
if (mHelper == null) return;
|
||||
|
||||
// IAB is fully set up. Now, let's get an inventory of stuff we own if needed.
|
||||
if (forceRequestInventory || (!isDeveloperVersion &&
|
||||
(!mSubscribedToLiveUpdates
|
||||
|| !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get()
|
||||
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC))) {
|
||||
// IAB is fully set up. Now, let's get an inventory of stuff we own if needed.
|
||||
if (forceRequestInventory || (!isDeveloperVersion &&
|
||||
(!mSubscribedToLiveUpdates
|
||||
|| !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get()
|
||||
|| System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC))) {
|
||||
|
||||
logDebug("Setup successful. Querying inventory.");
|
||||
List<String> skus = new ArrayList<>();
|
||||
skus.add(SKU_LIVE_UPDATES);
|
||||
skus.add(SKU_DEPTH_CONTOURS);
|
||||
skus.add(SKU_FULL_VERSION_PRICE);
|
||||
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
|
||||
} else {
|
||||
notifyDismissProgress();
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
logDebug("Setup successful. Querying inventory.");
|
||||
List<String> skus = new ArrayList<>();
|
||||
skus.add(SKU_LIVE_UPDATES);
|
||||
skus.add(SKU_DEPTH_CONTOURS);
|
||||
skus.add(SKU_FULL_VERSION_PRICE);
|
||||
try {
|
||||
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
|
||||
} catch (Exception e) {
|
||||
logError("queryInventoryAsync Error", e);
|
||||
notifyDismissProgress();
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notifyDismissProgress();
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logError("start Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Listener that's called when we finish querying the items and subscriptions we own
|
||||
|
@ -380,7 +402,7 @@ public class InAppHelper {
|
|||
|
||||
public void purchaseFullVersion(final Activity activity) {
|
||||
if (mHelper == null) {
|
||||
complain("In-app hepler is not initialized!");
|
||||
//complain("In-app hepler is not initialized!");
|
||||
notifyError("In-app hepler is not initialized!");
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
|
@ -390,14 +412,22 @@ public class InAppHelper {
|
|||
|
||||
logDebug("Launching purchase flow for full version");
|
||||
if (mHelper != null) {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_FULL_VERSION_PRICE, RC_REQUEST, mPurchaseFinishedListener);
|
||||
try {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_FULL_VERSION_PRICE, RC_REQUEST, mPurchaseFinishedListener);
|
||||
} catch (Exception e) {
|
||||
complain("Cannot launch full version purchase!");
|
||||
logError("purchaseFullVersion Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void purchaseDepthContours(final Activity activity) {
|
||||
if (mHelper == null) {
|
||||
complain("In-app hepler is not initialized!");
|
||||
//complain("In-app hepler is not initialized!");
|
||||
notifyError("In-app hepler is not initialized!");
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
|
@ -407,16 +437,32 @@ public class InAppHelper {
|
|||
|
||||
logDebug("Launching purchase flow for sea depth contours");
|
||||
if (mHelper != null) {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_DEPTH_CONTOURS, RC_REQUEST, mPurchaseFinishedListener);
|
||||
try {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_DEPTH_CONTOURS, RC_REQUEST, mPurchaseFinishedListener);
|
||||
} catch (Exception e) {
|
||||
complain("Cannot launch depth contours purchase!");
|
||||
logError("purchaseDepthContours Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void purchaseLiveUpdates(final Activity activity, final String email, final String userName,
|
||||
final String countryDownloadName, final boolean hideUserName) {
|
||||
if (mHelper == null || !mHelper.subscriptionsSupported()) {
|
||||
complain("Subscriptions not supported on your device yet. Sorry!");
|
||||
notifyError("Subscriptions not supported on your device yet. Sorry!");
|
||||
try {
|
||||
if (mHelper == null || !mHelper.subscriptionsSupported()) {
|
||||
complain("Subscriptions not supported on your device yet. Sorry!");
|
||||
notifyError("Subscriptions not supported on your device yet. Sorry!");
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logError("purchaseLiveUpdates Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
|
@ -488,9 +534,16 @@ public class InAppHelper {
|
|||
logDebug("Launching purchase flow for live updates subscription for userId=" + userId);
|
||||
String payload = userId + " " + token;
|
||||
if (mHelper != null) {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_LIVE_UPDATES, IabHelper.ITEM_TYPE_SUBS,
|
||||
RC_REQUEST, mPurchaseFinishedListener, payload);
|
||||
try {
|
||||
mHelper.launchPurchaseFlow(activity,
|
||||
SKU_LIVE_UPDATES, IabHelper.ITEM_TYPE_SUBS,
|
||||
RC_REQUEST, mPurchaseFinishedListener, payload);
|
||||
} catch (Exception e) {
|
||||
logError("launchPurchaseFlow Error", e);
|
||||
if (stopAfterResult) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notifyError("Empty userId");
|
||||
|
|
|
@ -36,7 +36,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_livie_updates);
|
||||
|
||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||
if (Version.isGooglePlayEnabled(getMyApplication())) {
|
||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||
}
|
||||
if (Version.isDeveloperVersion(getMyApplication())) {
|
||||
inAppHelper = null;
|
||||
}
|
||||
|
|
|
@ -214,7 +214,8 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
saveChangesButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (applySettings(userNameEdit.getText().toString().trim(),
|
||||
InAppHelper helper = getInAppHelper();
|
||||
if (helper != null && applySettings(userNameEdit.getText().toString().trim(),
|
||||
emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
|
||||
|
||||
final Map<String, String> parameters = new HashMap<>();
|
||||
|
@ -223,7 +224,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
parameters.put("email", settings.BILLING_USER_EMAIL.get());
|
||||
parameters.put("cemail", prevEmail);
|
||||
parameters.put("userid", settings.BILLING_USER_ID.get());
|
||||
parameters.put("token", getInAppHelper().getToken());
|
||||
parameters.put("token", helper.getToken());
|
||||
|
||||
showProgress();
|
||||
|
||||
|
|
Loading…
Reference in a new issue