diff --git a/android/res/xml/prefs_main.xml b/android/res/xml/prefs_main.xml index b9b33ba98d..08e26e24ac 100644 --- a/android/res/xml/prefs_main.xml +++ b/android/res/xml/prefs_main.xml @@ -83,12 +83,9 @@ android:summary="@string/pref_use_google_play" android:defaultValue="true" android:order="10"/> - diff --git a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java index 6bfcce7c57..5a254ecc08 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java @@ -19,7 +19,9 @@ import android.support.v7.preference.TwoStatePreference; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -32,6 +34,12 @@ import com.mapswithme.maps.downloader.OnmapDownloader; import com.mapswithme.maps.editor.ProfileActivity; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.TrackRecorder; +import com.mapswithme.maps.purchase.AdsRemovalActivationCallback; +import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider; +import com.mapswithme.maps.purchase.AdsRemovalPurchaseDialog; +import com.mapswithme.maps.purchase.PurchaseCallback; +import com.mapswithme.maps.purchase.PurchaseController; +import com.mapswithme.maps.purchase.PurchaseFactory; import com.mapswithme.maps.sound.LanguageData; import com.mapswithme.maps.sound.TtsPlayer; import com.mapswithme.util.Config; @@ -42,7 +50,6 @@ import com.mapswithme.util.UiUtils; import com.mapswithme.util.concurrency.UiThread; import com.mapswithme.util.log.LoggerFactory; import com.mapswithme.util.statistics.AlohaHelper; -import com.mapswithme.util.statistics.MytargetHelper; import com.mapswithme.util.statistics.Statistics; import java.util.HashMap; @@ -50,6 +57,7 @@ import java.util.List; import java.util.Map; public class SettingsPrefsFragment extends BaseXmlSettingsFragment + implements AdsRemovalActivationCallback, AdsRemovalPurchaseControllerProvider { private static final int REQUEST_INSTALL_DATA = 1; private static final String TTS_SCREEN_KEY = MwmApplication.get() @@ -76,6 +84,8 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment private final Map mLanguages = new HashMap<>(); private LanguageData mCurrentLanguage; private String mSelectedLanguage; + @Nullable + private PurchaseController mAdsRemovalPurchaseController; private boolean singleStorageOnly() { @@ -281,6 +291,21 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment return true; } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + { + mAdsRemovalPurchaseController = PurchaseFactory.createAdsRemovalPurchaseController(); + mAdsRemovalPurchaseController.initialize(getActivity()); + return super.onCreateView(inflater, container, savedInstanceState); + } + + @Override + public void onDestroyView() + { + mAdsRemovalPurchaseController.destroy(); + super.onDestroyView(); + } + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { @@ -363,14 +388,20 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment private void initDisplayShowcasePrefs() { - if (MytargetHelper.isShowcaseSwitchedOnServer()) - return; - Preference pref = findPreference(getString(R.string.pref_showcase_switched_on)); if (pref == null) return; - removePreference(getString(R.string.pref_settings_general), pref); + if (Framework.nativeHasActiveRemoveAdsSubscription()) + { + removePreference(getString(R.string.pref_settings_general), pref); + return; + } + + pref.setOnPreferenceClickListener(preference -> { + AdsRemovalPurchaseDialog.show(SettingsPrefsFragment.this); + return true; + }); } private void initLangInfoLink() @@ -882,4 +913,17 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment super.onDetach(); mPathManager.stopExternalStorageWatching(); } + + @Override + public void onAdsRemovalActivation() + { + initDisplayShowcasePrefs(); + } + + @Nullable + @Override + public PurchaseController getAdsRemovalPurchaseController() + { + return mAdsRemovalPurchaseController; + } } diff --git a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java index 82e17e9344..209fb8f3d6 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java +++ b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java @@ -6,7 +6,6 @@ import android.content.Context; import android.content.res.Resources; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.text.TextUtils; import android.view.LayoutInflater; @@ -26,7 +25,6 @@ import com.mapswithme.maps.ads.NativeAdListener; import com.mapswithme.maps.purchase.AdsRemovalPurchaseControllerProvider; import com.mapswithme.maps.purchase.AdsRemovalPurchaseDialog; import com.mapswithme.maps.purchase.PurchaseController; -import com.mapswithme.util.Config; import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.UiUtils; import com.mapswithme.util.Utils; @@ -38,7 +36,6 @@ import java.util.Collections; import java.util.List; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; -import static com.mapswithme.util.SharedPropertiesUtils.isShowcaseSwitchedOnLocal; import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_CLICK; import static com.mapswithme.util.statistics.Statistics.EventName.PP_BANNER_SHOW; import static com.mapswithme.util.statistics.Statistics.PP_BANNER_STATE_DETAILS; @@ -191,9 +188,7 @@ final class BannerController int state = mOpened ? PP_BANNER_STATE_DETAILS : PP_BANNER_STATE_PREVIEW; Statistics.INSTANCE.trackPPBannerClose(state, isCross); FragmentActivity activity = (FragmentActivity) mBannerView.getContext(); - AdsRemovalPurchaseDialog fragment - = (AdsRemovalPurchaseDialog) Fragment.instantiate(activity, AdsRemovalPurchaseDialog.class.getName()); - fragment.show(activity.getSupportFragmentManager(), null); + AdsRemovalPurchaseDialog.show(activity); } private void setErrorStatus(boolean value) @@ -247,11 +242,8 @@ final class BannerController setErrorStatus(false); mBanners = banners != null ? Collections.unmodifiableList(banners) : null; - if (mBanners == null || !isShowcaseSwitchedOnLocal() - || Config.getAdForbidden()) - { + if (mBanners == null) return; - } UiUtils.show(mContainerView); mAdsLoader.loadAd(mContainerView.getContext(), mBanners); diff --git a/android/src/com/mapswithme/util/Config.java b/android/src/com/mapswithme/util/Config.java index d45994f782..385aa3c27f 100644 --- a/android/src/com/mapswithme/util/Config.java +++ b/android/src/com/mapswithme/util/Config.java @@ -279,16 +279,6 @@ public final class Config setBool(KEY_MISC_USE_MOBILE_DATA_ROAMING, ConnectionState.isInRoaming()); } - public static boolean getAdForbidden() - { - return getBool(KEY_MISC_AD_FORBIDDEN, false); - } - - public static void setAdForbidden(boolean value) - { - setBool(KEY_MISC_AD_FORBIDDEN, value); - } - public static void setMobileDataTimeStamp(long timestamp) { setLong(KEY_MISC_USE_MOBILE_DATA_TIMESTAMP, timestamp); diff --git a/android/src/com/mapswithme/util/SharedPropertiesUtils.java b/android/src/com/mapswithme/util/SharedPropertiesUtils.java index 5956045250..bc6a656a82 100644 --- a/android/src/com/mapswithme/util/SharedPropertiesUtils.java +++ b/android/src/com/mapswithme/util/SharedPropertiesUtils.java @@ -28,12 +28,6 @@ public final class SharedPropertiesUtils throw new IllegalStateException("Try instantiate utility class SharedPropertiesUtils"); } - public static boolean isShowcaseSwitchedOnLocal() - { - return PreferenceManager.getDefaultSharedPreferences(MwmApplication.get()) - .getBoolean(MwmApplication.get().getString(R.string.pref_showcase_switched_on), false); - } - public static boolean isStatisticsEnabled() { return MwmApplication.prefs().getBoolean(KEY_PREF_STATISTICS, true); diff --git a/android/src/com/mapswithme/util/statistics/MytargetHelper.java b/android/src/com/mapswithme/util/statistics/MytargetHelper.java index 5ae8af38ba..64d50c2680 100644 --- a/android/src/com/mapswithme/util/statistics/MytargetHelper.java +++ b/android/src/com/mapswithme/util/statistics/MytargetHelper.java @@ -19,7 +19,6 @@ import java.net.URL; import java.util.List; import static com.mapswithme.maps.MwmApplication.prefs; -import static com.mapswithme.util.SharedPropertiesUtils.isShowcaseSwitchedOnLocal; public final class MytargetHelper { @@ -43,7 +42,7 @@ public final class MytargetHelper public MytargetHelper(final @NonNull Listener listener) { - if (!ConnectionState.isConnected() || !isShowcaseSwitchedOnLocal()) + if (!ConnectionState.isConnected()) { listener.onNoAds(); return;