Fixed inapp purchases. Added cancelled subscription screen.

This commit is contained in:
Alexey Kulish 2018-05-03 18:30:50 +03:00
parent 215413b2b4
commit 2c3d2033e6
27 changed files with 622 additions and 131 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<inset>
<shape android:shape="oval">
<solid android:color="@color/dialog_bg_color_light"/>
</shape>
</inset>
</item>
</layer-list>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<inset>
<shape android:shape="oval">
<solid android:color="@color/dialog_bg_color_night"/>
</shape>
</inset>
</item>
</layer-list>

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/dialog_transparent_bg_color"
android:clickable="true"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/button_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/list_content_padding">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/button_close_img"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:background="?attr/circle_dialog_bg"
android:src="@drawable/ic_action_remove_small"
android:tint="@color/icon_color"/>
</FrameLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/title_padding"
android:layout_marginTop="@dimen/list_header_padding"
android:src="@drawable/img_help_osmand_live"/>
</FrameLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding_large"
android:layout_marginRight="@dimen/list_content_padding_large"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/title_padding"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/purchase_cancelled_dialog_title"
android:textColor="?attr/dialog_title_color"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/info_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/title_padding"
android:textColor="?attr/dialog_text_description_color"
android:textSize="@dimen/default_list_text_size"
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/purchase_cancelled_dialog_descr"/>
</LinearLayout>
<LinearLayout
android:id="@+id/cards_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/inapp_descr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_content_padding_large"
android:layout_marginRight="@dimen/list_content_padding_large"
android:layout_marginTop="@dimen/list_header_padding"
android:gravity="center"
android:text="@string/osm_live_payment_desc"
android:textColor="?attr/card_description_text_color"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_padding"
android:layout_marginTop="@dimen/card_padding">
<include layout="@layout/purchase_dialog_card_button"/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -65,8 +65,12 @@
<attr name="primary_icon_color" format="color"/>
<attr name="light_icon_color" format="color"/>
<attr name="circle_dialog_bg" format="reference"/>
<attr name="dialog_bg_color" format="reference"/>
<attr name="dialog_transparent_bg_color" format="reference"/>
<attr name="dialog_title_color" format="reference"/>
<attr name="dialog_description_color" format="reference"/>
<attr name="dialog_text_description_color" format="reference"/>
<attr name="card_description_text_color" format="reference"/>
<attr name="wikivoyage_bg_color" format="reference"/>

View file

@ -3,6 +3,11 @@
<color name="feature_purchased_bg">#78cc5c</color>
<color name="dialog_bg_color_light">#f0f0f0</color>
<color name="dialog_bg_color_night">#17191a</color>
<color name="dialog_transparent_bg_color_light">#14f0f0f0</color>
<color name="dialog_transparent_bg_color_night">#1417191a</color>
<color name="dialog_title_color_light">#212121</color>
<color name="dialog_title_color_dark">#cccccc</color>
<color name="dialog_description_color_light">#212121</color>
@ -10,6 +15,7 @@
<color name="dialog_divider_light">#e6e6e6</color>
<color name="dialog_divider_dark">#2d3133</color>
<color name="dialog_text_description_color">#727272</color>
<color name="dialog_text_description_color_night">#808080</color>
<color name="card_description_text_color_light">#b3b3b3</color>
<color name="card_description_text_color_dark">#4d4d4d</color>

View file

@ -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
-->
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
<string name="osmand_team">OsmAnd team</string>
<string name="popular_destinations">Popular destinations</string>
<string name="paid_app">Paid app</string>

View file

@ -179,6 +179,7 @@
<item name="android:actionMenuTextColor">@color/color_white</item>
<item name="actionOverflowButtonStyle">@style/OverflowMenuButton</item>
<item name="circle_dialog_bg">@drawable/circle_dialog_bg_light</item>
<item name="dialog_inactive_text_color">@color/icon_color_light</item>
<item name="secondary_icon_color">@color/icon_color_light</item>
<item name="primary_icon_color">@color/icon_color</item>
@ -197,8 +198,11 @@
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_light</item>
<item name="dialog_bg_color">@color/dialog_bg_color_light</item>
<item name="dialog_transparent_bg_color">@color/dialog_transparent_bg_color_light</item>
<item name="dialog_title_color">@color/dialog_title_color_light</item>
<item name="dialog_description_color">@color/dialog_description_color_light</item>
<item name="dialog_text_description_color">@color/dialog_text_description_color</item>
<item name="card_description_text_color">@color/card_description_text_color_light</item>
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_light</item>
@ -398,8 +402,12 @@
<item name="coordinate_input_edit_text_normal">@color/coordinate_input_edit_text_normal_dark</item>
<item name="circle_dialog_bg">@drawable/circle_dialog_bg_night</item>
<item name="dialog_bg_color">@color/dialog_bg_color_night</item>
<item name="dialog_transparent_bg_color">@color/dialog_transparent_bg_color_night</item>
<item name="dialog_title_color">@color/dialog_title_color_dark</item>
<item name="dialog_description_color">@color/dialog_description_color_dark</item>
<item name="dialog_text_description_color">@color/dialog_text_description_color_night</item>
<item name="card_description_text_color">@color/card_description_text_color_dark</item>
<item name="wikivoyage_bg_color">@color/wikivoyage_bg_dark</item>

View file

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

View file

@ -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)) {
} 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() {

View file

@ -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<Fragment> 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<Fragment> 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<Fragment> 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<Fragment> 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<Fragment> fragments = fragmentManager.getFragments();
for (Fragment f : fragments) {
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).dismissProgress(taskType);
}
}
}
public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) {

View file

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

View file

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

View file

@ -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

View file

@ -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<Boolean> firstTimeShown = app.getSettings().LIVE_UPDATES_PURCHASE_CANCELLED_FIRST_DLG_SHOWN;
OsmandPreference<Boolean> 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);
}
}
}

View file

@ -206,54 +206,25 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
@Override
public void onInAppPurchaseError(InAppPurchaseTaskType taskType, String error) {
visibleBanner.updateFreeVersionBanner();
for (WeakReference<Fragment> 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<Fragment> 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<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).onItemPurchased(sku);
}
}
}
@Override
public void showInAppPurchaseProgress(InAppPurchaseTaskType taskType) {
for (WeakReference<Fragment> ref : fragSet) {
Fragment f = ref.get();
if (f instanceof InAppPurchaseListener && f.isAdded()) {
((InAppPurchaseListener) f).showProgress(taskType);
}
}
}
@Override
public void dismissInAppPurchaseProgress(InAppPurchaseTaskType taskType) {
for (WeakReference<Fragment> 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();
}

View file

@ -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) {

View file

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

View file

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

View file

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

View file

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

View file

@ -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<InAppPurchaseListener> 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<Long> 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) {

View file

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

View file

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

View file

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

View file

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

View file

@ -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;
}

View file

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