Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Opt users out of tracking #1510

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/src/main/java/com/money/manager/ex/MmexApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ public Integer getBaseCurrencytId() {
return NumericHelper.toInteger(value);
}

public boolean getSendUsage() {
return get(R.string.pref_anonymous_usage, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -779,4 +779,7 @@
<string name="currency">Currency</string>
<string name="menu_create_database">Create Database</string>
<string name="create_database">Create Database</string>
<string name="pref_anonymous_usage">prefanonymoususage</string>
<string name="summary_anonymous_usage">Enable to help us sending anonymous data about MMEX usage</string>
<string name="title_anonymous_usage">Send anonymous usage data</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@
android:entryValues="@array/new_transaction_dialog_values"
android:key="@string/pref_default_payee"
android:title="@string/default_payee" />
<SwitchPreferenceCompat
android:icon="@null"
android:defaultValue="true"
android:key="@string/pref_anonymous_usage"
android:title="@string/title_anonymous_usage"
android:summary="@string/summary_anonymous_usage" />

</PreferenceScreen>
Loading