Fix #3718
This commit is contained in:
parent
2f411cadde
commit
7fba3e4a3b
5 changed files with 148 additions and 86 deletions
|
@ -1629,6 +1629,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
if (inAppHelper != null) {
|
if (inAppHelper != null) {
|
||||||
inAppHelper.stop();
|
inAppHelper.stop();
|
||||||
}
|
}
|
||||||
|
if (Version.isGooglePlayEnabled(app)) {
|
||||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||||
inAppHelper.addListener(new InAppHelper.InAppListener() {
|
inAppHelper.addListener(new InAppHelper.InAppListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1658,5 +1659,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
});
|
});
|
||||||
inAppHelper.exec(runnable);
|
inAppHelper.exec(runnable);
|
||||||
return inAppHelper;
|
return inAppHelper;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,10 +222,12 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
public void startInAppHelper() {
|
public void startInAppHelper() {
|
||||||
stopInAppHelper();
|
stopInAppHelper();
|
||||||
|
|
||||||
|
if (Version.isGooglePlayEnabled(getMyApplication())) {
|
||||||
inAppHelper = new InAppHelper(getMyApplication(), true);
|
inAppHelper = new InAppHelper(getMyApplication(), true);
|
||||||
inAppHelper.addListener(this);
|
inAppHelper.addListener(this);
|
||||||
inAppHelper.start(false);
|
inAppHelper.start(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stopInAppHelper() {
|
public void stopInAppHelper() {
|
||||||
if (inAppHelper != null) {
|
if (inAppHelper != null) {
|
||||||
|
|
|
@ -198,13 +198,14 @@ public class InAppHelper {
|
||||||
// Start setup. This is asynchronous and the specified listener
|
// Start setup. This is asynchronous and the specified listener
|
||||||
// will be called once setup completes.
|
// will be called once setup completes.
|
||||||
logDebug("Starting setup.");
|
logDebug("Starting setup.");
|
||||||
|
try {
|
||||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||||
public void onIabSetupFinished(IabResult result) {
|
public void onIabSetupFinished(IabResult result) {
|
||||||
logDebug("Setup finished.");
|
logDebug("Setup finished.");
|
||||||
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
// Oh noes, there was a problem.
|
// Oh noes, there was a problem.
|
||||||
complain("Problem setting up in-app billing: " + result);
|
//complain("Problem setting up in-app billing: " + result);
|
||||||
notifyError(result.getMessage());
|
notifyError(result.getMessage());
|
||||||
if (stopAfterResult) {
|
if (stopAfterResult) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -218,6 +219,12 @@ public class InAppHelper {
|
||||||
runnable.run(InAppHelper.this);
|
runnable.run(InAppHelper.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
logError("exec Error", e);
|
||||||
|
if (stopAfterResult) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(final boolean stopAfterResult) {
|
public void start(final boolean stopAfterResult) {
|
||||||
|
@ -233,13 +240,14 @@ public class InAppHelper {
|
||||||
// Start setup. This is asynchronous and the specified listener
|
// Start setup. This is asynchronous and the specified listener
|
||||||
// will be called once setup completes.
|
// will be called once setup completes.
|
||||||
logDebug("Starting setup.");
|
logDebug("Starting setup.");
|
||||||
|
try {
|
||||||
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
|
||||||
public void onIabSetupFinished(IabResult result) {
|
public void onIabSetupFinished(IabResult result) {
|
||||||
logDebug("Setup finished.");
|
logDebug("Setup finished.");
|
||||||
|
|
||||||
if (!result.isSuccess()) {
|
if (!result.isSuccess()) {
|
||||||
// Oh noes, there was a problem.
|
// Oh noes, there was a problem.
|
||||||
complain("Problem setting up in-app billing: " + result);
|
//complain("Problem setting up in-app billing: " + result);
|
||||||
notifyError(result.getMessage());
|
notifyError(result.getMessage());
|
||||||
if (stopAfterResult) {
|
if (stopAfterResult) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -261,7 +269,15 @@ public class InAppHelper {
|
||||||
skus.add(SKU_LIVE_UPDATES);
|
skus.add(SKU_LIVE_UPDATES);
|
||||||
skus.add(SKU_DEPTH_CONTOURS);
|
skus.add(SKU_DEPTH_CONTOURS);
|
||||||
skus.add(SKU_FULL_VERSION_PRICE);
|
skus.add(SKU_FULL_VERSION_PRICE);
|
||||||
|
try {
|
||||||
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
|
mHelper.queryInventoryAsync(true, skus, mGotInventoryListener);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logError("queryInventoryAsync Error", e);
|
||||||
|
notifyDismissProgress();
|
||||||
|
if (stopAfterResult) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
notifyDismissProgress();
|
notifyDismissProgress();
|
||||||
if (stopAfterResult) {
|
if (stopAfterResult) {
|
||||||
|
@ -270,6 +286,12 @@ public class InAppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
logError("start Error", e);
|
||||||
|
if (stopAfterResult) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listener that's called when we finish querying the items and subscriptions we own
|
// 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) {
|
public void purchaseFullVersion(final Activity activity) {
|
||||||
if (mHelper == null) {
|
if (mHelper == null) {
|
||||||
complain("In-app hepler is not initialized!");
|
//complain("In-app hepler is not initialized!");
|
||||||
notifyError("In-app hepler is not initialized!");
|
notifyError("In-app hepler is not initialized!");
|
||||||
if (stopAfterResult) {
|
if (stopAfterResult) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -390,14 +412,22 @@ public class InAppHelper {
|
||||||
|
|
||||||
logDebug("Launching purchase flow for full version");
|
logDebug("Launching purchase flow for full version");
|
||||||
if (mHelper != null) {
|
if (mHelper != null) {
|
||||||
|
try {
|
||||||
mHelper.launchPurchaseFlow(activity,
|
mHelper.launchPurchaseFlow(activity,
|
||||||
SKU_FULL_VERSION_PRICE, RC_REQUEST, mPurchaseFinishedListener);
|
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) {
|
public void purchaseDepthContours(final Activity activity) {
|
||||||
if (mHelper == null) {
|
if (mHelper == null) {
|
||||||
complain("In-app hepler is not initialized!");
|
//complain("In-app hepler is not initialized!");
|
||||||
notifyError("In-app hepler is not initialized!");
|
notifyError("In-app hepler is not initialized!");
|
||||||
if (stopAfterResult) {
|
if (stopAfterResult) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -407,13 +437,22 @@ public class InAppHelper {
|
||||||
|
|
||||||
logDebug("Launching purchase flow for sea depth contours");
|
logDebug("Launching purchase flow for sea depth contours");
|
||||||
if (mHelper != null) {
|
if (mHelper != null) {
|
||||||
|
try {
|
||||||
mHelper.launchPurchaseFlow(activity,
|
mHelper.launchPurchaseFlow(activity,
|
||||||
SKU_DEPTH_CONTOURS, RC_REQUEST, mPurchaseFinishedListener);
|
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,
|
public void purchaseLiveUpdates(final Activity activity, final String email, final String userName,
|
||||||
final String countryDownloadName, final boolean hideUserName) {
|
final String countryDownloadName, final boolean hideUserName) {
|
||||||
|
try {
|
||||||
if (mHelper == null || !mHelper.subscriptionsSupported()) {
|
if (mHelper == null || !mHelper.subscriptionsSupported()) {
|
||||||
complain("Subscriptions not supported on your device yet. Sorry!");
|
complain("Subscriptions not supported on your device yet. Sorry!");
|
||||||
notifyError("Subscriptions not supported on your device yet. Sorry!");
|
notifyError("Subscriptions not supported on your device yet. Sorry!");
|
||||||
|
@ -422,6 +461,13 @@ public class InAppHelper {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logError("purchaseLiveUpdates Error", e);
|
||||||
|
if (stopAfterResult) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
notifyShowProgress();
|
notifyShowProgress();
|
||||||
|
|
||||||
|
@ -488,9 +534,16 @@ public class InAppHelper {
|
||||||
logDebug("Launching purchase flow for live updates subscription for userId=" + userId);
|
logDebug("Launching purchase flow for live updates subscription for userId=" + userId);
|
||||||
String payload = userId + " " + token;
|
String payload = userId + " " + token;
|
||||||
if (mHelper != null) {
|
if (mHelper != null) {
|
||||||
|
try {
|
||||||
mHelper.launchPurchaseFlow(activity,
|
mHelper.launchPurchaseFlow(activity,
|
||||||
SKU_LIVE_UPDATES, IabHelper.ITEM_TYPE_SUBS,
|
SKU_LIVE_UPDATES, IabHelper.ITEM_TYPE_SUBS,
|
||||||
RC_REQUEST, mPurchaseFinishedListener, payload);
|
RC_REQUEST, mPurchaseFinishedListener, payload);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logError("launchPurchaseFlow Error", e);
|
||||||
|
if (stopAfterResult) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
notifyError("Empty userId");
|
notifyError("Empty userId");
|
||||||
|
|
|
@ -36,7 +36,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_livie_updates);
|
setContentView(R.layout.activity_livie_updates);
|
||||||
|
|
||||||
|
if (Version.isGooglePlayEnabled(getMyApplication())) {
|
||||||
inAppHelper = new InAppHelper(getMyApplication(), false);
|
inAppHelper = new InAppHelper(getMyApplication(), false);
|
||||||
|
}
|
||||||
if (Version.isDeveloperVersion(getMyApplication())) {
|
if (Version.isDeveloperVersion(getMyApplication())) {
|
||||||
inAppHelper = null;
|
inAppHelper = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,7 +214,8 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
||||||
saveChangesButton.setOnClickListener(new View.OnClickListener() {
|
saveChangesButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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())) {
|
emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
|
||||||
|
|
||||||
final Map<String, String> parameters = new HashMap<>();
|
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("email", settings.BILLING_USER_EMAIL.get());
|
||||||
parameters.put("cemail", prevEmail);
|
parameters.put("cemail", prevEmail);
|
||||||
parameters.put("userid", settings.BILLING_USER_ID.get());
|
parameters.put("userid", settings.BILLING_USER_ID.get());
|
||||||
parameters.put("token", getInAppHelper().getToken());
|
parameters.put("token", helper.getToken());
|
||||||
|
|
||||||
showProgress();
|
showProgress();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue