diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index f183a06adb..2ab49449ed 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
+ Thank you for purchasing full version of OsmAnd!
Hills
Plains
More plains
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index 42e5c0b667..c888634174 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -73,6 +73,7 @@ public class OsmandApplication extends MultiDexApplication {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
public static final String SHOW_PLUS_VERSION_PARAM = "show_plus_version";
+ public static final String SHOW_PLUS_VERSION_INAPP_PARAM = "show_plus_version_inapp";
final AppInitializer appInitializer = new AppInitializer(this);
OsmandSettings osmandSettings = null;
diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
index 1c659c7cb8..b907bf8e7d 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java
@@ -914,6 +914,7 @@ public class OsmandSettings {
public final OsmandPreference BILLING_HIDE_USER_NAME = new BooleanPreference("billing_hide_user_name", false).makeGlobal();
public final OsmandPreference BILLING_PURCHASE_TOKEN_SENT = new BooleanPreference("billing_purchase_token_sent", false).makeGlobal();
public final OsmandPreference LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
+ public final OsmandPreference FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal();
public final OsmandPreference DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
public final OsmandPreference DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
index a2f759207b..1d54cac532 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
@@ -1,11 +1,9 @@
package net.osmand.plus.download;
import android.Manifest;
-import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
@@ -185,7 +183,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
inAppHelper = new InAppHelper(getMyApplication(), true);
inAppHelper.addListener(this);
visibleBanner.setUpdatingPrices(true);
- inAppHelper.start(true);
+ inAppHelper.start(false);
}
final Intent intent = getIntent();
@@ -196,11 +194,23 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // Pass on the activity result to the helper for handling
+ if (inAppHelper == null || !inAppHelper.onActivityResultHandled(requestCode, resultCode, data)) {
+ // not handled, so handle it ourselves (here's where you'd
+ // perform any handling of activity results not related to in-app
+ // billing...
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+ }
+
@Override
public void onDestroy() {
super.onDestroy();
if (inAppHelper != null) {
inAppHelper.removeListener(this);
+ inAppHelper.stop();
}
}
@@ -291,6 +301,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onItemPurchased(String sku) {
+ visibleBanner.setUpdatingPrices(false);
}
@Override
@@ -347,7 +358,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
}
private static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
- return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get())
+ return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get()
+ && !application.getSettings().FULL_VERSION_PURCHASED.get())
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
}
@@ -380,8 +392,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
collapseBanner();
} else {
ctx.getMyApplication().logEvent(ctx, "click_free_dialog");
- new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), "dialog");
- // expandBanner();
+ new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), FreeVersionDialogFragment.TAG);
}
}
};
@@ -438,12 +449,11 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onClick(View v) {
ctx.getMyApplication().logEvent(ctx, "click_buy_plus");
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(
- ctx.getMyApplication()) + "net.osmand.plus"));
- try {
- ctx.startActivity(intent);
- } catch (ActivityNotFoundException e) {
- LOG.error("ActivityNotFoundException", e);
+ ctx.inAppHelper.purchaseFullVersion(ctx);
+ DialogFragment f = (DialogFragment) ctx.getSupportFragmentManager()
+ .findFragmentByTag(FreeVersionDialogFragment.TAG);
+ if (f != null) {
+ f.dismiss();
}
}
});
@@ -489,6 +499,9 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
public void updateFreeVersionBanner() {
if (!shouldShowFreeVersionBanner(ctx.getMyApplication())) {
+ if (freeVersionBanner.getVisibility() == View.VISIBLE) {
+ freeVersionBanner.setVisibility(View.GONE);
+ }
return;
}
setMinimizedFreeVersionBanner(false);
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
index 1a75e5e694..f516fcfd55 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java
@@ -574,8 +574,11 @@ public class DownloadIndexesThread {
}
private boolean validateNotExceedsFreeLimit(IndexItem item) {
- boolean exceed = Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get() &&
- DownloadActivityType.isCountedInDownloads(item) && downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
+ boolean exceed = Version.isFreeVersion(app)
+ && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
+ && !app.getSettings().FULL_VERSION_PURCHASED.get()
+ && DownloadActivityType.isCountedInDownloads(item)
+ && downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
if(exceed) {
String breakDownloadMessage = app.getString(R.string.free_version_message,
DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java b/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java
index 624d9f4115..36cb5733b3 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java
@@ -154,7 +154,8 @@ public class DownloadValidationManager {
}
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
- if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()) {
+ if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get()
+ && !app.getSettings().FULL_VERSION_PURCHASED.get()) {
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
if (context instanceof FragmentActivity) {
diff --git a/OsmAnd/src/net/osmand/plus/download/ui/FreeVersionDialogFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/FreeVersionDialogFragment.java
index 706446ebd9..3ad4037885 100644
--- a/OsmAnd/src/net/osmand/plus/download/ui/FreeVersionDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/download/ui/FreeVersionDialogFragment.java
@@ -13,9 +13,11 @@ import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog;
+import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_INAPP_PARAM;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_PARAM;
public class FreeVersionDialogFragment extends DialogFragment {
+ public static final String TAG = "FreeVersionDialogFragment";
private FreeVersionDialog dialog;
@NonNull
@@ -28,7 +30,7 @@ public class FreeVersionDialogFragment extends DialogFragment {
builder.setNegativeButton(R.string.later, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
- boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_PARAM, false);
+ boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_INAPP_PARAM, true);
view.findViewById(R.id.osmLiveLayoutTopDivider).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
view.findViewById(R.id.fullVersionLayout).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
builder.setView(view);
diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java
index c047a82f1c..0bb469b235 100644
--- a/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java
+++ b/OsmAnd/src/net/osmand/plus/inapp/InAppHelper.java
@@ -36,6 +36,7 @@ public class InAppHelper {
boolean mDebugLog = false;
private static boolean mSubscribedToLiveUpdates = false;
+ private static boolean mFullVersionPurchased = false;
private static String mLiveUpdatesPrice;
private static long lastValidationCheckTime;
private static String mFullVersionPrice;
@@ -79,6 +80,10 @@ public class InAppHelper {
return mSubscribedToLiveUpdates;
}
+ public static boolean isFullVersionPurchased() {
+ return mFullVersionPurchased;
+ }
+
public static String getLiveUpdatesPrice() {
return mLiveUpdatesPrice;
}
@@ -108,7 +113,9 @@ public class InAppHelper {
isDeveloperVersion = Version.isDeveloperVersion(ctx);
if (isDeveloperVersion) {
mSubscribedToLiveUpdates = true;
+ mFullVersionPurchased = true;
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
+ ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
}
}
@@ -214,6 +221,13 @@ public class InAppHelper {
if (mSubscribedToLiveUpdates) {
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
}
+
+ Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE);
+ mFullVersionPurchased = isDeveloperVersion || (fullVersionPurchase != null && fullVersionPurchase.getPurchaseState() == 0);
+ if (mFullVersionPurchased) {
+ ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
+ }
+
lastValidationCheckTime = System.currentTimeMillis();
logDebug("User " + (mSubscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
+ " live updates purchased.");
@@ -270,9 +284,26 @@ public class InAppHelper {
}
};
+ public void purchaseFullVersion(final Activity activity) {
+ 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;
+ }
+
+ logDebug("Launching purchase flow for full version");
+ if (mHelper != null) {
+ mHelper.launchPurchaseFlow(activity,
+ SKU_FULL_VERSION_PRICE, RC_REQUEST, mPurchaseFinishedListener);
+ }
+ }
+
public void purchaseLiveUpdates(final Activity activity, final String email, final String userName,
final String countryDownloadName, final boolean hideUserName) {
- if (!mHelper.subscriptionsSupported()) {
+ 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) {
@@ -420,6 +451,24 @@ public class InAppHelper {
}
});
}
+ if (purchase.getSku().equals(SKU_FULL_VERSION_PRICE)) {
+ // bought full version
+ logDebug("Full version purchased.");
+ sendToken(purchase.getToken(), new OnRequestResultListener() {
+ @Override
+ public void onResult(String result) {
+ showToast(ctx.getString(R.string.full_version_thanks));
+ mFullVersionPurchased = true;
+ ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
+
+ notifyDismissProgress();
+ notifyItemPurchased(SKU_FULL_VERSION_PRICE);
+ if (stopAfterResult) {
+ stop();
+ }
+ }
+ });
+ }
}
};