forked from organicmaps/organicmaps
[android] Added ads removal dialog in settings
This commit is contained in:
parent
bce5731288
commit
0d08cbfa6f
9 changed files with 82 additions and 45 deletions
|
@ -83,12 +83,9 @@
|
|||
android:summary="@string/pref_use_google_play"
|
||||
android:defaultValue="true"
|
||||
android:order="10"/>
|
||||
<SwitchPreferenceCompat
|
||||
<Preference
|
||||
android:key="@string/pref_showcase_switched_on"
|
||||
android:title="@string/showcase_settings_title"
|
||||
android:defaultValue="true"
|
||||
android:switchTextOff=""
|
||||
android:switchTextOn=""
|
||||
android:title="@string/remove_ads"
|
||||
android:order="11"/>
|
||||
<SwitchPreferenceCompat
|
||||
android:key="@string/pref_enable_logging"
|
||||
|
|
|
@ -6,6 +6,9 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -67,6 +70,25 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
@NonNull
|
||||
private CompoundButton mOptionsButton;
|
||||
|
||||
public static void show(@NonNull FragmentActivity context)
|
||||
{
|
||||
DialogFragment fragment = instantiateDialog(context);
|
||||
fragment.show(context.getSupportFragmentManager(), AdsRemovalPurchaseDialog.class.getName());
|
||||
}
|
||||
|
||||
public static void show(@NonNull Fragment parent)
|
||||
{
|
||||
DialogFragment fragment = instantiateDialog(parent.getActivity());
|
||||
fragment.show(parent.getChildFragmentManager(), AdsRemovalPurchaseDialog.class.getName());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static DialogFragment instantiateDialog(@NonNull Context context)
|
||||
{
|
||||
String name = AdsRemovalPurchaseDialog.class.getName();
|
||||
return (DialogFragment) Fragment.instantiate(context, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
|
@ -79,7 +101,10 @@ public class AdsRemovalPurchaseDialog extends BaseMwmDialogFragment
|
|||
{
|
||||
super.onAttach(context);
|
||||
LOGGER.d(TAG, "onAttach");
|
||||
mControllerProvider = (AdsRemovalPurchaseControllerProvider) context;
|
||||
if (context instanceof AdsRemovalPurchaseControllerProvider)
|
||||
mControllerProvider = (AdsRemovalPurchaseControllerProvider) context;
|
||||
if (getParentFragment() instanceof AdsRemovalPurchaseControllerProvider)
|
||||
mControllerProvider = (AdsRemovalPurchaseControllerProvider) getParentFragment();
|
||||
if (context instanceof AdsRemovalActivationCallback)
|
||||
mActivationCallbacks.add((AdsRemovalActivationCallback) context);
|
||||
if (getParentFragment() instanceof AdsRemovalActivationCallback)
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.mapswithme.maps.search;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
|
@ -57,10 +56,7 @@ public class SearchCategoriesFragment extends BaseMwmRecyclerFragment<Categories
|
|||
@Override
|
||||
public void onAdsRemovalSelected()
|
||||
{
|
||||
AdsRemovalPurchaseDialog fragment
|
||||
= (AdsRemovalPurchaseDialog) Fragment.instantiate(getActivity(),
|
||||
AdsRemovalPurchaseDialog.class.getName());
|
||||
fragment.show(getChildFragmentManager(), null);
|
||||
AdsRemovalPurchaseDialog.show(this);
|
||||
}
|
||||
|
||||
private static boolean passCategory(Object listener, String category)
|
||||
|
|
|
@ -344,7 +344,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
mSearchAdapter = new SearchAdapter(this);
|
||||
readArguments();
|
||||
|
||||
if (ConnectionState.isWifiConnected() && SharedPropertiesUtils.isShowcaseSwitchedOnLocal())
|
||||
if (ConnectionState.isWifiConnected())
|
||||
{
|
||||
mAdsLoader = new GoogleAdsLoader(getContext(), ADS_DELAY_MS);
|
||||
mAdsLoader.attach(searchAdView ->
|
||||
|
|
|
@ -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<String, LanguageData> mLanguages = new HashMap<>();
|
||||
private LanguageData mCurrentLanguage;
|
||||
private String mSelectedLanguage;
|
||||
@Nullable
|
||||
private PurchaseController<PurchaseCallback> 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<PurchaseCallback> getAdsRemovalPurchaseController()
|
||||
{
|
||||
return mAdsRemovalPurchaseController;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Void> listener)
|
||||
{
|
||||
if (!ConnectionState.isConnected() || !isShowcaseSwitchedOnLocal())
|
||||
if (!ConnectionState.isConnected())
|
||||
{
|
||||
listener.onNoAds();
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue