From d6f9115da7759287839c37081605c717ddde7abc Mon Sep 17 00:00:00 2001 From: Lisheng Guan Date: Thu, 11 Jan 2024 22:49:52 +0800 Subject: [PATCH] Opt users out of tracking --- .../java/com/money/manager/ex/MmexApplication.java | 7 +++---- .../money/manager/ex/settings/GeneralSettings.java | 3 +++ .../ex/settings/GeneralSettingsFragment.java | 14 ++++++++++++++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/preferences_general.xml | 6 ++++++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/money/manager/ex/MmexApplication.java b/app/src/main/java/com/money/manager/ex/MmexApplication.java index 60e000a680..8faef67536 100644 --- a/app/src/main/java/com/money/manager/ex/MmexApplication.java +++ b/app/src/main/java/com/money/manager/ex/MmexApplication.java @@ -143,17 +143,16 @@ public void onCreate() { // Job Manager initialization. initializeJobManager(); - getOrCreateUUID(this); - mAmplitude = AmplitudeKt.Amplitude("1e1fbc10354400d9c3392a89558d693d" , getApplicationContext() , configuration -> { - configuration.setDefaultTracking(DefaultTrackingOptions.ALL);; + configuration.setDefaultTracking(DefaultTrackingOptions.ALL); + configuration.setOptOut(new AppSettings(this).getGeneralSettings().getSendUsage()); return Unit.INSTANCE; } ); - mAmplitude.setDeviceId(getOrCreateUUID(getApplicationContext())); + mAmplitude.setDeviceId(getOrCreateUUID(this)); } public static String getOrCreateUUID(Context context) { diff --git a/app/src/main/java/com/money/manager/ex/settings/GeneralSettings.java b/app/src/main/java/com/money/manager/ex/settings/GeneralSettings.java index 826e7e3337..c8905cc3d3 100644 --- a/app/src/main/java/com/money/manager/ex/settings/GeneralSettings.java +++ b/app/src/main/java/com/money/manager/ex/settings/GeneralSettings.java @@ -92,4 +92,7 @@ public Integer getBaseCurrencytId() { return NumericHelper.toInteger(value); } + public boolean getSendUsage() { + return get(R.string.pref_anonymous_usage, true); + } } diff --git a/app/src/main/java/com/money/manager/ex/settings/GeneralSettingsFragment.java b/app/src/main/java/com/money/manager/ex/settings/GeneralSettingsFragment.java index 018649893e..a36de877fd 100644 --- a/app/src/main/java/com/money/manager/ex/settings/GeneralSettingsFragment.java +++ b/app/src/main/java/com/money/manager/ex/settings/GeneralSettingsFragment.java @@ -21,7 +21,9 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.SwitchPreferenceCompat; +import com.money.manager.ex.MmexApplication; import com.money.manager.ex.R; import com.money.manager.ex.home.MainActivity; @@ -113,6 +115,18 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } }); } + + // send anonymous usage data + final SwitchPreferenceCompat spreference = (SwitchPreferenceCompat) findPreference(getString(R.string.pref_anonymous_usage)); + if (spreference == null) { + spreference.setOnPreferenceChangeListener((preference, newValue) -> { + // Handle the switch state change + boolean isChecked = (Boolean) newValue; + MmexApplication.getAmplitude().getConfiguration().setOptOut(isChecked); + // Add your logic here based on the switch state + return true; // Return true to persist the preference change + }); + } } public void setSummaryListPreference(Preference preference, String value, int idArrayValues, int idArrayItems) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7790836b7..034773178d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -779,4 +779,7 @@ Currency Create Database Create Database + prefanonymoususage + Enable to help us sending anonymous data about MMEX usage + Send anonymous usage data diff --git a/app/src/main/res/xml/preferences_general.xml b/app/src/main/res/xml/preferences_general.xml index a934627419..a41e8ea686 100644 --- a/app/src/main/res/xml/preferences_general.xml +++ b/app/src/main/res/xml/preferences_general.xml @@ -52,5 +52,11 @@ android:entryValues="@array/new_transaction_dialog_values" android:key="@string/pref_default_payee" android:title="@string/default_payee" /> + \ No newline at end of file