From 2c3d2033e6eec9f22e2b96f31ad47cd582bd8c5f Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 3 May 2018 18:30:50 +0300 Subject: [PATCH] Fixed inapp purchases. Added cancelled subscription screen. --- .../res/drawable/circle_dialog_bg_light.xml | 12 + .../res/drawable/circle_dialog_bg_night.xml | 12 + .../osmlive_cancelled_dialog_fragment.xml | 124 +++++++++ OsmAnd/res/values/attrs.xml | 4 + OsmAnd/res/values/colors.xml | 6 + OsmAnd/res/values/strings.xml | 3 + OsmAnd/res/values/styles.xml | 8 + .../net/osmand/plus/OsmandApplication.java | 6 +- .../osmand/plus/activities/MapActivity.java | 23 +- .../OsmandInAppPurchaseActivity.java | 61 +++- .../activities/SettingsGeneralActivity.java | 4 +- .../osmand/plus/base/BaseOsmAndFragment.java | 10 + .../chooseplan/ChoosePlanDialogFragment.java | 17 +- .../chooseplan/OsmLiveCancelledDialog.java | 261 ++++++++++++++++++ .../plus/download/DownloadActivity.java | 34 +-- .../plus/download/DownloadIndexesThread.java | 4 +- .../plus/download/DownloadResources.java | 4 +- .../download/DownloadValidationManager.java | 8 +- .../plus/download/ui/ItemViewHolder.java | 13 +- .../osmand/plus/helpers/DiscountHelper.java | 8 +- .../plus/inapp/InAppPurchaseHelper.java | 62 +++-- .../plus/liveupdates/LiveUpdatesFragment.java | 36 ++- .../liveupdates/SubscriptionFragment.java | 18 -- .../plus/resources/ResourceManager.java | 6 +- .../plus/srtmplugin/ContourLinesMenu.java | 3 +- .../osmand/plus/srtmplugin/HillshadeMenu.java | 3 +- .../views/corenative/NativeCoreContext.java | 3 +- 27 files changed, 622 insertions(+), 131 deletions(-) create mode 100644 OsmAnd/res/drawable/circle_dialog_bg_light.xml create mode 100644 OsmAnd/res/drawable/circle_dialog_bg_night.xml create mode 100644 OsmAnd/res/layout/osmlive_cancelled_dialog_fragment.xml create mode 100644 OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java diff --git a/OsmAnd/res/drawable/circle_dialog_bg_light.xml b/OsmAnd/res/drawable/circle_dialog_bg_light.xml new file mode 100644 index 0000000000..1821049526 --- /dev/null +++ b/OsmAnd/res/drawable/circle_dialog_bg_light.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/circle_dialog_bg_night.xml b/OsmAnd/res/drawable/circle_dialog_bg_night.xml new file mode 100644 index 0000000000..000d22e1cd --- /dev/null +++ b/OsmAnd/res/drawable/circle_dialog_bg_night.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/osmlive_cancelled_dialog_fragment.xml b/OsmAnd/res/layout/osmlive_cancelled_dialog_fragment.xml new file mode 100644 index 0000000000..f466046873 --- /dev/null +++ b/OsmAnd/res/layout/osmlive_cancelled_dialog_fragment.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 87f081516a..5da70475ad 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -65,8 +65,12 @@ + + + + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index 0f1466ffb6..e0872ed64c 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -3,6 +3,11 @@ #78cc5c + #f0f0f0 + #17191a + #14f0f0f0 + #1417191a + #212121 #cccccc #212121 @@ -10,6 +15,7 @@ #e6e6e6 #2d3133 #727272 + #808080 #b3b3b3 #4d4d4d diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 109049064c..68ac11206b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 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 --> + You have cancel OsmAnd Live subscription + Renew subscription to continue use the all features: + OsmAnd team Popular destinations Paid app diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index bcbd3ed781..d5bf5d0bc5 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -179,6 +179,7 @@ @color/color_white @style/OverflowMenuButton + @drawable/circle_dialog_bg_light @color/icon_color_light @color/icon_color_light @color/icon_color @@ -197,8 +198,11 @@ @color/coordinate_input_edit_text_normal_light + @color/dialog_bg_color_light + @color/dialog_transparent_bg_color_light @color/dialog_title_color_light @color/dialog_description_color_light + @color/dialog_text_description_color @color/card_description_text_color_light @color/wikivoyage_bg_light @@ -398,8 +402,12 @@ @color/coordinate_input_edit_text_normal_dark + @drawable/circle_dialog_bg_night + @color/dialog_bg_color_night + @color/dialog_transparent_bg_color_night @color/dialog_title_color_dark @color/dialog_description_color_dark + @color/dialog_text_description_color_night @color/card_description_text_color_dark @color/wikivoyage_bg_dark diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 5d83d282fa..1493509df8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -876,10 +876,8 @@ public class OsmandApplication extends MultiDexApplication { public void logEvent(Activity ctx, String event) { try { - if (Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this) - && !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get() - && !InAppPurchaseHelper.isFullVersionPurchased(this) - && !InAppPurchaseHelper.isSubscribedToLiveUpdates(this)) { + if (Version.isGooglePlayEnabled(this) && !Version.isPaidVersion(this) + && !osmandSettings.DO_NOT_SEND_ANONYMOUS_APP_USAGE.get()) { 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/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index c111ecee7e..887722b7ef 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -76,6 +76,7 @@ import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.FailSafeFuntions; import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.chooseplan.OsmLiveCancelledDialog; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dialogs.ErrorBottomSheetDialog; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; @@ -203,7 +204,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private boolean permissionGranted; private boolean mIsDestroyed = false; - private InAppPurchaseHelper inAppPurchaseHelper; private Timer splashScreenTimer; private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); @@ -785,9 +785,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven getSupportFragmentManager().beginTransaction() .add(R.id.fragmentContainer, new FirstUsageWelcomeFragment(), FirstUsageWelcomeFragment.TAG).commitAllowingStateLoss(); - } else if (!isFirstScreenShowing() && XMasDialogFragment.shouldShowXmasDialog(app)) { - SecondSplashScreenFragment.SHOW = false; - new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); + } else if (!isFirstScreenShowing()) { + if (XMasDialogFragment.shouldShowXmasDialog(app)) { + SecondSplashScreenFragment.SHOW = false; + new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); + } else if (OsmLiveCancelledDialog.shouldShowDialog(app)) { + OsmLiveCancelledDialog.showInstance(getSupportFragmentManager()); + } } FirstUsageWelcomeFragment.SHOW = false; @@ -865,6 +869,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return null; } + public boolean isInAppPurchaseAllowed() { + return true; + } + private void dismissSecondSplashScreen() { if (SecondSplashScreenFragment.VISIBLE) { SecondSplashScreenFragment.VISIBLE = false; @@ -1213,9 +1221,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (atlasMapRendererView != null) { atlasMapRendererView.handleOnDestroy(); } - if (inAppPurchaseHelper != null) { - inAppPurchaseHelper.stop(); - } mIsDestroyed = true; } @@ -1512,9 +1517,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (inAppPurchaseHelper != null && inAppPurchaseHelper.onActivityResultHandled(requestCode, resultCode, data)) { - return; - } for (ActivityResultListener listener : activityResultListeners) { if (listener.processResult(requestCode, resultCode, data)) { removeActivityResultListener(listener); @@ -1522,6 +1524,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } OsmandPlugin.onMapActivityResult(requestCode, resultCode, data); + super.onActivityResult(requestCode, resultCode, data); } public void refreshMap() { diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java index 75d7e6621e..60ac8e8d30 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandInAppPurchaseActivity.java @@ -8,6 +8,8 @@ import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; @@ -23,6 +25,8 @@ import net.osmand.plus.srtmplugin.SRTMPlugin; import org.apache.commons.logging.Log; +import java.util.List; + @SuppressLint("Registered") public class OsmandInAppPurchaseActivity extends AppCompatActivity implements InAppPurchaseListener { private static final Log LOG = PlatformUtil.getLog(OsmandInAppPurchaseActivity.class); @@ -64,7 +68,7 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In deinitInAppPurchaseHelper(); if (purchaseHelper != null) { - purchaseHelper.addListener(this); + purchaseHelper.setUiActivity(this); if (purchaseHelper.needRequestInventory()) { purchaseHelper.requestInventory(); } @@ -73,7 +77,7 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In private void deinitInAppPurchaseHelper() { if (purchaseHelper != null) { - purchaseHelper.removeListener(this); + purchaseHelper.resetUiActivity(this); purchaseHelper.stop(); } } @@ -141,26 +145,79 @@ public class OsmandInAppPurchaseActivity extends AppCompatActivity implements In @Override public void onError(InAppPurchaseTaskType taskType, String error) { onInAppPurchaseError(taskType, error); + fireInAppPurchaseErrorOnFragments(getSupportFragmentManager(), taskType, error); + } + + public void fireInAppPurchaseErrorOnFragments(@NonNull FragmentManager fragmentManager, + InAppPurchaseTaskType taskType, String error) { + List fragments = fragmentManager.getFragments(); + for (Fragment f : fragments) { + if (f instanceof InAppPurchaseListener && f.isAdded()) { + ((InAppPurchaseListener) f).onError(taskType, error); + } + } } @Override public void onGetItems() { onInAppPurchaseGetItems(); + fireInAppPurchaseGetItemsOnFragments(getSupportFragmentManager()); + } + + public void fireInAppPurchaseGetItemsOnFragments(@NonNull FragmentManager fragmentManager) { + List fragments = fragmentManager.getFragments(); + for (Fragment f : fragments) { + if (f instanceof InAppPurchaseListener && f.isAdded()) { + ((InAppPurchaseListener) f).onGetItems(); + } + } } @Override public void onItemPurchased(String sku) { onInAppPurchaseItemPurchased(sku); + fireInAppPurchaseItemPurchasedOnFragments(getSupportFragmentManager(), sku); + } + + public void fireInAppPurchaseItemPurchasedOnFragments(@NonNull FragmentManager fragmentManager, String sku) { + List fragments = fragmentManager.getFragments(); + for (Fragment f : fragments) { + if (f instanceof InAppPurchaseListener && f.isAdded()) { + ((InAppPurchaseListener) f).onItemPurchased(sku); + } + } } @Override public void showProgress(InAppPurchaseTaskType taskType) { showInAppPurchaseProgress(taskType); + fireInAppPurchaseShowProgressOnFragments(getSupportFragmentManager(), taskType); + } + + public void fireInAppPurchaseShowProgressOnFragments(@NonNull FragmentManager fragmentManager, + InAppPurchaseTaskType taskType) { + List fragments = fragmentManager.getFragments(); + for (Fragment f : fragments) { + if (f instanceof InAppPurchaseListener && f.isAdded()) { + ((InAppPurchaseListener) f).showProgress(taskType); + } + } } @Override public void dismissProgress(InAppPurchaseTaskType taskType) { dismissInAppPurchaseProgress(taskType); + fireInAppPurchaseDismissProgressOnFragments(getSupportFragmentManager(), taskType); + } + + public void fireInAppPurchaseDismissProgressOnFragments(@NonNull FragmentManager fragmentManager, + InAppPurchaseTaskType taskType) { + List fragments = fragmentManager.getFragments(); + for (Fragment f : fragments) { + if (f instanceof InAppPurchaseListener && f.isAdded()) { + ((InAppPurchaseListener) f).dismissProgress(taskType); + } + } } public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) { diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index ffc965be55..1f3d959b1d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -497,9 +497,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR 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)); OsmandApplication app = getMyApplication(); - if (Version.isGooglePlayEnabled(getMyApplication()) && Version.isFreeVersion(app) - && !InAppPurchaseHelper.isFullVersionPurchased(app) - && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { + if (Version.isGooglePlayEnabled(getMyApplication()) && !Version.isPaidVersion(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/base/BaseOsmAndFragment.java b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java index 21d381cb2c..501c3513ff 100644 --- a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandActionBarActivity; +import net.osmand.plus.activities.OsmandInAppPurchaseActivity; public class BaseOsmAndFragment extends Fragment implements TransitionAnimator { private IconsCache iconsCache; @@ -128,6 +129,15 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator { return (OsmandActionBarActivity) getActivity(); } + protected OsmandInAppPurchaseActivity getInAppPurchaseActivity() { + Activity activity = getActivity(); + if (activity instanceof OsmandInAppPurchaseActivity) { + return (OsmandInAppPurchaseActivity) getActivity(); + } else { + return null; + } + } + protected IconsCache getIconsCache() { if (iconsCache == null) { iconsCache = getMyApplication().getIconsCache(); diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java index de23600cc7..ab32e5cb83 100644 --- a/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/chooseplan/ChoosePlanDialogFragment.java @@ -32,7 +32,6 @@ 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; @@ -276,9 +275,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment cardDescription.setText(R.string.osm_live_payment_desc); osmLiveCardButton = cardView.findViewById(R.id.card_button); - InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); - boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY; - setupOsmLiveCardButton(requestingInventory); return cardView; } @@ -288,7 +284,7 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment ProgressBar progressBar = (ProgressBar) osmLiveCardButton.findViewById(R.id.card_button_progress); TextViewEx buttonTitle = (TextViewEx) osmLiveCardButton.findViewById(R.id.card_button_title); TextViewEx buttonSubtitle = (TextViewEx) osmLiveCardButton.findViewById(R.id.card_button_subtitle); - if (!purchaseHelper.hasPrices()) { + if (purchaseHelper == null || !purchaseHelper.hasPrices()) { buttonTitle.setText(getString(R.string.purchase_subscription_title, getString(R.string.osm_live_default_price))); } else { buttonTitle.setText(getString(R.string.purchase_subscription_title, purchaseHelper.getLiveUpdatesPrice())); @@ -376,9 +372,6 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment cardDescription.setText(R.string.in_app_purchase_desc_ex); planTypeCardButton = cardView.findViewById(R.id.card_button); - InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); - boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY; - setupPlanTypeCardButton(requestingInventory); return cardView; } @@ -421,6 +414,14 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment if (mapActivity != null) { mapActivity.disableDrawer(); } + + boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY; + if (osmLiveCardButton != null) { + setupOsmLiveCardButton(requestingInventory); + } + if (planTypeCardButton != null) { + setupPlanTypeCardButton(requestingInventory); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java new file mode 100644 index 0000000000..6c14a1a411 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/chooseplan/OsmLiveCancelledDialog.java @@ -0,0 +1,261 @@ +package net.osmand.plus.chooseplan; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.ColorRes; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; +import android.support.v4.content.ContextCompat; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.ProgressBar; + +import net.osmand.PlatformUtil; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.OsmandPreference; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.BaseOsmAndDialogFragment; +import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.OsmAndFeature; +import net.osmand.plus.inapp.InAppPurchaseHelper; +import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener; +import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType; +import net.osmand.plus.liveupdates.OsmLiveActivity; +import net.osmand.plus.liveupdates.SubscriptionFragment; +import net.osmand.plus.widgets.TextViewEx; + +import org.apache.commons.logging.Log; + +public class OsmLiveCancelledDialog extends BaseOsmAndDialogFragment implements InAppPurchaseListener { + public static final String TAG = OsmLiveCancelledDialog.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(OsmLiveCancelledDialog.class); + + private OsmandApplication app; + private InAppPurchaseHelper purchaseHelper; + + private boolean nightMode; + private View osmLiveButton; + + private final OsmAndFeature[] osmLiveFeatures = { + OsmAndFeature.DAILY_MAP_UPDATES, + OsmAndFeature.UNLIMITED_DOWNLOADS, + OsmAndFeature.WIKIPEDIA_OFFLINE, + OsmAndFeature.WIKIVOYAGE_OFFLINE, + OsmAndFeature.CONTOUR_LINES_HILLSHADE_MAPS, + OsmAndFeature.SEA_DEPTH_MAPS, + OsmAndFeature.UNLOCK_ALL_FEATURES, + OsmAndFeature.DONATION_TO_OSM, + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + app = getMyApplication(); + purchaseHelper = app.getInAppPurchaseHelper(); + nightMode = isNightMode(getMapActivity() != null); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + Activity ctx = requireActivity(); + int themeId = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar; + Dialog dialog = new Dialog(ctx, themeId); + Window window = dialog.getWindow(); + if (window != null) { + if (!getSettings().DO_NOT_USE_ANIMATIONS.get()) { + window.getAttributes().windowAnimations = R.style.Animations_Alpha; + } + if (Build.VERSION.SDK_INT >= 21) { + window.setStatusBarColor(ContextCompat.getColor(ctx, getStatusBarColor())); + } + } + return dialog; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + Context ctx = getContext(); + if (ctx == null) { + return null; + } + View view = inflate(R.layout.osmlive_cancelled_dialog_fragment, container); + + view.findViewById(R.id.button_close).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + TextViewEx infoDescr = (TextViewEx) view.findViewById(R.id.info_description); + StringBuilder descr = new StringBuilder(); + descr.append(getString(R.string.purchase_cancelled_dialog_descr)); + for (OsmAndFeature feature : osmLiveFeatures) { + descr.append("\n").append("— ").append(feature.toHumanString(ctx)); + } + infoDescr.setText(descr); + + osmLiveButton = view.findViewById(R.id.card_button); + + return view; + } + + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity != null && activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + @Override + public void onResume() { + super.onResume(); + + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.disableDrawer(); + } + + boolean requestingInventory = purchaseHelper != null && purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY; + setupOsmLiveButton(requestingInventory); + + OsmandPreference firstTimeShown = app.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN; + OsmandPreference secondTimeShown = app.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN; + if (!firstTimeShown.get()) { + firstTimeShown.set(true); + } else if (!secondTimeShown.get()) { + secondTimeShown.set(true); + } + } + + @Override + public void onPause() { + super.onPause(); + + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.enableDrawer(); + } + } + + @ColorRes + protected int getStatusBarColor() { + return nightMode ? R.color.status_bar_wikivoyage_dark : R.color.status_bar_wikivoyage_light; + } + + @Override + public void onError(InAppPurchaseTaskType taskType, String error) { + if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) { + setupOsmLiveButton(false); + } + } + + @Override + public void onGetItems() { + } + + @Override + public void onItemPurchased(String sku) { + } + + @Override + public void showProgress(InAppPurchaseTaskType taskType) { + if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) { + setupOsmLiveButton(true); + } + } + + @Override + public void dismissProgress(InAppPurchaseTaskType taskType) { + if (taskType == InAppPurchaseTaskType.REQUEST_INVENTORY) { + setupOsmLiveButton(false); + } + } + + private void setupOsmLiveButton(boolean progress) { + if (osmLiveButton != null) { + ProgressBar progressBar = (ProgressBar) osmLiveButton.findViewById(R.id.card_button_progress); + TextViewEx buttonTitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_title); + TextViewEx buttonSubtitle = (TextViewEx) osmLiveButton.findViewById(R.id.card_button_subtitle); + if (!purchaseHelper.hasPrices()) { + buttonTitle.setText(getString(R.string.purchase_subscription_title, getString(R.string.osm_live_default_price))); + } else { + buttonTitle.setText(getString(R.string.purchase_subscription_title, purchaseHelper.getLiveUpdatesPrice())); + } + buttonSubtitle.setText(R.string.osm_live_month_cost_desc); + if (progress) { + buttonTitle.setVisibility(View.GONE); + buttonSubtitle.setVisibility(View.GONE); + progressBar.setVisibility(View.VISIBLE); + osmLiveButton.setOnClickListener(null); + } else { + buttonTitle.setVisibility(View.VISIBLE); + buttonSubtitle.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.GONE); + osmLiveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + subscript(); + dismiss(); + } + }); + } + } + } + + private void subscript() { + FragmentActivity ctx = getActivity(); + if (ctx != null) { + if (ctx instanceof OsmLiveActivity) { + SubscriptionFragment subscriptionFragment = new SubscriptionFragment(); + subscriptionFragment.show(ctx.getSupportFragmentManager(), SubscriptionFragment.TAG); + } else { + Intent intent = new Intent(ctx, OsmLiveActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra(OsmLiveActivity.OPEN_SUBSCRIPTION_INTENT_PARAM, true); + ctx.startActivity(intent); + } + } + } + + private View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) { + int themeRes = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar; + return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes)) + .inflate(layoutId, container, false); + } + + public static boolean shouldShowDialog(OsmandApplication app) { + OsmandSettings settings = app.getSettings(); + long cancelledTime = settings.LIVE_UPDATES_PURCHASE_CANCELLED_TIME.get(); + boolean firstTimeShown = settings.LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.get(); + boolean secondTimeShown = settings.LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.get(); + return cancelledTime > 0 + && (!firstTimeShown + || (System.currentTimeMillis() - cancelledTime > InAppPurchaseHelper.getSubscriptionHoldingTime(app) + && !secondTimeShown)); + } + + public static void showInstance(@NonNull FragmentManager fm) { + try { + OsmLiveCancelledDialog fragment = new OsmLiveCancelledDialog(); + fragment.show(fm, OsmLiveCancelledDialog.TAG); + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index e188a8a017..11fb2868b0 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -206,54 +206,25 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo @Override public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) { visibleBanner.updateFreeVersionBanner(); - for (WeakReference ref : fragSet) { - Fragment f = ref.get(); - if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).onError(taskType, error); - } - } } @Override public void onInAppPurchaseGetItems() { visibleBanner.updateFreeVersionBanner(); - for (WeakReference ref : fragSet) { - Fragment f = ref.get(); - if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).onGetItems(); - } - } + } @Override public void onInAppPurchaseItemPurchased(String sku) { visibleBanner.updateFreeVersionBanner(); - for (WeakReference ref : fragSet) { - Fragment f = ref.get(); - if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).onItemPurchased(sku); - } - } } @Override public void showInAppPurchaseProgress(InAppPurchaseTaskType taskType) { - for (WeakReference ref : fragSet) { - Fragment f = ref.get(); - if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).showProgress(taskType); - } - } } @Override public void dismissInAppPurchaseProgress(InAppPurchaseTaskType taskType) { - for (WeakReference ref : fragSet) { - Fragment f = ref.get(); - if (f instanceof InAppPurchaseListener && f.isAdded()) { - ((InAppPurchaseListener) f).dismissProgress(taskType); - } - } } public DownloadIndexesThread getDownloadThread() { @@ -404,8 +375,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo } public static boolean shouldShowFreeVersionBanner(OsmandApplication application) { - return (Version.isFreeVersion(application) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(application) - && !InAppPurchaseHelper.isFullVersionPurchased(application)) + return !Version.isPaidVersion(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 aa0eadd273..79a4473237 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -563,9 +563,7 @@ public class DownloadIndexesThread { } private boolean validateNotExceedsFreeLimit(IndexItem item) { - boolean exceed = Version.isFreeVersion(app) - && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app) - && !InAppPurchaseHelper.isFullVersionPurchased(app) + boolean exceed = !Version.isPaidVersion(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 e8e1f35da2..16bc058384 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -325,7 +325,9 @@ public class DownloadResources extends DownloadResourceGroup { continue; } if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) { - if (InAppPurchaseHelper.isDepthContoursPurchased(app) || nauticalMaps.size() == 0) { + if (InAppPurchaseHelper.isDepthContoursPurchased(app) + || InAppPurchaseHelper.isSubscribedToLiveUpdates(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 3a12eb3305..7810ef80ef 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadValidationManager.java @@ -155,14 +155,12 @@ public class DownloadValidationManager { } protected void downloadFilesCheck_1_FreeVersion(FragmentActivity context, IndexItem[] items) { - if (Version.isFreeVersion(getMyApplication()) && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app) - && !InAppPurchaseHelper.isFullVersionPurchased(app)) { + if (!Version.isPaidVersion(app)) { int total = settings.NUMBER_OF_FREE_DOWNLOADS.get(); if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS) { - if (context instanceof FragmentActivity) { - FragmentActivity activity = context; + if (context != null) { new InstallPaidVersionDialogFragment() - .show(activity.getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG); + .show(context.getSupportFragmentManager(), InstallPaidVersionDialogFragment.TAG); } } else { downloadFilesCheck_2_Internet(context, items); diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index fd1c08985d..863d5d8595 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -21,6 +21,7 @@ import android.widget.Toast; import net.osmand.map.WorldRegion; import net.osmand.plus.R; +import net.osmand.plus.Version; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; @@ -50,7 +51,6 @@ public class ItemViewHolder { private boolean srtmDisabled; private boolean srtmNeedsInstallation; private boolean nauticalPluginDisabled; - private boolean freeVersion; private boolean depthContoursPurchased; protected final DownloadActivity context; @@ -128,9 +128,9 @@ public class ItemViewHolder { private void initAppStatusVariables() { srtmDisabled = context.isSrtmDisabled(); nauticalPluginDisabled = context.isNauticalPluginDisabled(); - freeVersion = context.isFreeVersion(); srtmNeedsInstallation = context.isSrtmNeedsInstallation(); - depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication()); + depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication()) + || InAppPurchaseHelper.isSubscribedToLiveUpdates(context.getMyApplication()); } public void bindIndexItem(final IndexItem indexItem) { @@ -314,11 +314,10 @@ public class ItemViewHolder { clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE; } - } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion - && !InAppPurchaseHelper.isFullVersionPurchased(context.getMyApplication())) { + } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE + && !Version.isPaidVersion(context.getMyApplication())) { clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE; - } else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE - && !InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication())) { + } else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) { clickAction = RightButtonAction.ASK_FOR_DEPTH_CONTOURS_PURCHASE; } return clickAction; diff --git a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java index 239eac2c6b..20aa2d543c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/DiscountHelper.java @@ -110,7 +110,8 @@ public class DiscountHelper { if (url.startsWith(INAPP_PREFIX) && url.length() > INAPP_PREFIX.length()) { String inAppSku = url.substring(INAPP_PREFIX.length()); InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); - if (purchaseHelper != null && purchaseHelper.isPurchased(inAppSku)) { + if (purchaseHelper != null + && (purchaseHelper.isPurchased(inAppSku) || InAppPurchaseHelper.isSubscribedToLiveUpdates(app))) { return; } } @@ -214,7 +215,10 @@ public class DiscountHelper { if (url.contains(InAppPurchaseHelper.SKU_FULL_VERSION_PRICE)) { OsmandApplication app = mapActivity.getMyApplication(); app.logEvent(mapActivity, "in_app_purchase_redirect"); - app.getInAppPurchaseHelper().purchaseFullVersion(mapActivity); + InAppPurchaseHelper purchaseHelper = app.getInAppPurchaseHelper(); + if (purchaseHelper != null) { + purchaseHelper.purchaseFullVersion(mapActivity); + } } else if (url.contains(InAppPurchaseHelper.SKU_LIVE_UPDATES)){ Intent intent = new Intent(mapActivity, OsmLiveActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); diff --git a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java index c41bfc20fd..cebdf768a5 100644 --- a/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java +++ b/OsmAnd/src/net/osmand/plus/inapp/InAppPurchaseHelper.java @@ -11,6 +11,7 @@ import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidNetworkUtils.OnRequestResultListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.inapp.util.IabHelper; @@ -36,7 +37,9 @@ import java.util.Map; public class InAppPurchaseHelper { // Debug tag, for logging private static final String TAG = InAppPurchaseHelper.class.getSimpleName(); - boolean mDebugLog = false; + boolean mDebugLog = true; + + private static final long SUBSCRIPTION_HOLDING_TIME_MSEC = 1000 * 60 * 60 * 24 * 3; // 3 days private long lastValidationCheckTime; private String liveUpdatesPrice; @@ -69,7 +72,7 @@ public class InAppPurchaseHelper { private boolean processingTask = false; private OsmandApplication ctx; - private List listeners = new ArrayList<>(); + private InAppPurchaseListener uiActivity = null; /* base64EncodedPublicKey should be YOUR APPLICATION'S PUBLIC KEY * (that you got from the Google Play developer console). This is not your @@ -121,6 +124,14 @@ public class InAppPurchaseHelper { return activeTask; } + public static long getSubscriptionHoldingTime(OsmandApplication app) { + if (Version.isDeveloperBuild(app)) { + return 1000 * 60 * 60; // 1 hour (test) + } else { + return SUBSCRIPTION_HOLDING_TIME_MSEC; + } + } + public static boolean isSubscribedToLiveUpdates(@NonNull OsmandApplication ctx) { return Version.isDeveloperBuild(ctx) || ctx.getSettings().LIVE_UPDATES_PURCHASED.get(); } @@ -193,7 +204,6 @@ public class InAppPurchaseHelper { } public boolean isPurchased(String inAppSku) { - OsmandSettings settings = ctx.getSettings(); if (inAppSku.equals(SKU_FULL_VERSION_PRICE)) { return isFullVersionPurchased(ctx); } else if (inAppSku.equals(SKU_LIVE_UPDATES_FULL) || inAppSku.equals(SKU_LIVE_UPDATES_FREE)) { @@ -358,10 +368,19 @@ public class InAppPurchaseHelper { // Do we have the live updates? Purchase liveUpdatesPurchase = inventory.getPurchase(SKU_LIVE_UPDATES); boolean subscribedToLiveUpdates = (liveUpdatesPurchase != null && liveUpdatesPurchase.getPurchaseState() == 0); - if (!subscribedToLiveUpdates && ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) { - ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME.set(System.currentTimeMillis()); + OsmandPreference subscriptionCancelledTime = ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_TIME; + if (!subscribedToLiveUpdates) { + if (ctx.getSettings().LIVE_UPDATES_PURCHASED.get()) { + subscriptionCancelledTime.set(System.currentTimeMillis()); + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN.set(false); + ctx.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_SECOND_DLG_SHOWN.set(false); + } else if (System.currentTimeMillis() - subscriptionCancelledTime.get() > getSubscriptionHoldingTime(ctx)) { + ctx.getSettings().LIVE_UPDATES_PURCHASED.set(false); + } + } else { + subscriptionCancelledTime.set(0L); + ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true); } - ctx.getSettings().LIVE_UPDATES_PURCHASED.set(subscribedToLiveUpdates); Purchase fullVersionPurchase = inventory.getPurchase(SKU_FULL_VERSION_PRICE); boolean fullVersionPurchased = (fullVersionPurchase != null && fullVersionPurchase.getPurchaseState() == 0); @@ -722,41 +741,44 @@ public class InAppPurchaseHelper { } private void notifyError(InAppPurchaseTaskType taskType, String message) { - for (InAppPurchaseListener l : listeners) { - l.onError(taskType, message); + if (uiActivity != null) { + uiActivity.onError(taskType, message); } } private void notifyGetItems() { - for (InAppPurchaseListener l : listeners) { - l.onGetItems(); + if (uiActivity != null) { + uiActivity.onGetItems(); } } private void notifyItemPurchased(String sku) { - for (InAppPurchaseListener l : listeners) { - l.onItemPurchased(sku); + if (uiActivity != null) { + uiActivity.onItemPurchased(sku); } } private void notifyShowProgress(InAppPurchaseTaskType taskType) { - for (InAppPurchaseListener l : listeners) { - l.showProgress(taskType); + if (uiActivity != null) { + uiActivity.showProgress(taskType); } } private void notifyDismissProgress(InAppPurchaseTaskType taskType) { - for (InAppPurchaseListener l : listeners) { - l.dismissProgress(taskType); + if (uiActivity != null) { + uiActivity.dismissProgress(taskType); } } - public void addListener(InAppPurchaseListener listener) { - this.listeners.add(listener); + /// UI notifications methods + public void setUiActivity(InAppPurchaseListener uiActivity) { + this.uiActivity = uiActivity; } - public void removeListener(InAppPurchaseListener listener) { - this.listeners.remove(listener); + public void resetUiActivity(InAppPurchaseListener uiActivity) { + if (this.uiActivity == uiActivity) { + this.uiActivity = null; + } } private void complain(String message) { diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index d0f3de34e2..775bd85cbf 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -37,6 +37,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; + import net.osmand.map.WorldRegion; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -229,7 +230,6 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc if (purchaseHelper.getActiveTask() == InAppPurchaseTaskType.REQUEST_INVENTORY) { enableProgress(); } - purchaseHelper.addListener(this); } if (((OsmLiveActivity) getActivity()).shouldOpenSubscription()) { SubscriptionFragment subscriptionFragment = new SubscriptionFragment(); @@ -245,15 +245,6 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc } } - @Override - public void onPause() { - super.onPause(); - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (purchaseHelper != null) { - purchaseHelper.removeListener(this); - } - } - public void notifyLiveUpdatesChanged() { if (getActivity() != null) { if (adapter != null && getMyApplication() != null) { @@ -702,6 +693,11 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc @Override public void onError(InAppPurchaseTaskType taskType, String error) { disableProgress(); + + OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); + if (activity != null) { + activity.fireInAppPurchaseErrorOnFragments(getChildFragmentManager(), taskType, error); + } } @Override @@ -711,6 +707,11 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc adapter.enableLiveUpdates(false); } disableProgress(); + + OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); + if (activity != null) { + activity.fireInAppPurchaseGetItemsOnFragments(getChildFragmentManager()); + } } @Override @@ -719,15 +720,30 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc if (purchaseHelper != null && purchaseHelper.getSkuLiveUpdates().equals(sku)) { updateSubscriptionHeader(); } + + OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); + if (activity != null) { + activity.fireInAppPurchaseItemPurchasedOnFragments(getChildFragmentManager(), sku); + } } @Override public void showProgress(InAppPurchaseTaskType taskType) { enableProgress(); + + OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); + if (activity != null) { + activity.fireInAppPurchaseShowProgressOnFragments(getChildFragmentManager(), taskType); + } } @Override public void dismissProgress(InAppPurchaseTaskType taskType) { disableProgress(); + + OsmandInAppPurchaseActivity activity = getInAppPurchaseActivity(); + if (activity != null) { + activity.fireInAppPurchaseDismissProgressOnFragments(getChildFragmentManager(), taskType); + } } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java index b372196fd6..b10641524a 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java @@ -308,24 +308,6 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In return view; } - @Override - public void onResume() { - super.onResume(); - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (purchaseHelper != null) { - purchaseHelper.addListener(this); - } - } - - @Override - public void onPause() { - super.onPause(); - InAppPurchaseHelper purchaseHelper = getInAppPurchaseHelper(); - if (purchaseHelper != null) { - purchaseHelper.removeListener(this); - } - } - @Override public void onDestroy() { super.onDestroy(); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 18709b2c71..2cdbf7879e 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -582,10 +582,10 @@ 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) || InAppPurchaseHelper.isFullVersionPurchased(context)) { + if (Version.isPaidVersion(context)) { collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); } - if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) { + if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(context)) { collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); } @@ -619,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 && !InAppPurchaseHelper.isFullVersionPurchased(context))) { + if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap)) { warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$ } else { if (mapReader.isBasemap()) { diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java index bcf8804b92..1daea9d540 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesMenu.java @@ -17,6 +17,7 @@ import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.render.RenderingRuleProperty; import java.io.IOException; @@ -47,7 +48,7 @@ public class ContourLinesMenu { final OsmandApplication app = mapActivity.getMyApplication(); final OsmandSettings settings = app.getSettings(); final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class); - final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null; + final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app); final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR); final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java index 821def2866..e5d4ad01ad 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeMenu.java @@ -16,6 +16,7 @@ import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.inapp.InAppPurchaseHelper; import java.io.IOException; import java.util.List; @@ -42,7 +43,7 @@ public class HillshadeMenu { final OsmandApplication app = mapActivity.getMyApplication(); final OsmandSettings settings = app.getSettings(); final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class); - final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null; + final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app); if (plugin == null) { return; } diff --git a/OsmAnd/src/net/osmand/plus/views/corenative/NativeCoreContext.java b/OsmAnd/src/net/osmand/plus/views/corenative/NativeCoreContext.java index a8a27ce6a8..d3685fc048 100644 --- a/OsmAnd/src/net/osmand/plus/views/corenative/NativeCoreContext.java +++ b/OsmAnd/src/net/osmand/plus/views/corenative/NativeCoreContext.java @@ -12,6 +12,7 @@ import net.osmand.core.jni.ObfsCollection; import net.osmand.core.jni.QIODeviceLogSink; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.srtmplugin.SRTMPlugin; import android.content.Context; import android.util.DisplayMetrics; @@ -60,7 +61,7 @@ public class NativeCoreContext { ObfsCollection obfsCollection = new ObfsCollection(); obfsCollection.addDirectory(directory.getAbsolutePath(), false); - if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) { + if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null || InAppPurchaseHelper.isSubscribedToLiveUpdates(app)) { obfsCollection.addDirectory(app.getAppPath(IndexConstants.SRTM_INDEX_DIR).getAbsolutePath(), false); }