Added inapp
This commit is contained in:
parent
6cc2bb534c
commit
333acbee8b
8 changed files with 88 additions and 17 deletions
|
@ -9,6 +9,7 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
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
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="full_version_thanks">Thank you for purchasing full version of OsmAnd!</string>
|
||||||
<string name="routing_attr_relief_smoothness_factor_hills_name">Hills</string>
|
<string name="routing_attr_relief_smoothness_factor_hills_name">Hills</string>
|
||||||
<string name="routing_attr_relief_smoothness_factor_plains_name">Plains</string>
|
<string name="routing_attr_relief_smoothness_factor_plains_name">Plains</string>
|
||||||
<string name="routing_attr_relief_smoothness_factor_more_plains_name">More plains</string>
|
<string name="routing_attr_relief_smoothness_factor_more_plains_name">More plains</string>
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
|
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_PARAM = "show_plus_version";
|
||||||
|
public static final String SHOW_PLUS_VERSION_INAPP_PARAM = "show_plus_version_inapp";
|
||||||
|
|
||||||
final AppInitializer appInitializer = new AppInitializer(this);
|
final AppInitializer appInitializer = new AppInitializer(this);
|
||||||
OsmandSettings osmandSettings = null;
|
OsmandSettings osmandSettings = null;
|
||||||
|
|
|
@ -914,6 +914,7 @@ public class OsmandSettings {
|
||||||
public final OsmandPreference<Boolean> BILLING_HIDE_USER_NAME = new BooleanPreference("billing_hide_user_name", false).makeGlobal();
|
public final OsmandPreference<Boolean> BILLING_HIDE_USER_NAME = new BooleanPreference("billing_hide_user_name", false).makeGlobal();
|
||||||
public final OsmandPreference<Boolean> BILLING_PURCHASE_TOKEN_SENT = new BooleanPreference("billing_purchase_token_sent", false).makeGlobal();
|
public final OsmandPreference<Boolean> BILLING_PURCHASE_TOKEN_SENT = new BooleanPreference("billing_purchase_token_sent", false).makeGlobal();
|
||||||
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
|
public final OsmandPreference<Boolean> LIVE_UPDATES_PURCHASED = new BooleanPreference("billing_live_updates_purchased", false).makeGlobal();
|
||||||
|
public final OsmandPreference<Boolean> FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal();
|
||||||
|
|
||||||
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
|
public final OsmandPreference<Integer> DISCOUNT_ID = new IntPreference("discount_id", 0).makeGlobal();
|
||||||
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();
|
public final OsmandPreference<Integer> DISCOUNT_SHOW_NUMBER_OF_STARTS = new IntPreference("number_of_starts_on_discount_show", 0).makeGlobal();
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
|
@ -185,7 +183,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
inAppHelper = new InAppHelper(getMyApplication(), true);
|
inAppHelper = new InAppHelper(getMyApplication(), true);
|
||||||
inAppHelper.addListener(this);
|
inAppHelper.addListener(this);
|
||||||
visibleBanner.setUpdatingPrices(true);
|
visibleBanner.setUpdatingPrices(true);
|
||||||
inAppHelper.start(true);
|
inAppHelper.start(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
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
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (inAppHelper != null) {
|
if (inAppHelper != null) {
|
||||||
inAppHelper.removeListener(this);
|
inAppHelper.removeListener(this);
|
||||||
|
inAppHelper.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,6 +301,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemPurchased(String sku) {
|
public void onItemPurchased(String sku) {
|
||||||
|
visibleBanner.setUpdatingPrices(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -347,7 +358,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldShowFreeVersionBanner(OsmandApplication application) {
|
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();
|
|| application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,8 +392,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
collapseBanner();
|
collapseBanner();
|
||||||
} else {
|
} else {
|
||||||
ctx.getMyApplication().logEvent(ctx, "click_free_dialog");
|
ctx.getMyApplication().logEvent(ctx, "click_free_dialog");
|
||||||
new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), "dialog");
|
new FreeVersionDialogFragment().show(ctx.getSupportFragmentManager(), FreeVersionDialogFragment.TAG);
|
||||||
// expandBanner();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -438,12 +449,11 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ctx.getMyApplication().logEvent(ctx, "click_buy_plus");
|
ctx.getMyApplication().logEvent(ctx, "click_buy_plus");
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Version.marketPrefix(
|
ctx.inAppHelper.purchaseFullVersion(ctx);
|
||||||
ctx.getMyApplication()) + "net.osmand.plus"));
|
DialogFragment f = (DialogFragment) ctx.getSupportFragmentManager()
|
||||||
try {
|
.findFragmentByTag(FreeVersionDialogFragment.TAG);
|
||||||
ctx.startActivity(intent);
|
if (f != null) {
|
||||||
} catch (ActivityNotFoundException e) {
|
f.dismiss();
|
||||||
LOG.error("ActivityNotFoundException", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -489,6 +499,9 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
||||||
|
|
||||||
public void updateFreeVersionBanner() {
|
public void updateFreeVersionBanner() {
|
||||||
if (!shouldShowFreeVersionBanner(ctx.getMyApplication())) {
|
if (!shouldShowFreeVersionBanner(ctx.getMyApplication())) {
|
||||||
|
if (freeVersionBanner.getVisibility() == View.VISIBLE) {
|
||||||
|
freeVersionBanner.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setMinimizedFreeVersionBanner(false);
|
setMinimizedFreeVersionBanner(false);
|
||||||
|
|
|
@ -574,8 +574,11 @@ public class DownloadIndexesThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateNotExceedsFreeLimit(IndexItem item) {
|
private boolean validateNotExceedsFreeLimit(IndexItem item) {
|
||||||
boolean exceed = Version.isFreeVersion(app) && !app.getSettings().LIVE_UPDATES_PURCHASED.get() &&
|
boolean exceed = Version.isFreeVersion(app)
|
||||||
DownloadActivityType.isCountedInDownloads(item) && downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
&& !app.getSettings().LIVE_UPDATES_PURCHASED.get()
|
||||||
|
&& !app.getSettings().FULL_VERSION_PURCHASED.get()
|
||||||
|
&& DownloadActivityType.isCountedInDownloads(item)
|
||||||
|
&& downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS;
|
||||||
if(exceed) {
|
if(exceed) {
|
||||||
String breakDownloadMessage = app.getString(R.string.free_version_message,
|
String breakDownloadMessage = app.getString(R.string.free_version_message,
|
||||||
DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
|
DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
|
||||||
|
|
|
@ -154,7 +154,8 @@ public class DownloadValidationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) {
|
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();
|
int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
|
||||||
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
|
if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) {
|
||||||
if (context instanceof FragmentActivity) {
|
if (context instanceof FragmentActivity) {
|
||||||
|
|
|
@ -13,9 +13,11 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.download.DownloadActivity;
|
import net.osmand.plus.download.DownloadActivity;
|
||||||
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog;
|
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;
|
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_PARAM;
|
||||||
|
|
||||||
public class FreeVersionDialogFragment extends DialogFragment {
|
public class FreeVersionDialogFragment extends DialogFragment {
|
||||||
|
public static final String TAG = "FreeVersionDialogFragment";
|
||||||
private FreeVersionDialog dialog;
|
private FreeVersionDialog dialog;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -28,7 +30,7 @@ public class FreeVersionDialogFragment extends DialogFragment {
|
||||||
builder.setNegativeButton(R.string.later, null);
|
builder.setNegativeButton(R.string.later, null);
|
||||||
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, 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.osmLiveLayoutTopDivider).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
|
||||||
view.findViewById(R.id.fullVersionLayout).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
|
view.findViewById(R.id.fullVersionLayout).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
|
||||||
builder.setView(view);
|
builder.setView(view);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class InAppHelper {
|
||||||
boolean mDebugLog = false;
|
boolean mDebugLog = false;
|
||||||
|
|
||||||
private static boolean mSubscribedToLiveUpdates = false;
|
private static boolean mSubscribedToLiveUpdates = false;
|
||||||
|
private static boolean mFullVersionPurchased = false;
|
||||||
private static String mLiveUpdatesPrice;
|
private static String mLiveUpdatesPrice;
|
||||||
private static long lastValidationCheckTime;
|
private static long lastValidationCheckTime;
|
||||||
private static String mFullVersionPrice;
|
private static String mFullVersionPrice;
|
||||||
|
@ -79,6 +80,10 @@ public class InAppHelper {
|
||||||
return mSubscribedToLiveUpdates;
|
return mSubscribedToLiveUpdates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFullVersionPurchased() {
|
||||||
|
return mFullVersionPurchased;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getLiveUpdatesPrice() {
|
public static String getLiveUpdatesPrice() {
|
||||||
return mLiveUpdatesPrice;
|
return mLiveUpdatesPrice;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +113,9 @@ public class InAppHelper {
|
||||||
isDeveloperVersion = Version.isDeveloperVersion(ctx);
|
isDeveloperVersion = Version.isDeveloperVersion(ctx);
|
||||||
if (isDeveloperVersion) {
|
if (isDeveloperVersion) {
|
||||||
mSubscribedToLiveUpdates = true;
|
mSubscribedToLiveUpdates = true;
|
||||||
|
mFullVersionPurchased = true;
|
||||||
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
|
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
|
||||||
|
ctx.getSettings().FULL_VERSION_PURCHASED.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,6 +221,13 @@ public class InAppHelper {
|
||||||
if (mSubscribedToLiveUpdates) {
|
if (mSubscribedToLiveUpdates) {
|
||||||
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
|
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();
|
lastValidationCheckTime = System.currentTimeMillis();
|
||||||
logDebug("User " + (mSubscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
|
logDebug("User " + (mSubscribedToLiveUpdates ? "HAS" : "DOES NOT HAVE")
|
||||||
+ " live updates purchased.");
|
+ " 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,
|
public void purchaseLiveUpdates(final Activity activity, final String email, final String userName,
|
||||||
final String countryDownloadName, final boolean hideUserName) {
|
final String countryDownloadName, final boolean hideUserName) {
|
||||||
if (!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!");
|
||||||
if (stopAfterResult) {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue