From 856ddb3588d9d7a55a17fa246f7dadd879792dd5 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 30 Apr 2018 13:03:49 +0300 Subject: [PATCH] Fixed inapp settings vars --- .../osmand/SecondSplashScreenFragment.java | 7 +++-- .../net/osmand/plus/OsmandApplication.java | 4 +-- .../src/net/osmand/plus/OsmandSettings.java | 5 +-- OsmAnd/src/net/osmand/plus/Version.java | 12 +++++-- .../activities/SettingsGeneralActivity.java | 7 +++-- .../chooseplan/ChoosePlanDialogFragment.java | 6 ++-- .../plus/download/DownloadActivity.java | 5 +-- .../plus/download/DownloadIndexesThread.java | 5 +-- .../plus/download/DownloadResources.java | 3 +- .../download/DownloadValidationManager.java | 5 +-- .../plus/download/ui/ItemViewHolder.java | 7 +++-- .../download/ui/LocalIndexesFragment.java | 3 +- .../download/ui/UpdatesIndexFragment.java | 3 +- .../plus/inapp/InAppPurchaseHelper.java | 31 +++++++++++-------- .../plus/liveupdates/LiveUpdatesFragment.java | 21 ++++++------- .../plus/liveupdates/OsmLiveActivity.java | 3 +- .../plus/resources/ResourceManager.java | 5 +-- 17 files changed, 77 insertions(+), 55 deletions(-) diff --git a/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java b/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java index 1c3d071b8d..13297f8fa8 100644 --- a/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java +++ b/OsmAnd/src/net/osmand/SecondSplashScreenFragment.java @@ -19,6 +19,7 @@ import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper; public class SecondSplashScreenFragment extends Fragment { public static final String TAG = "SecondSplashScreenFragment"; @@ -99,15 +100,15 @@ public class SecondSplashScreenFragment extends Fragment { logoLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); ImageView text = new ImageView(activity); if (Version.isFreeVersion(app)) { - if (settings.LIVE_UPDATES_PURCHASED.get()) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_osmlive)); - } else if (settings.FULL_VERSION_PURCHASED.get()) { + } else if (InAppPurchaseHelper.isFullVersionPurchased(app)) { text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_inapp)); } else { text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand)); } } else if (Version.isPaidVersion(app) || Version.isDeveloperVersion(app)) { - if (settings.LIVE_UPDATES_PURCHASED.get()) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_plus_osmlive)); } else { text.setImageDrawable(getResources().getDrawable(R.drawable.image_text_osmand_plus)); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 8bc16880ee..5d83d282fa 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -878,8 +878,8 @@ public class OsmandApplication extends MultiDexApplication { try { if (Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this) && !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get() - && !osmandSettings.FULL_VERSION_PURCHASED.get() - && !osmandSettings.LIVE_UPDATES_PURCHASED.get()) { + && !InAppPurchaseHelper.isFullVersionPurchased(this) + && !InAppPurchaseHelper.isSubscribedToLiveUpdates(this)) { Class cl = Class.forName("com.google.firebase.analytics.FirebaseAnalytics"); Method mm = cl.getMethod("getInstance", Context.class); Object inst = mm.invoke(null, ctx == null ? this : ctx); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 38aef91443..fbe4f3e981 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -965,6 +965,9 @@ 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 LIVE_UPDATES_PURCHASE_CANCELLED_TIME = new LongPreference("live_updates_purchase_cancelled_time", 0).makeGlobal(); + public final OsmandPreference LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN = new BooleanPreference("live_updates_purchase_cancelled_first_dlg_shown", false).makeGlobal(); + public final OsmandPreference LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN = new BooleanPreference("live_updates_purchase_cancelled_second_dlg_shown", false).makeGlobal(); public final OsmandPreference FULL_VERSION_PURCHASED = new BooleanPreference("billing_full_version_purchased", false).makeGlobal(); public final OsmandPreference DEPTH_CONTOURS_PURCHASED = new BooleanPreference("billing_sea_depth_purchased", false).makeGlobal(); public final OsmandPreference EMAIL_SUBSCRIBED = new BooleanPreference("email_subscribed", false).makeGlobal(); @@ -974,8 +977,6 @@ public class OsmandSettings { public final OsmandPreference DISCOUNT_TOTAL_SHOW = new IntPreference("discount_total_show", 0).makeGlobal(); public final OsmandPreference DISCOUNT_SHOW_DATETIME_MS = new LongPreference("show_discount_datetime_ms", 0).makeGlobal(); - public final OsmandPreference TRAVEL_ARTICLES_PURCHASED = new BooleanPreference("travel_articles_purchased", false).makeGlobal(); - // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference USER_OSM_BUG_NAME = new StringPreference("user_osm_bug_name", "NoName/OsmAnd").makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/Version.java b/OsmAnd/src/net/osmand/plus/Version.java index 42e0fe0cb6..d283ea556f 100644 --- a/OsmAnd/src/net/osmand/plus/Version.java +++ b/OsmAnd/src/net/osmand/plus/Version.java @@ -6,6 +6,8 @@ import java.net.URLEncoder; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import net.osmand.plus.inapp.InAppPurchaseHelper; + public class Version { private final String appVersion; @@ -121,14 +123,18 @@ public class Version { public static boolean isPaidVersion(OsmandApplication ctx) { return !isFreeVersion(ctx) - || ctx.getSettings().FULL_VERSION_PURCHASED.get() - || ctx.getSettings().LIVE_UPDATES_PURCHASED.get(); + || InAppPurchaseHelper.isFullVersionPurchased(ctx) + || InAppPurchaseHelper.isSubscribedToLiveUpdates(ctx); } public static boolean isDeveloperVersion(OsmandApplication ctx){ return getAppName(ctx).contains("~") || ctx.getPackageName().equals(FREE_DEV_VERSION_NAME); } - + + public static boolean isDeveloperBuild(OsmandApplication ctx){ + return getAppName(ctx).contains("~"); + } + public static String getVersionForTracker(OsmandApplication ctx) { String v = Version.getAppName(ctx); if(Version.isProductionVersion(ctx)){ diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 181799bf1a..ffc965be55 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -48,6 +48,7 @@ import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment; import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory; import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.render.RenderingRulesStorage; @@ -495,8 +496,10 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR misc.addPreference(createCheckBoxPreference(settings.DO_NOT_USE_ANIMATIONS, R.string.do_not_use_animations, R.string.do_not_use_animations_descr)); misc.addPreference(createCheckBoxPreference(settings.MAP_EMPTY_STATE_ALLOWED, R.string.tap_on_map_to_hide_interface, R.string.tap_on_map_to_hide_interface_descr)); misc.addPreference(createCheckBoxPreference(settings.DO_NOT_SHOW_STARTUP_MESSAGES, R.string.do_not_show_startup_messages, R.string.do_not_show_startup_messages_desc)); - if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(getMyApplication()) - && !settings.FULL_VERSION_PURCHASED.get() && !settings.LIVE_UPDATES_PURCHASED.get()) { + OsmandApplication app = getMyApplication(); + if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(app) + && !InAppPurchaseHelper.isFullVersionPurchased(app) + && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { misc.addPreference(createCheckBoxPreference(settings.DO_NOT_SEND_ANONYMOUS_APP_USAGE, R.string.do_not_send_anonymous_app_usage, R.string.do_not_send_anonymous_app_usage_desc)); } } diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java index 714854c502..de23600cc7 100644 --- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java @@ -32,6 +32,7 @@ import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.inapp.InAppPurchaseHelper; @@ -89,11 +90,10 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment case WIKIPEDIA_OFFLINE: case UNLOCK_ALL_FEATURES: case DONATION_TO_OSM: + case WIKIVOYAGE_OFFLINE: return false; case SEA_DEPTH_MAPS: - return ctx.getSettings().DEPTH_CONTOURS_PURCHASED.get(); - case WIKIVOYAGE_OFFLINE: - return ctx.getSettings().TRAVEL_ARTICLES_PURCHASED.get(); + return InAppPurchaseHelper.isDepthContoursPurchased(ctx); case CONTOUR_LINES_HILLSHADE_MAPS: return OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index 862a8214a3..e188a8a017 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -58,6 +58,7 @@ import net.osmand.plus.download.ui.DownloadResourceGroupFragment; import net.osmand.plus.download.ui.LocalIndexesFragment; import net.osmand.plus.download.ui.UpdatesIndexFragment; import net.osmand.plus.helpers.FileNameTranslationHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener; import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; @@ -403,8 +404,8 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo } public static boolean shouldShowFreeVersionBanner(OsmandApplication application) { - return (Version.isFreeVersion(application) && !application.getSettings().LIVE_UPDATES_PURCHASED.get() - && !application.getSettings().FULL_VERSION_PURCHASED.get()) + return (Version.isFreeVersion(application) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(application) + && !InAppPurchaseHelper.isFullVersionPurchased(application)) || application.getSettings().SHOULD_SHOW_FREE_VERSION_BANNER.get(); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 714ccc289f..aa0eadd273 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -32,6 +32,7 @@ import net.osmand.plus.Version; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.helpers.DatabaseHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.resources.ResourceManager; import net.osmand.util.Algorithms; @@ -563,8 +564,8 @@ public class DownloadIndexesThread { private boolean validateNotExceedsFreeLimit(IndexItem item) { boolean exceed = Version.isFreeVersion(app) - && !app.getSettings().LIVE_UPDATES_PURCHASED.get() - && !app.getSettings().FULL_VERSION_PURCHASED.get() + && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app) + && !InAppPurchaseHelper.isFullVersionPurchased(app) && DownloadActivityType.isCountedInDownloads(item) && downloads.get() >= DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS; if(exceed) { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index f30e085784..aad7982128 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -12,6 +12,7 @@ import net.osmand.map.OsmandRegions; import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -321,7 +322,7 @@ public class DownloadResources extends DownloadResourceGroup { continue; } if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) { - if (app.getSettings().DEPTH_CONTOURS_PURCHASED.get() || nauticalMaps.size() == 0) { + if (InAppPurchaseHelper.isDepthContoursPurchased(app) || nauticalMaps.size() == 0) { nauticalMaps.addItem(ii); } continue; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java b/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java index f1eb89235d..3a12eb3305 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java @@ -17,6 +17,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.inapp.InAppPurchaseHelper; import java.io.File; import java.text.MessageFormat; @@ -154,8 +155,8 @@ public class DownloadValidationManager { } protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) { - if (Version.isFreeVersion(getMyApplication()) && !app.getSettings().LIVE_UPDATES_PURCHASED.get() - && !app.getSettings().FULL_VERSION_PURCHASED.get()) { + if (Version.isFreeVersion(getMyApplication()) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app) + && !InAppPurchaseHelper.isFullVersionPurchased(app)) { 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/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index c1ed2b5816..fd1c08985d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -32,6 +32,7 @@ import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask; import net.osmand.plus.helpers.FileNameTranslationHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.util.Algorithms; import java.io.File; @@ -129,7 +130,7 @@ public class ItemViewHolder { nauticalPluginDisabled = context.isNauticalPluginDisabled(); freeVersion = context.isFreeVersion(); srtmNeedsInstallation = context.isSrtmNeedsInstallation(); - depthContoursPurchased = context.getMyApplication().getSettings().DEPTH_CONTOURS_PURCHASED.get(); + depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication()); } public void bindIndexItem(final IndexItem indexItem) { @@ -314,10 +315,10 @@ public class ItemViewHolder { } } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion - && !context.getMyApplication().getSettings().FULL_VERSION_PURCHASED.get()) { + && !InAppPurchaseHelper.isFullVersionPurchased(context.getMyApplication())) { clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE; } else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE - && !context.getMyApplication().getSettings().DEPTH_CONTOURS_PURCHASED.get()) { + && !InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication())) { clickAction = RightButtonAction.ASK_FOR_DEPTH_CONTOURS_PURCHASE; } return clickAction; diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 5b17c4cb81..a09e58b937 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -56,6 +56,7 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.FileNameTranslationHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.resources.IncrementalChangesManager; import net.osmand.util.Algorithms; @@ -469,7 +470,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement if (operation == DELETE_OPERATION) { File f = new File(info.getPathToData()); successfull = Algorithms.removeAllFiles(f); - if (getMyApplication().getSettings().LIVE_UPDATES_PURCHASED.get()) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { String fileNameWithoutExtension = Algorithms.getFileNameWithoutExtension(f); IncrementalChangesManager changesManager = diff --git a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java index cc77789481..0d288b29b8 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/UpdatesIndexFragment.java @@ -26,6 +26,7 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.util.Algorithms; import java.util.Comparator; @@ -92,7 +93,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download getMyApplication().getResourceManager().getOsmandRegions(); OsmandSettings settings = getMyApplication().getSettings(); listAdapter = new UpdateIndexAdapter(a, R.layout.download_index_list_item, indexItems, - !settings.LIVE_UPDATES_PURCHASED.get() || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()); + !InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication()) || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get()); listAdapter.sort(new Comparator() { @Override public int compare(IndexItem indexItem, IndexItem indexItem2) { diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java index 1a74139640..c41bfc20fd 100644 --- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java +++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java @@ -121,8 +121,16 @@ public class InAppPurchaseHelper { return activeTask; } - public boolean isSubscribedToLiveUpdates() { - return ctx.getSettings().LIVE_UPDATES_PURCHASED.get(); + public static boolean isSubscribedToLiveUpdates(@NonNull OsmandApplication ctx) { + return Version.isDeveloperBuild(ctx) || ctx.getSettings().LIVE_UPDATES_PURCHASED.get(); + } + + public static boolean isFullVersionPurchased(@NonNull OsmandApplication ctx) { + return Version.isDeveloperBuild(ctx) || ctx.getSettings().FULL_VERSION_PURCHASED.get(); + } + + public static boolean isDepthContoursPurchased(@NonNull OsmandApplication ctx) { + return Version.isDeveloperBuild(ctx) || ctx.getSettings().DEPTH_CONTOURS_PURCHASED.get(); } public String getLiveUpdatesPrice() { @@ -176,12 +184,7 @@ public class InAppPurchaseHelper { public InAppPurchaseHelper(OsmandApplication ctx) { this.ctx = ctx; - this.isDeveloperVersion = Version.isDeveloperVersion(ctx); - if (this.isDeveloperVersion) { - ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true); - ctx.getSettings().FULL_VERSION_PURCHASED.set(true); - ctx.getSettings().DEPTH_CONTOURS_PURCHASED.set(true); - } + isDeveloperVersion = Version.isDeveloperVersion(ctx); initialize(); } @@ -192,11 +195,11 @@ public class InAppPurchaseHelper { public boolean isPurchased(String inAppSku) { OsmandSettings settings = ctx.getSettings(); if (inAppSku.equals(SKU_FULL_VERSION_PRICE)) { - return settings.FULL_VERSION_PURCHASED.get(); + return isFullVersionPurchased(ctx); } else if (inAppSku.equals(SKU_LIVE_UPDATES_FULL) || inAppSku.equals(SKU_LIVE_UPDATES_FREE)) { - return settings.LIVE_UPDATES_PURCHASED.get(); + return isSubscribedToLiveUpdates(ctx); } else if (inAppSku.equals(SKU_DEPTH_CONTOURS_FULL) || inAppSku.equals(SKU_DEPTH_CONTOURS_FREE)) { - return settings.DEPTH_CONTOURS_PURCHASED.get(); + return isDepthContoursPurchased(ctx); } return false; } @@ -252,7 +255,7 @@ public class InAppPurchaseHelper { } public boolean needRequestInventory() { - return (ctx.getSettings().LIVE_UPDATES_PURCHASED.get() && !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get()) + return (isSubscribedToLiveUpdates(ctx) && !ctx.getSettings().BILLING_PURCHASE_TOKEN_SENT.get()) || System.currentTimeMillis() - lastValidationCheckTime > PURCHASE_VALIDATION_PERIOD_MSEC; } @@ -355,7 +358,9 @@ public class InAppPurchaseHelper { // Do we have the live updates? Purchase liveUpdatesPurchase = inventory.getPurchase(SKU_LIVE_UPDATES); boolean subscribedToLiveUpdates = (liveUpdatesPurchase != null && liveUpdatesPurchase.getPurchaseState() == 0); - //subscribedToLiveUpdates = false; + if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) { + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(System.currentTimeMillis()); + } ctx.getSettings().LIVE_UPDATES_PURCHASED.set(subscribedToLiveUpdates); Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE); diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index 8aad43a3a1..d0f3de34e2 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -130,8 +130,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (!processing && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) { + if (!processing && InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { final FragmentManager fragmentManager = getChildFragmentManager(); LiveUpdatesSettingsDialogFragment .createInstance(adapter.getChild(groupPosition, childPosition).getFileName()) @@ -153,8 +152,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (position == 0 && !processing && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) { + if (position == 0 && !processing && InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { SubscriptionFragment subscriptionFragment = new SubscriptionFragment(); subscriptionFragment.setEditMode(true); subscriptionFragment.show(getChildFragmentManager(), SubscriptionFragment.TAG); @@ -174,7 +172,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc if (getActivity() instanceof OsmLiveActivity) { View subscriptionBanner = subscriptionHeader.findViewById(R.id.subscription_banner); View subscriptionInfo = subscriptionHeader.findViewById(R.id.subscription_info); - if (getSettings().LIVE_UPDATES_PURCHASED.get()) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { ImageView statusIcon = (ImageView) subscriptionHeader.findViewById(R.id.statusIcon); TextView statusTextView = (TextView) subscriptionHeader.findViewById(R.id.statusTextView); TextView regionNameHeaderTextView = (TextView) subscriptionHeader.findViewById(R.id.regionHeaderTextView); @@ -267,7 +265,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc @SuppressWarnings("deprecation") @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (getSettings().LIVE_UPDATES_PURCHASED.get() && !Version.isDeveloperVersion(getMyApplication())) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication()) + && !Version.isDeveloperVersion(getMyApplication())) { + ActionBar actionBar = getMyActivity().getSupportActionBar(); if (actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); @@ -404,8 +404,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) { + if (InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { switchOnLiveUpdates(settings); } else { liveUpdatesSwitch.setChecked(false); @@ -606,8 +605,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc descriptionTextView.setText(context.getString(R.string.last_map_change, lastCheckString)); } - InAppPurchaseHelper purchaseHelper = fragment.getInAppPurchaseHelper(); - if (!fragment.isProcessing() && purchaseHelper != null && purchaseHelper.isSubscribedToLiveUpdates()) { + if (!fragment.isProcessing() && InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) { final View.OnClickListener clickListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -708,8 +706,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc @Override public void onGetItems() { - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (purchaseHelper != null && !purchaseHelper.isSubscribedToLiveUpdates()) { + if (!InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication())) { getSettings().IS_LIVE_UPDATES_ON.set(false); adapter.enableLiveUpdates(false); } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/OsmLiveActivity.java b/OsmAnd/src/net/osmand/plus/liveupdates/OsmLiveActivity.java index 2d42d40da3..210af91384 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/OsmLiveActivity.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/OsmLiveActivity.java @@ -21,6 +21,7 @@ import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogListener; import net.osmand.plus.download.AbstractDownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.inapp.InAppPurchaseHelper; import org.apache.commons.logging.Log; @@ -86,7 +87,7 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa @Override protected void onResume() { super.onResume(); - if (!getMyApplication().getSettings().LIVE_UPDATES_PURCHASED.get() && showSettingOnly) { + if (!InAppPurchaseHelper.isSubscribedToLiveUpdates(getMyApplication()) && showSettingOnly) { ChoosePlanDialogFragment.showOsmLiveInstance(getSupportFragmentManager()); } } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index a55fbc7ae1..18709b2c71 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -36,6 +36,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.resources.AsyncLoadingThread.MapLoadRequest; @@ -581,7 +582,7 @@ public class ResourceManager { collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files); renameRoadsFiles(files, roadsPath); collectFiles(roadsPath, IndexConstants.BINARY_MAP_INDEX_EXT, files); - if (!Version.isFreeVersion(context) || context.getSettings().FULL_VERSION_PURCHASED.get()) { + if (!Version.isFreeVersion(context) || InAppPurchaseHelper.isFullVersionPurchased(context)) { collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); } if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) { @@ -618,7 +619,7 @@ public class ResourceManager { } boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)); boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT); - if (mapReader == null || (Version.isFreeVersion(context) && wikiMap && !context.getSettings().FULL_VERSION_PURCHASED.get())) { + if (mapReader == null || (Version.isFreeVersion(context) && wikiMap && !InAppPurchaseHelper.isFullVersionPurchased(context))) { warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$ } else { if (mapReader.isBasemap()) {