This commit is contained in:
Alexey Kulish 2017-04-29 12:04:39 +03:00
parent 2f411cadde
commit 7fba3e4a3b
5 changed files with 148 additions and 86 deletions

View file

@ -1629,6 +1629,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (inAppHelper != null) {
inAppHelper.stop();
}
if (Version.isGooglePlayEnabled(app)) {
inAppHelper = new InAppHelper(getMyApplication(), false);
inAppHelper.addListener(new InAppHelper.InAppListener() {
@Override
@ -1658,5 +1659,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
});
inAppHelper.exec(runnable);
return inAppHelper;
} else {
return null;
}
}
}

View file

@ -222,10 +222,12 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
public void startInAppHelper() {
stopInAppHelper();
if (Version.isGooglePlayEnabled(getMyApplication())) {
inAppHelper = new InAppHelper(getMyApplication(), true);
inAppHelper.addListener(this);
inAppHelper.start(false);
}
}
public void stopInAppHelper() {
if (inAppHelper != null) {

View file

@ -198,13 +198,14 @@ public class InAppHelper {
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
logDebug("Starting setup.");
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);
//complain("Problem setting up in-app billing: " + result);
notifyError(result.getMessage());
if (stopAfterResult) {
stop();
@ -218,6 +219,12 @@ public class InAppHelper {
runnable.run(InAppHelper.this);
}
});
} catch (Exception e) {
logError("exec Error", e);
if (stopAfterResult) {
stop();
}
}
}
public void start(final boolean stopAfterResult) {
@ -233,13 +240,14 @@ public class InAppHelper {
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
logDebug("Starting setup.");
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);
//complain("Problem setting up in-app billing: " + result);
notifyError(result.getMessage());
if (stopAfterResult) {
stop();
@ -261,7 +269,15 @@ public class InAppHelper {
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) {
@ -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
@ -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) {
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,13 +437,22 @@ public class InAppHelper {
logDebug("Launching purchase flow for sea depth contours");
if (mHelper != null) {
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) {
try {
if (mHelper == null || !mHelper.subscriptionsSupported()) {
complain("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;
}
} catch (Exception e) {
logError("purchaseLiveUpdates Error", e);
if (stopAfterResult) {
stop();
}
return;
}
notifyShowProgress();
@ -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) {
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");

View file

@ -36,7 +36,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_livie_updates);
if (Version.isGooglePlayEnabled(getMyApplication())) {
inAppHelper = new InAppHelper(getMyApplication(), false);
}
if (Version.isDeveloperVersion(getMyApplication())) {
inAppHelper = null;
}

View file

@ -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();