From 24f1d9572dd64e285c0fce36eadfba05fa89dfd7 Mon Sep 17 00:00:00 2001 From: Dmitry Donskoy Date: Thu, 31 May 2018 19:37:03 +0300 Subject: [PATCH] [android] Modified prefs, Modified fabric initialization --- android/AndroidManifest.xml | 5 + android/build.gradle | 3 + android/res/layout/fragment_gdpr.xml | 13 ++ android/res/values/donottranslate.xml | 1 - android/res/xml/prefs_main.xml | 42 ++-- .../com/mapswithme/maps/MwmApplication.java | 15 +- .../maps/gdpr/MwmOptOutActivity.java | 14 ++ .../maps/gdpr/OptOutDialogFragment.java | 179 ------------------ .../mapswithme/maps/gdpr/OptOutFragment.java | 22 +++ .../maps/settings/SettingsPrefsFragment.java | 143 ++------------ 10 files changed, 105 insertions(+), 332 deletions(-) create mode 100644 android/res/layout/fragment_gdpr.xml create mode 100644 android/src/com/mapswithme/maps/gdpr/MwmOptOutActivity.java delete mode 100644 android/src/com/mapswithme/maps/gdpr/OptOutDialogFragment.java create mode 100644 android/src/com/mapswithme/maps/gdpr/OptOutFragment.java diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 6a6e9b3eda..b71293a39d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -425,6 +425,11 @@ + + + + + \ No newline at end of file diff --git a/android/res/values/donottranslate.xml b/android/res/values/donottranslate.xml index 3dafa50047..34b457df20 100644 --- a/android/res/values/donottranslate.xml +++ b/android/res/values/donottranslate.xml @@ -86,7 +86,6 @@ search_hotel_filter_%s - pref_opt_out_appsflyer pref_subtittle_opt_out pref_opt_out_fabric pref_opt_out_fabric_activated diff --git a/android/res/xml/prefs_main.xml b/android/res/xml/prefs_main.xml index 0e6f090238..22f2f01b17 100644 --- a/android/res/xml/prefs_main.xml +++ b/android/res/xml/prefs_main.xml @@ -6,23 +6,6 @@ android:key="@string/pref_osm_profile" android:title="@string/profile" android:order="1"/> - - - - - - - - + + + + + + + + + + + diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java index f1e143b6ac..f69791a62b 100644 --- a/android/src/com/mapswithme/maps/MwmApplication.java +++ b/android/src/com/mapswithme/maps/MwmApplication.java @@ -149,10 +149,10 @@ public class MwmApplication extends Application public boolean isCrashlyticsEnabled() { - return !BuildConfig.FABRIC_API_KEY.startsWith("0000") && forceFabricActivated(); + return !BuildConfig.FABRIC_API_KEY.startsWith("0000"); } - private boolean forceFabricActivated() + private boolean isFabricActivated() { String prefKey = getResources().getString(R.string.pref_opt_out_fabric_activated); return mPrefs.getBoolean(prefKey, true); @@ -304,11 +304,14 @@ public class MwmApplication extends Application if (isCrashlyticsInitialized()) return false; - Fabric.with(this, new Crashlytics(), new CrashlyticsNdk()); + Crashlytics core = new Crashlytics + .Builder() + .core(new CrashlyticsCore.Builder().disabled(!isFabricActivated()).build()) + .build(); + Fabric.with(this, core, new CrashlyticsNdk()); nativeInitCrashlytics(); - - mCrashlyticsInitialized = true; + return mCrashlyticsInitialized = true; } public boolean isCrashlyticsInitialized() @@ -316,7 +319,7 @@ public class MwmApplication extends Application return mCrashlyticsInitialized; } - private static boolean setInstallationIdToCrashlytics() + private boolean setInstallationIdToCrashlytics() { if (!isCrashlyticsEnabled()) return false; diff --git a/android/src/com/mapswithme/maps/gdpr/MwmOptOutActivity.java b/android/src/com/mapswithme/maps/gdpr/MwmOptOutActivity.java new file mode 100644 index 0000000000..de38ef7662 --- /dev/null +++ b/android/src/com/mapswithme/maps/gdpr/MwmOptOutActivity.java @@ -0,0 +1,14 @@ +package com.mapswithme.maps.gdpr; + +import android.support.v4.app.Fragment; + +import com.mapswithme.maps.base.BaseToolbarActivity; + +public class MwmOptOutActivity extends BaseToolbarActivity +{ + @Override + protected Class getFragmentClass() + { + return OptOutFragment.class; + } +} diff --git a/android/src/com/mapswithme/maps/gdpr/OptOutDialogFragment.java b/android/src/com/mapswithme/maps/gdpr/OptOutDialogFragment.java deleted file mode 100644 index 3d76a702cb..0000000000 --- a/android/src/com/mapswithme/maps/gdpr/OptOutDialogFragment.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.mapswithme.maps.gdpr; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.text.TextUtils; -import android.widget.Toast; - -import com.appsflyer.AppsFlyerLib; -import com.mapswithme.maps.MwmApplication; -import com.mapswithme.maps.R; -import com.mapswithme.maps.base.BaseMwmDialogFragment; - -public class OptOutDialogFragment extends BaseMwmDialogFragment -{ - public static final String ARGS_TITLE = "opt_out_title"; - public static final String ARGS_OPT_OUT_ACTIONS_FACTORY = "opt_out_actions_factory"; - public static final String TAG = OptOutDialogFragment.class.getCanonicalName(); - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) - { - Bundle args = getArguments(); - - if (args == null) - { - throw new IllegalArgumentException("Args can not be null"); - } - - String title = args.getString(ARGS_TITLE); - String factoryName = args.getString(ARGS_OPT_OUT_ACTIONS_FACTORY); - OptOutActionsFactory factory = OptOutActionsFactory.getOrThrow(factoryName); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle(title) - .setNegativeButton(android.R.string.cancel, - (dialog, which) -> onDataProcessingAllowed(factory)) - .setPositiveButton(android.R.string.ok, - (dialog, which) -> onDataProcessingRestricted(factory)); - return builder.create(); - } - - private void onDataProcessingAllowed(OptOutActionsFactory factory) - { - } - - private void onDataProcessingRestricted(OptOutActionsFactory factory) - { - factory.mPositiveBtnListener.onClick(getActivity().getApplication()); - Toast.makeText(getActivity(), android.R.string.yes, Toast.LENGTH_SHORT).show(); - } - - interface OnClickListener - { - void onClick(T data); - } - - public enum OptOutActionsFactory - { - APPSFLYER( - new AppsFlyerListenerBase.PositiveBtnListener(), - new AppsFlyerListenerBase.NegativeBtnListener()), - FABRIC(new FabricPositiveBtnListener(), - new FabricNegativeBtnListener()); - - @NonNull - private final Bundle mFragArgs; - @NonNull - private final OnClickListener mPositiveBtnListener; - @NonNull - private final OnClickListener mNegativeBtnListener; - - OptOutActionsFactory(@NonNull OnClickListener positiveBtnListener, - @NonNull OnClickListener negativeBtnListener) - { - mPositiveBtnListener = positiveBtnListener; - mNegativeBtnListener = negativeBtnListener; - mFragArgs = getBundle(name()); - } - - @NonNull - private static Bundle getBundle(String name) - { - Bundle fragArgs = new Bundle(); - fragArgs.putString(ARGS_OPT_OUT_ACTIONS_FACTORY, name); - /*FIXME*/ - fragArgs.putString(ARGS_TITLE, "my title"); - return fragArgs; - } - - @NonNull - public Bundle getFragArgs() - { - return mFragArgs; - } - - @NonNull - public static OptOutActionsFactory getOrThrow(String name) - { - for (OptOutActionsFactory each : values()) - { - if (TextUtils.equals(each.name(), name)) - { - return each; - } - } - throw new IllegalArgumentException("Value not found for arg = " + name); - } - - private static class AppsFlyerListenerBase implements OnClickListener - { - - private final boolean mIsTrackingEnabled; - - private AppsFlyerListenerBase(boolean isTrackingEnabled) - { - mIsTrackingEnabled = isTrackingEnabled; - } - - @Override - public void onClick(Context data) - { - AppsFlyerLib.getInstance().stopTracking(mIsTrackingEnabled, data); - } - - private static class PositiveBtnListener extends AppsFlyerListenerBase - { - - private PositiveBtnListener() - { - super(false); - } - } - - private static class NegativeBtnListener extends AppsFlyerListenerBase - { - private NegativeBtnListener() - { - super(true); - } - } - } - - private static class FabricPositiveBtnListener implements OnClickListener - { - @Override - public void onClick(Context context) - { - MwmApplication app = (MwmApplication) context.getApplicationContext(); - app.deactivateCrashlytics(); - } - - /*FIXME*/ - private void logAnalytics(Context data) - { - - } - } - - private static class FabricNegativeBtnListener implements OnClickListener - { - @Override - public void onClick(Context context) - { - MwmApplication app = (MwmApplication) context.getApplicationContext(); - SharedPreferences prefs = MwmApplication.prefs(context); - String prefKey = context.getString(R.string.pref_opt_out_fabric_activated); - prefs - .edit() - .putBoolean(prefKey, true) - .apply(); - app.initCrashlytics(); - } - } - } -} diff --git a/android/src/com/mapswithme/maps/gdpr/OptOutFragment.java b/android/src/com/mapswithme/maps/gdpr/OptOutFragment.java new file mode 100644 index 0000000000..404bc471b3 --- /dev/null +++ b/android/src/com/mapswithme/maps/gdpr/OptOutFragment.java @@ -0,0 +1,22 @@ +package com.mapswithme.maps.gdpr; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.mapswithme.maps.R; + +public class OptOutFragment extends Fragment +{ + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) + { + return inflater.inflate(R.layout.fragment_gdpr, container, false); + } +} diff --git a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java index 08054651ed..9a25506a4e 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java @@ -20,7 +20,6 @@ import android.support.v7.preference.TwoStatePreference; import android.text.Spannable; import android.text.SpannableString; import android.text.style.ForegroundColorSpan; -import android.util.Log; import android.view.View; import com.flurry.android.FlurryAgent; @@ -34,7 +33,6 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.downloader.MapManager; import com.mapswithme.maps.downloader.OnmapDownloader; import com.mapswithme.maps.editor.ProfileActivity; -import com.mapswithme.maps.gdpr.OptOutDialogFragment; import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.TrackRecorder; import com.mapswithme.maps.sound.LanguageData; @@ -45,15 +43,11 @@ import com.mapswithme.util.SharedPropertiesUtils; import com.mapswithme.util.ThemeSwitcher; import com.mapswithme.util.UiUtils; import com.mapswithme.util.concurrency.UiThread; +import com.mapswithme.util.log.Logger; 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 com.mopub.common.MoPub; -import com.mopub.common.logging.MoPubLog; -import com.mopub.common.privacy.ConsentDialogListener; -import com.mopub.common.privacy.PersonalInfoManager; -import com.mopub.mobileads.MoPubErrorCode; import java.util.HashMap; import java.util.List; @@ -66,6 +60,8 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment .getString(R.string.pref_tts_screen); private static final String TTS_INFO_LINK = MwmApplication.get() .getString(R.string.tts_info_link); + private static final String TAG = "settings"; + private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC); @NonNull private final StoragePathManager mPathManager = new StoragePathManager(); @@ -323,27 +319,6 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment private void initOptOutBlock() { initFlurryOptOut(); - initMoPubOptOut(); - initFabricOptOut(); - initAppsFlyerOptOut(); - } - - private void initAppsFlyerOptOut() - { - initOptOutItem(R.string.pref_opt_out_appsflyer, new AppsFlyerPrefClickListener()); - } - - private void initFabricOptOut() - { - initOptOutItem(R.string.pref_opt_out_fabric, new FabricClickListener()); - } - - private void initMoPubOptOut() - { - final PersonalInfoManager moPubManager = MoPub.getPersonalInformationManager(); - if (moPubManager == null) - return; - initOptOutItem(R.string.pref_opt_out_mopub, new MoPubPrefClickListener(moPubManager)); } private void initFlurryOptOut() @@ -918,119 +893,31 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment mPathManager.stopExternalStorageWatching(); } - private abstract class AbstractPrefDialogClickListener implements Preference.OnPreferenceClickListener { - - @Override - public boolean onPreferenceClick(Preference preference) - { - OptOutDialogFragment frag = new OptOutDialogFragment(); - OptOutDialogFragment.OptOutActionsFactory factory = getOptOutActionsFactory(); - - frag.setArguments(factory.getFragArgs()); - frag.show(getFragmentManager(), OptOutDialogFragment.TAG); - return false; - } - - @NonNull - protected abstract OptOutDialogFragment.OptOutActionsFactory getOptOutActionsFactory(); - } - - private class AppsFlyerPrefClickListener extends AbstractPrefDialogClickListener - { - @Override - public boolean onPreferenceClick(Preference preference) - { - OptOutDialogFragment frag = new OptOutDialogFragment(); - - OptOutDialogFragment.OptOutActionsFactory factory = OptOutDialogFragment - .OptOutActionsFactory - .APPSFLYER; - frag.setArguments(factory.getFragArgs()); - frag.show(getFragmentManager(), OptOutDialogFragment.TAG); - return true; - } - - @NonNull - @Override - protected OptOutDialogFragment.OptOutActionsFactory getOptOutActionsFactory() - { - return OptOutDialogFragment - .OptOutActionsFactory - .APPSFLYER; - } - } - - private class MoPubPrefClickListener implements Preference.OnPreferenceClickListener - { - @NonNull - private final PersonalInfoManager mMoPubManager; - - MoPubPrefClickListener(@NonNull PersonalInfoManager moPubManager) - { - mMoPubManager = moPubManager; - } - - @Override - public boolean onPreferenceClick(Preference preference) - { - /*FIXME*/ - if (mMoPubManager.shouldShowConsentDialog()) - { - class MapsMeMoPubDialogListener implements ConsentDialogListener - { - @Override - public void onConsentDialogLoaded() - { - mMoPubManager.showConsentDialog(); - } - - @Override - public void onConsentDialogLoadFailed(@NonNull MoPubErrorCode moPubErrorCode) - { - MoPubLog.i("Consent dialog failed to load."); - } - } - mMoPubManager.loadConsentDialog(new MapsMeMoPubDialogListener()); - } - return true; - } - } - private class FlurryPrefClickListener implements Preference.OnPreferenceClickListener { @Override public boolean onPreferenceClick(Preference preference) { - class MapsMeFlurryPrivacySession implements FlurryPrivacySession.Callback - { - @Override - public void success() { - Log.d("settings", "Privacy Dashboard opened successfully"); - } - - @Override - public void failure() { - Log.d("settings", "Opening Privacy Dashboard failed"); - } - } - Context c = getContext().getApplicationContext(); MapsMeFlurryPrivacySession callback = new MapsMeFlurryPrivacySession(); final FlurryPrivacySession.Request request = new FlurryPrivacySession.Request(c, callback); FlurryAgent.openPrivacyDashboard(request); return true; } - } - private class FabricClickListener extends AbstractPrefDialogClickListener - { - @NonNull - @Override - protected OptOutDialogFragment.OptOutActionsFactory getOptOutActionsFactory() + class MapsMeFlurryPrivacySession implements FlurryPrivacySession.Callback { - return OptOutDialogFragment - .OptOutActionsFactory - .FABRIC; + @Override + public void success() + { + LOGGER.d(TAG, "Privacy Dashboard opened successfully"); + } + + @Override + public void failure() + { + LOGGER.d(TAG, "Opening Privacy Dashboard failed"); + } } } }